Skip to content

Commit 3c76904

Browse files
committed
Add clearer dev and build instructions
1 parent 12e0482 commit 3c76904

File tree

1 file changed

+44
-4
lines changed

1 file changed

+44
-4
lines changed

README.md

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,35 @@
1+
<p align="middle">
12
<img width="100" alt="image" src="https://user-images.githubusercontent.com/20548516/218344678-d41f4c4a-6b1b-48cc-8553-2b9fbe2169d6.png"/>
23
<img width="100" alt="image" src="https://camo.githubusercontent.com/f1ac9955f30176e6183aeeeac1b77354c7a132696fdc77c06ef0f0bec30f258c/68747470733a2f2f6861636b616461792e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031392f30392f707974686f6e2d6c6f676f2e706e67"/>
34
<img width="100" alt="image" src="https://camo.githubusercontent.com/add2c9721e333f0043ac938f3dadbc26a282776e01b95b308fcaba5afaf74ae3/68747470733a2f2f6173736574732e76657263656c2e636f6d2f696d6167652f75706c6f61642f76313538383830353835382f7265706f7369746f726965732f76657263656c2f6c6f676f2e706e67"/>
5+
</p>
46

57
# sveltekit-python-vercel
68

79
Write Python endpoints in [SvelteKit](https://kit.svelte.dev/) and seamlessly deploy them to Vercel.
810

11+
- [Current Features](#current-features)
12+
- [Installing](#installing)
13+
- [Testing Locally](#testing-locally)
14+
- [Deploying to Vercel](#deploying-to-vercel)
15+
- [Example](#example)
16+
- [Backend Caveats](#backend-caveats)
17+
- [Fork of `sveltekit-modal`](#fork-of-sveltekit-modal)
18+
- [Possible future plans](#possible-future-plans)
19+
20+
921
**This is very much in beta.**
1022

1123
## Current Features
1224

1325
- Write `+server.py` files nearly the same way you would write `+server.js` files
14-
- These functions deploy automatically to Vercel Serverless
26+
- Deploy (quadi) automatically to Vercel Serverless
1527

1628
## Installing
1729

1830
- Open or set up your SvelteKit project
19-
- Install with `npm i -D sveltekit-python-vercel`
31+
- Install SvelteKit's Vercel adapter: `pnpm i -D @sveltejs/adapter-vercel`
32+
- Install with `pnpm i -D sveltekit-python-vercel`
2033
- Update your `vite.config.js`
2134

2235
```javascript
@@ -34,7 +47,7 @@ Write Python endpoints in [SvelteKit](https://kit.svelte.dev/) and seamlessly de
3447
- Update your `svelte.config.js`:
3548

3649
```javascript
37-
import adapter from "@sveltejs/adapter-vercel";
50+
import adapter from "@sveltejs/adapter-vercel"; // Use the vercel adapter
3851
import { vitePreprocess } from "@sveltejs/kit/vite";
3952

4053
/** @type {import('@sveltejs/kit').Config} */
@@ -97,7 +110,30 @@ Using [Poetry](https://python-poetry.org/) to manage your virtual environments w
97110
- Required packages are python3.9 (that is what Vercel's runtime uses), `fastapi`, and `uvicorn`.
98111
- Install whatever other dependencies you need from pypi using `poetry add package-name`
99112

113+
- Enter your virtual env with `poetry shell`
100114
- Run `pnpm dev` or `npm dev`
115+
- You should see both the usual SvelteKit server start as well as the unvicorn server (by default on `http://0.0.0.0:8000`) in the console.
116+
117+
## Deploying to Vercel
118+
- At the moment this requires a tiny bit of extra labor besides just pushing to your repository. I believe this is because of the way Vercel looks for serverless functions, but I hope to make this a bit easier in the future.
119+
120+
- When you make changes to your python endpoints, you have to manually regenerate the `/api` folder by running:
121+
1. `poetry export -f requirements.txt --output requirements.txt --without-hashes`
122+
2. `node ./node_modules/sveltekit-python-vercel/esm/src/vite/sveltekit_python_vercel/bin.mjs`
123+
- Then commit `requirements.txt` and the changes in `/api` and push.
124+
125+
126+
Note:
127+
- To make this a bit smoother, you can add a script to you `package.json`:
128+
```json
129+
"scripts": {
130+
...
131+
"py-update": "poetry export -f requirements.txt --output requirements.txt --without-hashes; node ./node_modules/sveltekit-python-vercel/esm/src/vite/sveltekit_python_vercel/bin.mjs"
132+
}
133+
```
134+
- and then just run `pnpm py-update`
135+
136+
101137

102138

103139
## Example
@@ -174,9 +210,13 @@ Using [Poetry](https://python-poetry.org/) to manage your virtual environments w
174210

175211
```
176212

177-
## Caveats
213+
### Backend Caveats
178214

179215
There are currently a few things that have to be worked around.
216+
- `GET` endpoints are directly fed the parameters from the url, so when you define an endpoint
217+
- All other endpoints are fed the body as a JSON. The recommended way to deal with this is to use a pydantic model and pass it as the singular input to the function.
218+
219+
See the example above.
180220

181221
## Fork of `sveltekit-modal`
182222

0 commit comments

Comments
 (0)