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.9.tar.gz (39.3 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.9-cp313-cp313-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.13Windows x86-64

genai_pyo3-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

genai_pyo3-0.1.9-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.7 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.9-cp312-cp312-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.12Windows x86-64

genai_pyo3-0.1.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.9-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

genai_pyo3-0.1.9-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.7 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.9-cp311-cp311-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.11Windows x86-64

genai_pyo3-0.1.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.9-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

genai_pyo3-0.1.9-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.7 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.9-cp310-cp310-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.10Windows x86-64

genai_pyo3-0.1.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.9-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

genai_pyo3-0.1.9-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.7 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.9-cp39-cp39-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.1.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.9-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

genai_pyo3-0.1.9-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.7 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.9.tar.gz.

File metadata

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

File hashes

Hashes for genai_pyo3-0.1.9.tar.gz
Algorithm Hash digest
SHA256 f756c8109a0060c3d49ab4a8b84f6820dca04b71b072485338ebe4d36771fd75
MD5 2c3eed27ddf5ec2e078250091aa8d594
BLAKE2b-256 b00b673c21d4aa5876c34726ad90d50b762c5346763271833b899883383a373b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.9-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 a79216348586dec2869ca4a1dffc9d3331c469e3a8e67157d40d460ccec55b67
MD5 577f7b49f0632f6fbfb5bbeb728783e3
BLAKE2b-256 987da10fab8221e485d8f631d87c521ae2c8d3a440bbb5f76b831071f570df0f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.9-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 77106d8d9888eea9e3990c2294bc3bf0e02a79f65efbd67ad0535aca5bd942d4
MD5 1600efc022313d08d4b0c189369cbe0d
BLAKE2b-256 04c933088ed96769ce4c46e93554f67785a74c774949c13b0513f6f653086396

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.1.9-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2a6a91131e80ec60f81fbb86b2eb87797ccfd80f3a197e019ce2aa01af524864
MD5 bc588096c4aae531441642ceb393e557
BLAKE2b-256 969096f1372230ad708f70ae75735554312207a31e67f61ddef45220e5793f39

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.9-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.9-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 6ad66acc97879b2f696f92954011d0b1960e275d75f89ddaa53ff08f68433066
MD5 879efc7d7d26cf639a56ae402f0bb00d
BLAKE2b-256 a5601e713e91a56408aa55557f0f458dea166e0e681792e1eace8881c3edaecc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.9-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3f49511c529ce5959e197ce945a1591b0fbe0b7c91c7035e0b8d939fab8174e3
MD5 170242ab414c4d83dbcf08289ee39613
BLAKE2b-256 088dbe8cbbd1e1d98a6dc2e477b4b562053ca83fcd56a939b0996eb67956f177

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.9-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 76ec105d1687747f0aec95dc71de259cc2142cd95a7b3710512e9d9655a514ad
MD5 00077f93048a95e738112222d1e01b50
BLAKE2b-256 9cdea70c96cfbdb6347a9d308fbedc4c924e2ee3ee13735f5808eec0b6a000cb

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.9-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.1.9-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 78430cd9af115e1954ff7e46bde52c87fdda597fdca35d373dea1ce94e3fc519
MD5 092236c70cc06d19ccea10b145b08324
BLAKE2b-256 d355124e2125b204e6e3f6cdbd9f9c7ae8483fa5e12b9f63cf5a6325f30530d8

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.9-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.9-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 1310fb37b46049a72b53993f479f1f5e7c72c4bc0b8baa26590f6596b5a50c67
MD5 ee44fc16a4389b53766d6752e1d15e02
BLAKE2b-256 4b056a1aa075c1ea3eac468ca1d79a48b07333d752c6f7c32b59a6a235e29d9d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.9-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 2f2b8a2aac92e27b063ccb517670df38355e2be3370db220fb611cbbb0e9bb41
MD5 c5d0e839b8a2f2ac7c377c0992398fb2
BLAKE2b-256 a85b0f706c1eab48f6eb6bcf9e1c74f7b0438c7869293bf2c5652b58a86dc34d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.9-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 befec491da2e166621be4bc098249ed23864dbe6a2f5351423ff443cde6db235
MD5 4a91cb1d146c88fb29f7e3f90a170554
BLAKE2b-256 bbdb796e3695e0c00f36d20db5d3ce07aba6ea04b20a1a90d578c4fff1a258cb

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.9-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.1.9-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bd05fcb3d83f733464552ed4479fb4edc0138116b3334121e697df8eb5f18344
MD5 0dd04e6ac8930ed653c67940040557f8
BLAKE2b-256 458bc9971f78f52d01a04209b3f2f6ce0a96f39e754c9d95ce898bf380372ec1

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.9-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.9-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 22cd685604ee496761450d0f1f717919b6b3b2b69f791bd4acfb96d0d78d79b8
MD5 0d455d66afde3cc67b0d10cf5966f1d9
BLAKE2b-256 11a6ac159a222d4e7e8eae01c07e77287f112f1d7c2816b2ddea2347e9b8ea83

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.9-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 dbb99ffbdefe63d9d35ad6a5d12e60c57727755466309aefa22a2e3753caf032
MD5 5903abb86c598060bba0156cf27a96f4
BLAKE2b-256 b7def457f518c2803758cdde3face9b4a0998688aa08536f30ea2f5aa0779566

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.9-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 af346896b7e7ae98abdb898f77b7f85d7e3f0d500d8be2ff9fb6bf97dfc961fb
MD5 68889a8582d755b130f8a2f0992b027f
BLAKE2b-256 42e1e62371c433372a62d349088d01a0f55afd29b0bc61508519757bbf26cde7

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.9-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.1.9-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 fe0041e6b69453ab909b11435e76e29b7d54cbb2fe47926e1b7762a4e669cafb
MD5 eb8e9f33a28531820412a0c349959898
BLAKE2b-256 a9c922b9581758eab776c2d639a81a46d1e60fba6ab46145f170aa88f4c3ffd7

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.9-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.9-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 58eec6c1ce3213de63c9ef2898d7daf255bdedffaf365e3e1eed0fcccb243ed7
MD5 0bec4ed460bb83b2abf9ad8da132c85e
BLAKE2b-256 c4bf3dea5058b67dc4e5be6d72ff7c0dc110c658b6a16a19a21c70032c5c648b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.9-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 70d2bec6f8a2d935f9f1db7f64196a2ea55cf85776862bab5516e47dd0cf552c
MD5 f250e4500a8a5b3bef73cebd42fa77c3
BLAKE2b-256 aa47490b42e6238ff28e9bef5471da0a497145a8dfdbb0640ec4e865156cda89

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.9-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ec6bb63f7772a4fcac8160b10b6e9337331f0cc22a1e16b0cd3fd43762a34d4d
MD5 7753efa3af92148962ad06ac6eb2f628
BLAKE2b-256 4b80506e8adda0131d95cb3f749fd9c65ce6cdddee84734cfdf505179cf3a833

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.9-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.1.9-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 48f8a36a9cbdc94d87a6184183370fe7b11b46c2e93067b7366dcf21e3497084
MD5 17461978515a81c510525c9dd0bbf80c
BLAKE2b-256 63df8e19de18312a06f0166987daf02fe9e240f94a8ccf2427804a6ba07986c0

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.9-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.9-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 e9c80516a688415c438e0aceaa7b586fc81b400e6cd08e9594a331b906bc5f25
MD5 e1f5215db02ad824c7f0479c5557be46
BLAKE2b-256 9d94d715e35d4f9e5ab14c130f1ef1325bccad8ed5b1b3fa31a2bad166150a1e

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