Quill SDK for Python.
Project description
Quill Python SDK
Quickstart
First, install the quillsql package by running:
$ pip install quillsql
Then, add a /quill endpoint to your existing python server. For example, if
you were running a FASTAPI app, you would just add the endpoint like this:
from quillsql import Quill
quill = None
@app.on_event("startup")
async def startup_event():
global quill
quill = await Quill.create(
private_key=os.getenv("QULL_PRIVATE_KEY"),
database_connection_string=os.getenv("POSTGRES_READ"),
database_type="postgresql"
)
@app.on_event("shutdown")
async def shutdown_event():
if quill is not None:
await quill.aclose()
security = HTTPBearer()
async def authenticate_jwt(token: str = Depends(security)):
# Your JWT validation logic here
# Return user object or raise HTTPException
user = validate_jwt_token(token.credentials)
return user
@app.post("/quill")
async def quill_post(data: Request, user: dict = Depends(authenticate_jwt)):
# assuming user fetched via auth middleware has an userId
user_id = user["user_id"]
body = await data.json()
metadata = body.get("metadata")
result = await quill.query(
tenants=[{"tenantField": "user_id", "tenantIds": [user_id]}],
metadata=metadata
)
return result
Then you can run your app like normally. Pass in this route to our react library on the frontend and you all set!
Streaming
from quillsql import Quill
from fastapi.responses import StreamingResponse
import asyncio
quill = None
@app.on_event("startup")
async def startup_event():
global quill
quill = await Quill.create(
private_key=os.getenv("QULL_PRIVATE_KEY"),
database_connection_string=os.getenv("POSTGRES_READ"),
database_type="postgresql"
)
@app.on_event("shutdown")
async def shutdown_event():
if quill is not None:
await quill.aclose()
@app.post("/quill-stream")
async def quill_post(data: Request, user: dict = Depends(authenticate_jwt)):
# assuming user fetched via auth middleware has an userId
user_id = user["user_id"]
body = await data.json()
metadata = body.get("metadata")
quill_stream = quill.stream(
tenants=[{"tenantField": "user_id", "tenantIds": [user_id]}],
metadata=metadata,
)
async def event_generator():
# Full event types list: https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol#data-stream-protocol
async for event in quill_stream:
if event["type"] == "start":
pass
elif event["type"] == "text-delta":
yield event['delta']
elif event["type"] == "finish":
return
elif event["type"] == "error":
yield event['errorText']
await asyncio.sleep(0)
return StreamingResponse(event_generator(), media_type="text/event-stream")
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file quillsql-3.0.2.tar.gz.
File metadata
- Download URL: quillsql-3.0.2.tar.gz
- Upload date:
- Size: 31.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4be41ff4db7d5e4ec86611441c5ee7dd42fbb5aefd6d34121806068c089815c8
|
|
| MD5 |
b35f64a23ec9bce1bbe308e3465455a1
|
|
| BLAKE2b-256 |
d6dd8c3ff88874bf32e8ef8f3f26b294113ae20fa030e47843137dfe56248b11
|
File details
Details for the file quillsql-3.0.2-py3-none-any.whl.
File metadata
- Download URL: quillsql-3.0.2-py3-none-any.whl
- Upload date:
- Size: 32.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a73732af9f4884ca0bf2cea581fef7582f99d9049ada3b4273c601259eb56df
|
|
| MD5 |
827fe1bda7cadff4d7273042c4b9af36
|
|
| BLAKE2b-256 |
4a0d1271672d41cfe9ebe72b84ca734565670ee1b6239cacd11a53bd88a948d0
|