Skip to main content

Python bindings for rust-genai

Project description

genai-pyo3

Typed Python bindings for the Rust genai crate, built with pyo3 and maturin.

This repo uses the upstream GitHub repository for genai directly:

genai = { git = "https://github.com/jeremychone/rust-genai" }

What It Exposes

The Python extension currently exposes:

  • Client
  • ChatMessage
  • ChatRequest
  • ChatOptions
  • ChatResponse
  • ChatStreamEvent
  • StreamEnd
  • ToolCall
  • Usage

The main async entry points are:

  • await client.achat(model, request, options=None) for a full response
  • await client.astream_chat(model, request, options=None) for chunked streaming

Install

Editable install with uv:

uv pip install -e .

This builds the pyo3 extension and makes genai_pyo3 importable from the active environment.

Quick Start

Minimal async call:

import asyncio
from genai_pyo3 import ChatMessage, ChatOptions, ChatRequest, Client


async def main() -> None:
    client = Client()
    request = ChatRequest(
        messages=[ChatMessage("user", "Say hello in one short sentence")]
    )
    options = ChatOptions(temperature=0.2)

    response = await client.achat("gpt-4o-mini", request, options)
    print(response.text)


asyncio.run(main())

Minimal async streaming call:

import asyncio
from genai_pyo3 import ChatMessage, ChatOptions, ChatRequest, Client


async def main() -> None:
    client = Client()
    request = ChatRequest(
        messages=[ChatMessage("user", "Write three short bullet points about Rust")]
    )
    options = ChatOptions(capture_content=True, capture_usage=True)

    stream = await client.astream_chat("gpt-4o-mini", request, options)
    async for event in stream:
        print(event.kind, event.content)


asyncio.run(main())

Examples

  • examples/async_chat_basic.py: basic achat example
  • examples/async_stream_chat.py: basic astream_chat example
  • examples/client_overrides.py: explicit provider/API-key override example
  • examples/gemini_env.py: Gemini achat example using env vars
  • examples/gemini_stream_env.py: Gemini streaming example using env vars

Run The Gemini Examples

The Gemini examples use:

  • GEMINI_API_KEY
  • GEMINI_MODEL (optional, defaults to gemini-2.0-flash)
  • GEMINI_BASE_URL (optional, for custom or local Gemini-compatible endpoints)

Non-streaming:

GEMINI_API_KEY=your-key python examples/gemini_env.py

Streaming:

GEMINI_API_KEY=your-key python examples/gemini_stream_env.py

With a custom endpoint:

GEMINI_API_KEY=your-key \
GEMINI_BASE_URL=http://your-host/v1beta \
python examples/gemini_env.py
GEMINI_API_KEY=your-key \
GEMINI_BASE_URL=http://your-host/v1beta \
python examples/gemini_stream_env.py

If GEMINI_BASE_URL is unset, the examples use the default Gemini endpoint resolved by the underlying genai client.

Layout

  • Cargo.toml: Rust extension crate
  • pyproject.toml: Python package metadata and maturin config
  • python/genai_pyo3: Python package entrypoint
  • src/lib.rs: pyo3 binding implementation
  • examples/: small Python usage examples

Local Development

Create a virtualenv and install in editable mode:

cd genai-pyo3
python -m venv .venv
source .venv/bin/activate
uv pip install -e .

If you want stricter reproducibility, pin that dependency to a branch, tag, or revision.

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

genai_pyo3-0.1.2.tar.gz (33.5 kB view details)

Uploaded Source

Built Distributions

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

genai_pyo3-0.1.2-cp313-cp313-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.13Windows x86-64

genai_pyo3-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.2-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.4 MB view details)

Uploaded CPython 3.13macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

genai_pyo3-0.1.2-cp312-cp312-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.12Windows x86-64

genai_pyo3-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.2-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.4 MB view details)

Uploaded CPython 3.12macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

genai_pyo3-0.1.2-cp311-cp311-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.11Windows x86-64

genai_pyo3-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.2-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.4 MB view details)

Uploaded CPython 3.11macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

genai_pyo3-0.1.2-cp310-cp310-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.10Windows x86-64

genai_pyo3-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.2-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.4 MB view details)

Uploaded CPython 3.10macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

genai_pyo3-0.1.2-cp39-cp39-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.2-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.5 MB view details)

Uploaded CPython 3.9macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

File details

Details for the file genai_pyo3-0.1.2.tar.gz.

File metadata

  • Download URL: genai_pyo3-0.1.2.tar.gz
  • Upload date:
  • Size: 33.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.1

File hashes

Hashes for genai_pyo3-0.1.2.tar.gz
Algorithm Hash digest
SHA256 92247389783557e118a9dfa14e5b3a54560ea70fd7c25b534aca61f2502464e5
MD5 a732d0816d6abd85a18be9cefbfec1ae
BLAKE2b-256 03da69a5b461e74acda1be531c0a5087875fc2cd1d6fd877e7a403c8b8387993

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.2-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.1.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 276179c7efb572cd081a503df827dd95e54a2cda6cc6e665a6c80c51ccce1370
MD5 96fead891a700a3328ec702f7e1d2426
BLAKE2b-256 b8d43b44b0a87cc79c6ab75f6706b0edfa596935d58d3addcb1bf422d843e26d

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.1.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ae76265ca7f13b8b6d17d4d538ce25d08fb0a0414a643258ffc35e63b1bc27d2
MD5 ef28598869b87913f31d29b08f23a8bc
BLAKE2b-256 1c8223db427e0cf52fe3630a6eaca84a8bc6ecaa77c51230b61cce065b26edbf

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.2-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.1.2-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 dedb421101c4c08aae9f3a53a7e5c114a14b44b826d978d1d6a125939100ab74
MD5 532bd0a76f5c12241d1b99618054e6fa
BLAKE2b-256 71b16e64a9df7ab9f28a3e396d5d8d09b1092a4ebe95fff58e6524db58f3b816

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.2-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.1.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 82aae27fa2250c38903ce2da5c9f726f6bfed671d2485f2c1ebf75ca42b6c4ee
MD5 ef859317d1a45ad41e89ab4880e019e6
BLAKE2b-256 d79ce2efac1d267f84959ec0fb9845037ff02bddc10a22356fae5043cf2d97d2

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.1.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a8519079c42f528d0b23e410e31057e81add7d4ceb84515c9210e4b4751c90a8
MD5 73a46090e71953e86fae703c4738ad42
BLAKE2b-256 ebc204bc9e335e10c1130eaffd496a46b348ef9b11f5acfaa16b0d17ce8ef39f

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.2-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.1.2-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 61f22690c933acde0334f3304ea4d47aff4e1783362c8531f6190c871837b94c
MD5 d8931c883f10e8f721589df49f1bb164
BLAKE2b-256 c81131f25d866be729fc958f9dcdac79755bd1086da9e6f7acb9fee9124d7e49

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.2-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.1.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 29194ae09f462909792b34ed5c41cb85f8fc3cfc1651d3ea8be07b3e9f0672ee
MD5 51e30b0ed2dd9b66fff7ebd4b8ee795d
BLAKE2b-256 f9d14e0329a2d53e921bf1fc138c6597e11bcb0865b1b0a1e3f310e59af1ab4a

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.1.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 47ad99420bf110fae344f7f094bca9f06dec262d5bbd070c7fd4f820ed08176e
MD5 1ec2fd9b62faafefaa53ab91edbdb373
BLAKE2b-256 a86a4703f4518f703682ae7b75d89ff8fcc4d4fbfd97bfd06b1234d58486f502

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.2-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.1.2-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 d31aaa6312bb257119559f560f2f10299f636a324c77fdd42c8722063b4bd1ef
MD5 b7b818134635b8889ddcb2f2886f96ae
BLAKE2b-256 15894a0290fd068f2b14297c1477bf63185ab4ce767bdb7b2558ccdf5e4e2246

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.2-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.1.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ffd5e97b90fe6e4dc980024c2ef01a4db1d278061c39b6faf72cdcf6114ffb1e
MD5 22575aea288b1aa2e2ae39e0c6066c92
BLAKE2b-256 e0238493570bff1319aea48cd169f220341a4bb258763c9c7bdbf2844fe335ad

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.1.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6396fcfb86da063e3133625f8760380909ec46ec554f560f3c1e88a3ca80817a
MD5 abd5683a59ddb35896e55ba5e613797b
BLAKE2b-256 90d18ecace0c4506b34ca4d83a40dda5a477801170b79aa1f965f1250abb2666

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.2-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.1.2-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 863cddce31e1aa45a70ec98b4fb0ea20b85d694ba48c71a2847fa1243bcb9c6f
MD5 f2bff1bb13fe3645281a33eb05010bef
BLAKE2b-256 9b8fcd573f64e22b906ebe2d09bc5ccfb1de48c62a831d035a9e1d5b67e52a20

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.2-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.1.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 ea03a69fd6e9532710de7a90e19a9b6ce736073007d6e1fd764c77110de29fac
MD5 97704673943b408416605e9dff481a65
BLAKE2b-256 7a18e524399596ae7f765aad55845e22d47ab3be59c1aa3b76bf6734021c5b0e

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.1.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3d8740bb1bb710d7cdca49e4939cda519d6cd0ebc9ec0e7a711f09d821331719
MD5 550f11574c8c9626d9a0eab76e4fc917
BLAKE2b-256 63456bd39eca7fad1d306983e8675c231eb4fd7e9aed974a9253c53843a98db1

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.2-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.1.2-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 d7f477c5a21fdf9c2e676563b5f5ae68a717cbb4e57cc54a140fe3cee5d5ecc9
MD5 e8d9d1e706b944a51c9e10020cc01c78
BLAKE2b-256 0aabd4b8cb0082b43563d26e288382af475625167de27c7f7b7642e97558af75

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