Simple Sveltekit boilerplate that uses Flask as the API backend.
This is a hybrid Sveltekit + Flask Python app that uses Sveltekit as the frontend and Flask as the API backend. One great use case of this is to write Sveltekit apps that use Python AI libraries on the backend.
The Python/Flask server is mapped into to Next.js app under /api/
.
This is implemented using hook.server.ts
handleFetch to map any request to /api/:path*
to the Flask API, which is hosted in the /api
folder.
On localhost, the rewrite will be made to the 127.0.0.1:3000
port, which is where the Flask server is running.
In production, the Flask server is hosted as Python serverless functions on Vercel.
https://sveltekit-flask.vercel.app/
You can clone the repo, and create .env
file with same values as .env.example
which are API_ADDRESS
and CLIENT_API_ADDRESS
.
if you want to change any port settings feel free to change them in package.json
(you'll also need to update it in .env
).
First, install the dependencies:
pnpm install
# or
yarn
# or
npm install
Then setup virtual environment for flask via following command:
pipenv shell
Then, run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
Open http://localhost:3001 with your browser to see the result.
The Flask server will be running on http://127.0.0.1:3000.
To learn more about Svelte and Sveltekit, take a look at the following resources:
You can check out the Sveltekit GitHub repository - your feedback and contributions are welcome!