You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -63,8 +62,10 @@ Write Python endpoints in [SvelteKit](https://kit.svelte.dev/) and seamlessly de
63
62
```
64
63
65
64
- Update your `vercel.json`
65
+
66
66
- The build command prepares all your endpoints and copies them to the `/api` directory where Vercel looks for functions
67
67
- Functions and Routes tell Vercel how to run and redirect function calls
68
+
68
69
```json
69
70
{
70
71
"buildCommand": "node ./node_modules/sveltekit-python-vercel/esm/src/vite/sveltekit_python_vercel/bin.mjs; vite build",
@@ -85,7 +86,8 @@ Write Python endpoints in [SvelteKit](https://kit.svelte.dev/) and seamlessly de
85
86
- Write some `+server.py` endpoints. See the example section below.
86
87
87
88
## Testing Locally
88
-
Using [Poetry](https://python-poetry.org/) to manage your virtual environments with this package is recommended.
89
+
90
+
Using [Poetry](https://python-poetry.org/) to manage your virtual environments with this package is recommended.
89
91
90
92
- Run `poetry init` to create a new virtual environment, and follow the steps. Or simply create a `pyproject.toml` like the one below.
91
93
@@ -107,6 +109,7 @@ Using [Poetry](https://python-poetry.org/) to manage your virtual environments w
107
109
requires = ["poetry-core"]
108
110
build-backend = "poetry.core.masonry.api"
109
111
```
112
+
110
113
- Required packages are python3.9 (that is what Vercel's runtime uses), `fastapi`, and `uvicorn`.
111
114
- Install whatever other dependencies you need from pypi using `poetry add package-name`
112
115
@@ -115,15 +118,16 @@ Using [Poetry](https://python-poetry.org/) to manage your virtual environments w
115
118
- 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
119
117
120
## Deploying to Vercel
121
+
118
122
- 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
123
120
124
- When you make changes to your python endpoints, you have to manually regenerate the `/api` folder by running:
There are currently a few things that have to be worked around.
219
+
216
220
-`GET` endpoints are directly fed the parameters from the url, so when you define an endpoint
217
221
- 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
222
@@ -224,7 +228,6 @@ Check out the awesome [sveltekit-modal](https://github.com/semicognitive/sveltek
224
228
225
229
## Possible future plans
226
230
227
-
-[ ] Make API endpoints work with wildcard urls (e.g. `src/routes/user/[username]/+server.py) This currently throws an error during build.
228
231
-[ ] Generate endpoints (/api folder) automatically during build
229
232
-[ ] Auto create requirements.txt from pyproject.toml (both related to vercel functions being checked/handled before build)
0 commit comments