Skip to main content

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 = Quill(
    private_key=os.getenv("QULL_PRIVATE_KEY"),
    database_connection_string=os.getenv("POSTGRES_READ"),
    database_type="postgresql"
)

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 = 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 = Quill(
    private_key=os.getenv("QULL_PRIVATE_KEY"),
    database_connection_string=os.getenv("POSTGRES_READ"),
    database_type="postgresql"
)

@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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

quillsql-2.2.10.tar.gz (26.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

quillsql-2.2.10-py3-none-any.whl (27.8 kB view details)

Uploaded Python 3

File details

Details for the file quillsql-2.2.10.tar.gz.

File metadata

  • Download URL: quillsql-2.2.10.tar.gz
  • Upload date:
  • Size: 26.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for quillsql-2.2.10.tar.gz
Algorithm Hash digest
SHA256 dc55fb77a7e4b0d68cb3b4a9f2d52f67b5a323651e6d8c84822ae6b9d46fc42b
MD5 d9b3a446b6ecb8ececbfe36b56970ae9
BLAKE2b-256 ab8e7d47660ae88242db711d4acdac1fd6a5fbfe392e5ac3d01e8e35c82c3eb9

See more details on using hashes here.

File details

Details for the file quillsql-2.2.10-py3-none-any.whl.

File metadata

  • Download URL: quillsql-2.2.10-py3-none-any.whl
  • Upload date:
  • Size: 27.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.6

File hashes

Hashes for quillsql-2.2.10-py3-none-any.whl
Algorithm Hash digest
SHA256 89d5c50f57f9e555667f674618f8c199a2bf0ec4a388e60122bdf4469e5ada34
MD5 77777e4d6f08007ba7a2a13b6b984882
BLAKE2b-256 ee516342756ff8692c0e231f153d720e35ee8c13ce3814b8ba1c932d5ccf3a70

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page