Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,16 @@ on:
jobs:
test:
runs-on: ubuntu-latest
env:
UV_PYTHON: "3.13"

steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v4
with:
version: "0.12.3"

- name: Set up Python
run: uv python install 3.13
Expand All @@ -28,3 +32,6 @@ jobs:

- name: Run tests
run: uv run pytest -vv

- name: Run Ruff
run: uv run ruff check .
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ repos:
)$

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.14.3
rev: v0.16.0
hooks:
- id: ruff
name: ruff check
Expand Down
3 changes: 1 addition & 2 deletions 01-hello/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ description = "Python hello world worker"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"webtypy>=0.1.7",
]

[dependency-groups]
dev = [
"workers-py",
"workers-py==1.17.7",
"workers-runtime-sdk"
]
2 changes: 1 addition & 1 deletion 01-hello/src/entry.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from workers import WorkerEntrypoint, Response
from workers import Response, WorkerEntrypoint


class Default(WorkerEntrypoint):
Expand Down
3 changes: 1 addition & 2 deletions 02-binding/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ description = "Python bindings example"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"webtypy>=0.1.7",
]

[dependency-groups]
dev = [
"workers-py",
"workers-py==1.17.7",
"workers-runtime-sdk"
]
2 changes: 1 addition & 1 deletion 02-binding/src/entry.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from workers import WorkerEntrypoint, Response
from workers import Response, WorkerEntrypoint


class Default(WorkerEntrypoint):
Expand Down
3 changes: 1 addition & 2 deletions 03-fastapi/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,13 @@ description = "Python fastapi example"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"webtypy>=0.1.7",
"fastapi",
"markupsafe",
"jinja2",
]

[dependency-groups]
dev = [
"workers-py",
"workers-py==1.17.7",
"workers-runtime-sdk"
]
26 changes: 26 additions & 0 deletions 03-fastapi/src/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import jinja2
from fastapi import FastAPI, Request

environment = jinja2.Environment()
template = environment.from_string("Hello, {{ name }}!")

app = FastAPI()


@app.get("/")
async def root():
message = "This is an example of FastAPI with Jinja2 - go to /hi/<name> to see a template rendered"
return {"message": message}


@app.get("/hi/{name}")
async def say_hi(name: str):
message = template.render(name=name)
return {"message": message}


@app.get("/env")
async def env(req: Request):
env = req.scope["env"]
message = f"Here is an example of getting an environment variable: {env.MESSAGE}"
return {"message": message}
28 changes: 2 additions & 26 deletions 03-fastapi/src/worker.py
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
import jinja2
from fastapi import FastAPI, Request
from workers import WorkerEntrypoint

environment = jinja2.Environment()
template = environment.from_string("Hello, {{ name }}!")

app = FastAPI()


@app.get("/")
async def root():
message = "This is an example of FastAPI with Jinja2 - go to /hi/<name> to see a template rendered"
return {"message": message}


@app.get("/hi/{name}")
async def say_hi(name: str):
message = template.render(name=name)
return {"message": message}


@app.get("/env")
async def env(req: Request):
env = req.scope["env"]
message = f"Here is an example of getting an environment variable: {env.MESSAGE}"
return {"message": message}


class Default(WorkerEntrypoint):
async def fetch(self, request):
# FastAPI's telemetry needs entropy, which is only available in a request.
import asgi
from app import app

return await asgi.fetch(app, request.js_object, self.env)
3 changes: 1 addition & 2 deletions 04-query-d1/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ description = "Python d1 example"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"webtypy>=0.1.7",
]

[dependency-groups]
dev = [
"workers-py",
"workers-py==1.17.7",
"workers-runtime-sdk"
]
2 changes: 1 addition & 1 deletion 04-query-d1/src/entry.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from workers import WorkerEntrypoint, Response
from workers import Response, WorkerEntrypoint


class Default(WorkerEntrypoint):
Expand Down
3 changes: 0 additions & 3 deletions 04-query-d1/wrangler.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
"compatibility_flags": [
"python_workers"
],
"ai": {
"binding": "AI"
},
"d1_databases": [
{
"binding": "DB", // i.e. available in your Worker on env.DB
Expand Down
3 changes: 1 addition & 2 deletions 05-langchain/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@ description = "Python langchain example"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"webtypy>=0.1.7",
"langchain_core",
"langchain_openai"
]

[dependency-groups]
dev = [
"workers-py",
"workers-py==1.17.7",
"workers-runtime-sdk"
]
2 changes: 1 addition & 1 deletion 05-langchain/src/worker.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from workers import WorkerEntrypoint, Response
from langchain_core.prompts import PromptTemplate
from langchain_openai import OpenAI
from workers import Response, WorkerEntrypoint


class Default(WorkerEntrypoint):
Expand Down
3 changes: 1 addition & 2 deletions 06-assets/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ description = "Python assets handling example"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"webtypy>=0.1.7",
]

[dependency-groups]
dev = [
"workers-py",
"workers-py==1.17.7",
"workers-runtime-sdk"
]
3 changes: 1 addition & 2 deletions 07-durable-objects/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ description = "Python durable objects example"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"webtypy>=0.1.7",
]

[dependency-groups]
dev = [
"workers-py",
"workers-py==1.17.7",
"workers-runtime-sdk"
]
6 changes: 3 additions & 3 deletions 07-durable-objects/src/entry.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from workers import WorkerEntrypoint, Response, DurableObject
from pyodide.ffi import to_js
from urllib.parse import urlparse

from pyodide.ffi import to_js
from workers import DurableObject, Response, WorkerEntrypoint


class List(DurableObject):
async def get_messages(self):
Expand All @@ -12,7 +13,6 @@ async def add_message(self, message):
messages = await self.get_messages()
messages.append(message)
await self.ctx.storage.put("messages", to_js(messages))
return


class Default(WorkerEntrypoint):
Expand Down
Loading
Loading