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

Uploaded CPython 3.13Windows x86-64

genai_pyo3-0.1.14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.14-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.14-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.14-cp312-cp312-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.12Windows x86-64

genai_pyo3-0.1.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.14-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.14-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.14-cp311-cp311-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.11Windows x86-64

genai_pyo3-0.1.14-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.14-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.14-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.14-cp310-cp310-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.10Windows x86-64

genai_pyo3-0.1.14-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.14-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.14-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.14-cp39-cp39-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.1.14-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.14-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.14-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.14.tar.gz.

File metadata

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

File hashes

Hashes for genai_pyo3-0.1.14.tar.gz
Algorithm Hash digest
SHA256 0f7c218b9addea8fd2f597b845c1f7ca83c0e7f4e1c5190645ebc7117fb6f2cd
MD5 8e6d07af8b1e4d550289361425b6e68e
BLAKE2b-256 96cc31492a605f8daa95bb521e7859bf2218ca0201fb322ec0e90e54f95717b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.14-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 32f42fbdd099169bc415db200ec21b1c2964702a7f436558b2330e8cfafab09f
MD5 00a6969ac1e6414b827e438e3b2bec55
BLAKE2b-256 bbd280e3f476a1cd345eb3687795cc8069f7def33dee1e6d1b955800af001a90

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.14-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a5d6a69094f2d6466cb612c629191fb5ae6cf1bba3c863835bebf2b2df23c9ae
MD5 3d4df401cb34ad58d309c5ab2aeaeb27
BLAKE2b-256 d7a0e2485c1a9ecdcc9e0d2f47b1f4d3d709cd35d5fb54f9946693110de7839f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.14-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8c468efb69ad2e85daff5cfa727969b09a8b172f51ea3a93e5aa08ffb499e2e1
MD5 59a2660bcc7624550dd688433cad5dc1
BLAKE2b-256 95e561196118cb2b089d7397040feb1d8b9b409082d6885e06cdbe49989cd6d8

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.14-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.14-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 b2a6f8a619b4bd226c7ab1a7a2d5f16002363a8c9f33a432d795a1464165924a
MD5 43d8b1b585b58cce0a425dc8f507c8a2
BLAKE2b-256 3f86ae61a95e3eddec94cc9580ce9fa1845e9abba02cb8aa215e22b8d60079ae

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.14-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 772d03fdac8d52b0a085681a22178f73dc262eb930ed12396ec3e9501df594a7
MD5 3b001870dc7aeaf9b3d927911d94f0fb
BLAKE2b-256 32c57fc1586a6bcb6115d2df19d2f25cc0e8733a6b5732ec145e716fbe7465d3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.14-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0ea6ac101c1cb104ea8864962c3164400c212977cc601999a503ba423428988c
MD5 2f0ef26aed7aef865ba4d2676c13bdc9
BLAKE2b-256 636b6cb3839b0b9d5d95ed519cb23531ee8ae1224df0cddee89c3434c1d22bdc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.14-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 647971f4e56ba9600397dc92ee490a914db30ac81ae6884cda455b02a9977f33
MD5 d58d0f34a7fbc9e3eb9d026645a0a103
BLAKE2b-256 35a47fefadf837f8a793bee061f8ffd17b3765958e51852046e08adf9f7eee6d

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.14-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.14-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 6f6a34d08e9d7f745d2daeb9418c4f096866611970639ba016279a3acdd43102
MD5 45906ad8f18b90749d1b04db3e95a8ec
BLAKE2b-256 cb985c30fc00486e56f127fa2997c91478fee6787e4a8cf5f496d4b6bd096877

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.14-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 dfb851d58510c1ca58bebff434e1436dbe724710bc8e4dc3179a30ccc8a9f2cf
MD5 418c1507a7640556473012d459753b51
BLAKE2b-256 0779456a1650990e9004685b026fc8ce60b05ff079d0d9385e1cf1ef0c1bb278

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.14-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 dd7ae39857452c79f140f6b02d1de6462539976c003fed68c60f2f817d483eeb
MD5 330986f522b7f056323187dcc51e61bf
BLAKE2b-256 33876be3bfe8401c6b4353f9420b91c61804992c669eb35a3230174e4a270ef8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.14-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3fa41cca752a3d205163c1202d54960c3393af74e467444f6b0a8792d8fa2f28
MD5 43e6c5e376e369c10fa9e7e0eac28e3e
BLAKE2b-256 cfd6e5f982d5548f466ad6ad1975b2362714828e77f833d32dfdf63cb7a22005

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.14-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.14-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 2f54c772f27fecd67a130e8d757d1ca24d7ec451665eaed2363ef64f8592152c
MD5 1800d4b37ca9981a52062d9ee46a203e
BLAKE2b-256 140a3c470ac7fbd8aa26a774ccef9961d385e5b97a54d68b47d32c09e2515f05

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.14-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 75e7c89dc6f267ffe2a409337722743eae2263fa576310a48ed824c2efc1f1fa
MD5 bf5bb9f9e911cc45edd7cdfce98f9820
BLAKE2b-256 c968aaeadd219cc12fda291206e59b6352c2bd62f34e26350e9f9f62f64ceec6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.14-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b0e9c20da871f39adf66095727e7a1bff1b8d9d2da688108106522d7bd5739f0
MD5 6770431626421c9aad74b34a38ba70a9
BLAKE2b-256 7d360474a97deb4879bb2cba316312fb593f690f763c832054cc31617fca2601

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.14-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 07551b6e730c6c2b4146589a5919cb52275727d49913f24fb3f8bced60139a1a
MD5 d1c07a58e87967afe9926cc203be4754
BLAKE2b-256 06298a0af87527b8984a6d25538f76712dd1b37bd93d385b4d3563a527b3fd2f

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.14-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.14-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 9aaaa6cb2d8ceac9d91673ca81f412e0aade3e5c2c8a31bfe6a3a119af6d9f96
MD5 10443f91dc90de2c8244aa7dcc37a68f
BLAKE2b-256 69a1c2854c60d9a117928a4d2943e11e7b73998a99957dc34caf049b5c4c3379

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.14-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 71fce552f568326f823f79f2f9764f5d0914885e0d80756acea7a58bd0951bfd
MD5 1b4e6513f4d40a41202379f1431e528b
BLAKE2b-256 635506fdefd7a05108ccf5ca36e8d66d31ed0b08fe9de04c9a4047a57bd36f64

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.14-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9698d383b0039fee28bbbe57b80c903e0f30b1f982c6babc0b241b145966d9eb
MD5 d754456a4c724ae7d7cf5eb7afe3a3f6
BLAKE2b-256 d63e43dbcca3fa68212c8d66f669f2e31a3e6098a186dd664f10f8545ba3cf01

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.14-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 206cc316eb32d8114bb24a2ad0f209cf48b2fd0fa709c08dbd0832b1911ce033
MD5 945c7d80dd19e97a194763a355607af8
BLAKE2b-256 91c2b7a8ae57e54de304641f1eb75a84d433628f3eb3d1673242d000861a338c

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.14-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.14-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 c0bcb4dab2d85f4c1009fa6100fc7f64482f71eff6c87c9e452a48e7488fad6a
MD5 720ef03f5a831016f408e64fce1181c4
BLAKE2b-256 2f2622d2d302e50ff81ef7c361c0ffea5a4be2b9a9dcb9e3875732ef1a1f23f0

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