Simple SvelteKit boilerplate that uses Flask as the API backend.
This is a hybrid SvelteKit + 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 SvelteKit app under /api/
.
This is implemented using next.config.js
rewrites 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:5328
port, which is where the Flask server is running.
In production, the Flask server is hosted as Python serverless functions on Vercel.
https://nextjs-flask-starter.vercel.app/
You can clone & deploy it to Vercel with one click:
You can clone & create this repo with the following command
npx create-next-app nextjs-flask --example "https://github.com/vercel/examples/tree/main/python/nextjs-flask"
First, install the dependencies:
npm install
# or
yarn
# or
pnpm install
Then, run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
Open http://localhost:5173 with your browser to see the result.
The Flask server will be running on http://127.0.0.1:5328 – feel free to change the port in package.json
(you'll also need to update it in next.config.js
).
To learn more about SvelteKit, take a look at the following resources:
You can check out the SvelteKit GitHub repository - your feedback and contributions are welcome!