Skip to content

Commit 6a5c2bf

Browse files
committed
FastMCP working
1 parent e817d75 commit 6a5c2bf

File tree

12 files changed

+210
-280
lines changed

12 files changed

+210
-280
lines changed

.github/workflows/test.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: Test Deploy CI
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
10+
11+
jobs:
12+
vendoring:
13+
strategy:
14+
matrix:
15+
os: [ubuntu-latest, macos-latest, windows-latest]
16+
runs-on: ${{ matrix.os }}
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v4
24+
with:
25+
python-version: '3.12'
26+
27+
- name: Install Node.js
28+
uses: actions/setup-node@v4
29+
with:
30+
node-version: 22
31+
32+
- name: Install Wrangler
33+
run: npm install -g wrangler
34+
35+
- name: Run vendoring script (Linux/macOS)
36+
if: runner.os != 'Windows'
37+
run: ./.github/workflows/vendoring/unix.sh
38+
shell: bash
39+
40+
- name: Run vendoring script (Windows)
41+
if: runner.os == 'Windows'
42+
continue-on-error: true
43+
run: .github\workflows\vendoring\windows.bat
44+
45+
- name: Test worker deployment
46+
run: wrangler deploy --dry-run
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
python3.12 -m venv .venv
4+
source .venv/bin/activate
5+
.venv/bin/pip install pyodide-build
6+
.venv/bin/pyodide venv .venv-pyodide
7+
.venv-pyodide/bin/pip install -t src/vendor -r vendor.txt
8+
9+
if [ -z "$(ls -A src/vendor)" ]; then
10+
echo "Vendoring failed: No files in src/vendor"
11+
exit 1
12+
fi
13+
14+
echo "Vendoring succeeded"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
@echo off
2+
3+
python -m venv .venv
4+
call .venv\Scripts\activate
5+
.venv\Scripts\pip install pyodide-build
6+
.venv\Scripts\pyodide venv .venv-pyodide
7+
.venv-pyodide\Scripts\pip install -t src/vendor -r vendor.txt
8+
9+
if not exist src\vendor\* (
10+
echo Vendoring failed: No files in src/vendor
11+
exit /b 1
12+
)
13+
14+
echo Vendoring succeeded

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.venv/
22
node_modules/
33
src/vendor/
4-
.vscode/
4+
.vscode/
5+
.wrangler/

README.md

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
# Vendoring Packages: FastAPI + Jinja2 Example
1+
# Python Workers: FastMCP Example
22

3-
*Note: You must have Python Packages enabled on your account for built-in packages to work. Request Access to our Closed Beta using [This Form](https://forms.gle/FcjjhV3YtPyjRPaL8)*
4-
5-
This is an example of a Python Worker that uses a built-in package (FastAPI) with a vendored package (Jinja2).
3+
This is an example of a Python Worker that uses the FastMCP package.
64

75
## Adding Packages
86

9-
Built-in packages can be selected from [this list](https://developers.cloudflare.com/workers/languages/python/packages/#supported-packages) and added to your `requirements.txt` file. These can be used with no other explicit install step.
10-
117
Vendored packages are added to your source files and need to be installed in a special manner. The Python Workers team plans to make this process automatic in the future, but for now, manual steps need to be taken.
128

139
### Vendoring Packages
1410

15-
[//]: # (NOTE: when updating the instructions below, be sure to also update the vendoring.yml CI workflow)
16-
1711
First, install Python3.12 and pip for Python 3.12.
1812

1913
*Currently, other versions of Python will not work - use 3.12!*
@@ -30,34 +24,11 @@ Within our virtual environment, install the pyodide CLI:
3024
.venv/bin/pyodide venv .venv-pyodide
3125
```
3226

33-
Next, add packages to your vendor.txt file. Here we'll add jinja2
34-
```
35-
jinja2
36-
```
37-
38-
Lastly, add these packages to your source files at `src/vendor`. For any additional packages, re-run this command.
27+
Lastly, download the vendored packages. For any additional packages, re-run this command.
3928
```console
4029
.venv-pyodide/bin/pip install -t src/vendor -r vendor.txt
4130
```
4231

43-
### Using Vendored packages
44-
45-
In your wrangler.toml, make the vendor directory available:
46-
47-
```toml
48-
[[rules]]
49-
globs = ["vendor/**"]
50-
type = "Data"
51-
fallthrough = true
52-
```
53-
54-
Now, you can import and use the packages:
55-
56-
```python
57-
import jinja2
58-
# ... etc ...
59-
```
60-
6132
### Developing and Deploying
6233

6334
To develop your Worker, run `npx wrangler@latest dev`.

0 commit comments

Comments
 (0)