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.11.tar.gz (41.2 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.11-cp313-cp313-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.13Windows x86-64

genai_pyo3-0.1.11-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.11-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

genai_pyo3-0.1.11-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.0 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.11-cp312-cp312-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.12Windows x86-64

genai_pyo3-0.1.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.11-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

genai_pyo3-0.1.11-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.0 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.11-cp311-cp311-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.11Windows x86-64

genai_pyo3-0.1.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.11-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

genai_pyo3-0.1.11-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.0 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.11-cp310-cp310-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.10Windows x86-64

genai_pyo3-0.1.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.11-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

genai_pyo3-0.1.11-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.0 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.11-cp39-cp39-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.1.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.11-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.8 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

genai_pyo3-0.1.11-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.0 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.11.tar.gz.

File metadata

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

File hashes

Hashes for genai_pyo3-0.1.11.tar.gz
Algorithm Hash digest
SHA256 590bfe3ef048880cf601ae329f7243b9d9744404822e44561f2b30152e6c36a9
MD5 abd87cdb9c1f3ebc9ffddaf61568c676
BLAKE2b-256 eda19a5410774de262775da5d644171b4e30fc9352f9aa2c8206f67c95beef10

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.11-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 6e8698f83d6a1c04be590850029861c322c7c59cf8ff7959b703bb8efb482c6b
MD5 4c19a8860b54952f0be539c6fafb76d3
BLAKE2b-256 84ac5ebfff5e52d9f6cf59b250708fd571352a0802be643e30b3ccc0b9f00235

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.11-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 93ede85a0a2a6b1410ae17e5c49fc0fc10814bcdc84f1cb6f69c336e4157f985
MD5 7910b81a90708095ff62c208d9a7ecdc
BLAKE2b-256 7ad5754c5111d3984775195c1e10efb106a69a7d092a38ce1c863203658288fd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.11-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 154795e205701d51d8bf6718bdf8bba88354e31da5b53342b087372a7b8e13f9
MD5 a2e2cea7be6b44bcd81e5367906d60a5
BLAKE2b-256 88123a0361c03b90539e6d4255c9354389e3bf620519b0b2f31b03d4ee097f63

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.11-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.11-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 27e7a5f92ced67d10c24432a62aacfeac23c37f7ad51e13075e27790803dc845
MD5 395699befdb5eb30032ec14df1dcda91
BLAKE2b-256 3c15614f0872b64961179c9fd27c39834382caa1d3995eb2b27cfc15d0735c92

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.11-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 dfd1e4fcd6e6a9cdde067cf434ee0bb80ead53391f2148ba1a19145f4cbb2495
MD5 29b754d0364e35803f7f5db154c459fd
BLAKE2b-256 e7b90ce3938bea06b525ceadacd972763aa6f7dff0c3295168a218463a04dc3a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.11-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f44a488cc586a4bb5c323bf31388ca68719bd1e125a4ddde1c4a1cd941c156cb
MD5 25bc33a63bad5cedf463a55ece24e2da
BLAKE2b-256 9a633bce5f26b7d637c49a770e001366ed8a5240eb705515e365893b577003cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.11-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 222a28614ee51cfac4cfa7377fa9e7fe14430bca2283c2d27b26e59df7dea549
MD5 4a8f0158e4c6d60e4d4f373b8600ff6a
BLAKE2b-256 0f8b94c6ae7bae81a596ca86f64558d98efc09a52f596e1acddd783480e4c957

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.11-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.11-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 3c02f976de1897d1634274e017ccde2ffcf4bebe0325fdb6772891eb7b9c5999
MD5 8c4554f1a4497276107ad89b1d8648e4
BLAKE2b-256 1c0510ddca0ea23aad6d34c6b05fc7c8f790dd56ef8fdb497d7a6801199f98a7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.11-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 0fff9e5e3177ec27f93b589d20dd8f0be4a297fac3bfa72ac3de3b0802950bed
MD5 a49b0d75920b37b637110e898ec87107
BLAKE2b-256 83e504017300bc5670eea7b0bee4b3f04a37426d1ccd7252ac59e64544688a7b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.11-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 59470384573116542edb6f0b89bf13aaff3b855631a8fb6eb7fd834936c2fb5e
MD5 632eb248adbc2fa15a7c12e84c808539
BLAKE2b-256 b4522efffa0bdb58e17e1234797a775bdf7388f655f575a88cb280ccc1be01d2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.11-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 52fc01a16b879ae5f059af04f817d8993c2a1dd5e301d5fed70d02c7c7f07851
MD5 9a297d5ebfaf152c6aece0c1b4859d37
BLAKE2b-256 2b166d39e6b2ce3c7dcc518440d8f617b3605db3911bca8407e8e5c8fb86e3cd

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.11-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.11-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 32879efea6638f042cf45789e5c734c80d1e9b81ac6a0a76aff37a1d3ec17100
MD5 8238d1da8b3ac6bc8118fd8725f29982
BLAKE2b-256 c7d13fae170156840597e7a22b6c7c53c47e3e36520107328a22398bd96089ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.11-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 9d34048c276ceacb089722ff75538e0841b6a800adf5ac8ea671d9fa6dff0516
MD5 f18f529b005555cb1bd9da0213ccd0df
BLAKE2b-256 14c46b6bb9b649b40c2ab505c6c558333778c127fd55570610f861876e0e10c6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.11-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6d0fea3a3beadb682a684a5305f31c31e6697b873052f22dced143880d6a471a
MD5 023c219f1ab57007c8425391116458b5
BLAKE2b-256 31f226f2fb14cf0d0107bbf55dbd300f322d2e66ed038488e0551beef770b292

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.11-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a90bb8766149f4a83f913fb806ea57b1dd2df55d9fc7065e8be25fec46b750ac
MD5 b7ea4ac6831f26b0f2ab1802d24ac78f
BLAKE2b-256 de8175d9c2b01eb16ae2c43e831525cd6e7cae8c4d3cf4d2f9b1e97a671e0678

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.11-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.11-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 217065859e2eca528f25ff3f7452ee5c4e041933363b123b87fb4c90850836d2
MD5 1a72fe35ab719bee9c33a0a05bb13e59
BLAKE2b-256 ac1c2fdb54d17ce74098331badf5f18d2575740d09873949ef62a8864f1d85cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.11-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 e4acc1af79b83f133eef5987352fbd900bf8e5632e521a80b7d0ce50b627e098
MD5 05ff57f9f3fbcd0f5e96a5aef5d2e033
BLAKE2b-256 94f9d61b394d3efd93b15ac26c1d6bdadcb451b8b7df4757a6c50eb59227f124

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.11-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3041dc7c4bc2c6696e996043de84d065f827d205a1504e2e25c344b4b365f392
MD5 e9e7ee203b357d290951402172949f6e
BLAKE2b-256 bef0de2c7d3678844390cdee1954338e368e15b61ee93f314c24aab4da847ed2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.11-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6dbfd1bdbbf4039eaf3eb4b8e93758582646598f19532247750cd4e12ceda1fd
MD5 c2f72344e7e399339f0c031e84fd7d49
BLAKE2b-256 16b9e6cbd81e8af06562110feda3c357bf8003b6663c28db262f22270b5b7c2f

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.11-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.11-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 2fcfd3e8f976d38bb445d083a891926d49a2a84cf95f1e44cf1bf40663193c8a
MD5 e79a1e5108b4bfa0f36d75d4c47de28b
BLAKE2b-256 d7a2db1ff9b46efff46d32b8de88ec7034e714063255a885223bae07d02e5899

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