Skip to content

Commit 5df1a38

Browse files
authored
chore(py): Update package READMEs on PyPI (#5880)
1 parent b728267 commit 5df1a38

22 files changed

Lines changed: 316 additions & 118 deletions

File tree

py/packages/genkit-anthropic/README.md

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,30 @@
55
>
66
> **Preview** — This plugin is in preview and may have API changes in future releases.
77
8-
This Genkit plugin provides a set of tools and utilities for working with Anthropic.
8+
Anthropic Claude model provider for Genkit.
9+
10+
## Installation
11+
12+
```bash
13+
uv add genkit-anthropic
14+
```
15+
16+
## Usage
17+
18+
```python
19+
from genkit import Genkit
20+
from genkit_anthropic import Anthropic
21+
22+
ai = Genkit(plugins=[Anthropic()])
23+
24+
res = await ai.generate(
25+
model='anthropic/claude-sonnet-4-6',
26+
prompt='Explain recursion in 10 words.',
27+
)
28+
print(res.text)
29+
```
30+
31+
Set `ANTHROPIC_API_KEY` in the environment, or pass `api_key=` to `Anthropic()`.
932

1033
## Disclaimer
1134

py/packages/genkit-anthropic/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ version = "0.9.0"
6262

6363
[project.urls]
6464
"Bug Tracker" = "https://github.com/genkit-ai/genkit/issues"
65-
Changelog = "https://github.com/genkit-ai/genkit/blob/main/py/packages/genkit-anthropic/CHANGELOG.md"
6665
"Documentation" = "https://firebase.google.com/docs/genkit"
6766
"Homepage" = "https://github.com/genkit-ai/genkit"
6867
"Repository" = "https://github.com/genkit-ai/genkit/tree/main/py"

py/packages/genkit-django/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Genkit Django Plugin
22

3-
`genkit-plugin-django` exposes Genkit flows as HTTP endpoints in a Django application. It mirrors `genkit-plugin-flask` and `genkit-plugin-fastapi`: one decorator turns a `@ai.flow()` into a Django view that speaks the Genkit HTTP protocol (JSON envelope, optional SSE streaming, structured error responses).
3+
`genkit-django` exposes Genkit flows as HTTP endpoints in a Django application. It mirrors `genkit-flask` and `genkit-fastapi`: one decorator turns a `@ai.flow()` into a Django view that speaks the Genkit HTTP protocol (JSON envelope, optional SSE streaming, structured error responses).
44

55
## Install
66

77
```bash
8-
pip install genkit-plugin-django
8+
uv add genkit-django
99
```
1010

1111
## Usage

py/packages/genkit-django/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,6 @@ version = "0.9.0"
6767

6868
[project.urls]
6969
"Bug Tracker" = "https://github.com/genkit-ai/genkit/issues"
70-
Changelog = "https://github.com/genkit-ai/genkit/blob/main/py/packages/genkit-django/CHANGELOG.md"
7170
"Documentation" = "https://firebase.google.com/docs/genkit"
7271
"Homepage" = "https://github.com/genkit-ai/genkit"
7372
"Repository" = "https://github.com/genkit-ai/genkit/tree/main/py"

py/packages/genkit-evaluators/README.md

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,34 @@ No LLM or API keys required.
1111
## Installation
1212

1313
```bash
14-
pip install genkit-plugin-evaluators
14+
uv add genkit-evaluators
1515
```
1616

1717
## Usage
1818

1919
```python
2020
from genkit import Genkit
21-
from genkit_evaluators import GenkitEval
22-
23-
ai = Genkit(plugins=[GenkitEval()])
24-
25-
# Run evaluation with genkit eval-flow or programmatically
26-
evaluator = await ai.registry.resolve_evaluator('genkitEval/regex')
27-
result = await evaluator.run(
28-
input={
29-
'dataset': [
30-
{'input': 'sample', 'output': 'banana', 'reference': 'ba?a?a'},
31-
{'input': 'sample', 'output': 'apple', 'reference': 'ba?a?a'},
32-
],
33-
'evalRunId': 'test',
34-
}
21+
from genkit.evaluator import BaseDataPoint
22+
from genkit_evaluators import register_genkit_evaluators
23+
24+
ai = Genkit()
25+
register_genkit_evaluators(ai)
26+
27+
results = await ai.evaluate(
28+
evaluator='genkitEval/regex',
29+
dataset=[
30+
BaseDataPoint(input='sample', output='banana', reference='ba?a?a'),
31+
BaseDataPoint(input='sample', output='apple', reference='ba?a?a'),
32+
],
3533
)
3634
```
3735

36+
Or from the CLI:
37+
38+
```bash
39+
genkit eval:run datasets/example.json --evaluators=genkitEval/regex
40+
```
41+
3842
## Evaluators
3943

4044
- **genkitEval/regex** – Reference is a regex string. Output (stringified if needed) must match.

py/packages/genkit-evaluators/pyproject.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,10 @@ requires-python = ">=3.10"
4141
version = "0.9.0"
4242

4343
[project.urls]
44-
"Homepage" = "https://github.com/genkit-ai/genkit"
45-
"Repository" = "https://github.com/genkit-ai/genkit/tree/main/py"
44+
"Bug Tracker" = "https://github.com/genkit-ai/genkit/issues"
45+
"Documentation" = "https://firebase.google.com/docs/genkit"
46+
"Homepage" = "https://github.com/genkit-ai/genkit"
47+
"Repository" = "https://github.com/genkit-ai/genkit/tree/main/py"
4648

4749
[build-system]
4850
build-backend = "hatchling.build"

py/packages/genkit-fastapi/README.md

Lines changed: 94 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,118 @@
11
# Genkit FastAPI Plugin
22

3-
Serve Genkit flows as FastAPI endpoints.
3+
Expose Genkit flows and agents as HTTP endpoints in a FastAPI application.
44

55
## Installation
66

77
```bash
8-
pip install genkit-plugin-fastapi
8+
uv add genkit-fastapi genkit-google-genai
99
```
1010

1111
## Usage
1212

13+
### Serving Flows (`serve_flow`)
14+
15+
Use `serve_flow` to register a Genkit flow as a FastAPI endpoint:
16+
17+
```python
1318
from fastapi import FastAPI
1419
from genkit import Genkit
15-
from genkit_fastapi import genkit_fastapi_handler
20+
from genkit_fastapi import serve_flow
1621
from genkit_google_genai import GoogleAI
1722

18-
ai = Genkit(plugins=[GoogleAI()])
23+
ai = Genkit(plugins=[GoogleAI()], model='googleai/gemini-flash-latest')
1924
app = FastAPI()
2025

2126

27+
@ai.tool(description='Get current weather for a location')
28+
async def get_weather(location: str) -> str:
29+
return f'Sunny in {location}'
30+
31+
2232
@ai.flow()
2333
async def chat_flow(prompt: str) -> str:
24-
response = await ai.generate(prompt=prompt)
34+
response = await ai.generate(
35+
prompt=prompt,
36+
tools=[get_weather],
37+
)
2538
return response.text
2639

2740

28-
@app.post('/chat')
41+
# Mount flow endpoint at POST /api/chat_flow
42+
app.include_router(serve_flow(chat_flow), prefix='/api')
43+
```
44+
45+
### Serving Agents (`serve_agent`)
46+
47+
Use `serve_agent` to expose an agent as FastAPI routes (including `/getSnapshot` and `/abort` endpoints when session state storage is enabled):
48+
49+
```python
50+
from fastapi import FastAPI
51+
from genkit import Genkit
52+
from genkit_fastapi import serve_agent
53+
from genkit_google_genai import GoogleAI
54+
55+
ai = Genkit(plugins=[GoogleAI()], model='googleai/gemini-flash-latest')
56+
app = FastAPI()
57+
58+
59+
@ai.tool(description='Get current weather for a location')
60+
async def get_weather(location: str) -> str:
61+
return f'Sunny in {location}'
62+
63+
64+
weather_agent = ai.define_agent(
65+
name='weatherAgent',
66+
model='googleai/gemini-flash-latest',
67+
system='You are a helpful weather assistant.',
68+
tools=[get_weather],
69+
)
70+
71+
# Mount agent turn route at POST /api/weatherAgent (plus /getSnapshot and /abort companion endpoints)
72+
app.include_router(serve_agent(weather_agent), prefix='/api')
73+
```
74+
75+
### Custom Base Path & Dependency Injection
76+
77+
Customize the base path or resolve request context using FastAPI's dependency injection system:
78+
79+
```python
80+
from fastapi import Depends, Header
81+
from genkit_fastapi import serve_flow
82+
83+
84+
async def user_context(authorization: str = Header(...)):
85+
return {'uid': parse_token(authorization)}
86+
87+
88+
app.include_router(
89+
serve_flow(
90+
chat_flow,
91+
base_path='/chat',
92+
context_dependency=user_context,
93+
),
94+
prefix='/api',
95+
)
96+
```
97+
98+
### Decorator Handler (`genkit_fastapi_handler`)
99+
100+
For custom route definitions, you can also use `@genkit_fastapi_handler`:
101+
102+
```python
103+
from genkit_fastapi import genkit_fastapi_handler
104+
105+
106+
@app.post('/custom-chat', response_model=None)
29107
@genkit_fastapi_handler(ai)
30-
async def chat():
31-
return chat_flow
108+
@ai.flow()
109+
async def custom_chat(prompt: str) -> str:
110+
response = await ai.generate(
111+
prompt=prompt,
112+
tools=[get_weather],
113+
)
114+
return response.text
115+
```
32116

33117
## Running
34118

@@ -42,10 +126,10 @@ uvicorn main:app
42126

43127
## Streaming
44128

45-
The handler automatically supports streaming when the client sends `Accept: text/event-stream`:
129+
Endpoints automatically support streaming when the client sends `Accept: text/event-stream` or specifies `?stream=true`:
46130

47131
```bash
48-
curl -X POST http://localhost:8000/chat \
132+
curl -X POST http://localhost:8000/api/chat_flow \
49133
-H "Content-Type: application/json" \
50134
-H "Accept: text/event-stream" \
51135
-d '{"data": "Tell me a joke"}'

py/packages/genkit-fastapi/pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ version = "0.9.0"
5656

5757
[project.urls]
5858
"Bug Tracker" = "https://github.com/genkit-ai/genkit/issues"
59-
"Changelog" = "https://github.com/genkit-ai/genkit/blob/main/py/packages/genkit-fastapi/CHANGELOG.md"
6059
"Documentation" = "https://firebase.google.com/docs/genkit"
6160
"Homepage" = "https://github.com/genkit-ai/genkit"
6261
"Repository" = "https://github.com/genkit-ai/genkit/tree/main/py"

py/packages/genkit-flask/README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,31 @@
1-
# Genkit Flask plugin
1+
# Genkit Flask Plugin
22

3-
This Genkit plugin provides a set of tools and utilities for working with Flask.
3+
Expose Genkit flows as HTTP endpoints in a Flask application.
4+
5+
## Installation
6+
7+
```bash
8+
uv add genkit-flask genkit-google-genai
9+
```
10+
11+
## Usage
12+
13+
```python
14+
from flask import Flask
15+
from genkit import Genkit
16+
from genkit_flask import genkit_flask_handler
17+
from genkit_google_genai import GoogleAI
18+
19+
app = Flask(__name__)
20+
ai = Genkit(plugins=[GoogleAI()], model='googleai/gemini-flash-latest')
21+
22+
23+
@app.post('/api/greet')
24+
@genkit_flask_handler(ai)
25+
@ai.flow()
26+
async def greet_user(name: str) -> str:
27+
res = await ai.generate(prompt=f'Say hello to {name} in one sentence.')
28+
return res.text
29+
```
30+
31+
Requires Flask 3.1+.

py/packages/genkit-flask/pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ dependencies = [
4848
"pydantic>=2.10.5",
4949
"flask>=3.1.3",
5050
]
51-
description = "Genkit Firebase Plugin"
51+
description = "Genkit Flask Plugin"
5252
keywords = [
5353
"genkit",
5454
"ai",
@@ -68,7 +68,6 @@ version = "0.9.0"
6868

6969
[project.urls]
7070
"Bug Tracker" = "https://github.com/genkit-ai/genkit/issues"
71-
Changelog = "https://github.com/genkit-ai/genkit/blob/main/py/packages/genkit-flask/CHANGELOG.md"
7271
"Documentation" = "https://firebase.google.com/docs/genkit"
7372
"Homepage" = "https://github.com/genkit-ai/genkit"
7473
"Repository" = "https://github.com/genkit-ai/genkit/tree/main/py"

0 commit comments

Comments
 (0)