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.6.0.tar.gz (47.1 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.6.0-cp313-cp313-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.13Windows x86-64

genai_pyo3-0.6.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

genai_pyo3-0.6.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

genai_pyo3-0.6.0-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.3 MB view details)

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

genai_pyo3-0.6.0-cp312-cp312-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.12Windows x86-64

genai_pyo3-0.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

genai_pyo3-0.6.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

genai_pyo3-0.6.0-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.3 MB view details)

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

genai_pyo3-0.6.0-cp311-cp311-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.11Windows x86-64

genai_pyo3-0.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

genai_pyo3-0.6.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

genai_pyo3-0.6.0-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.3 MB view details)

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

genai_pyo3-0.6.0-cp310-cp310-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.10Windows x86-64

genai_pyo3-0.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

genai_pyo3-0.6.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

genai_pyo3-0.6.0-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.3 MB view details)

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

genai_pyo3-0.6.0-cp39-cp39-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.6.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

genai_pyo3-0.6.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

genai_pyo3-0.6.0-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.3 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.6.0.tar.gz.

File metadata

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

File hashes

Hashes for genai_pyo3-0.6.0.tar.gz
Algorithm Hash digest
SHA256 416328b57eacc10a12f68b076f2b5260ef75a83f94cf584fb100aa48e28c5dd5
MD5 d784622e27ac77e51cb1b6cef64a2541
BLAKE2b-256 892ff7ff5fa478a2041bc907aceb12f3854fe1b3729f953284ee4f48ce991a84

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 bbc4215b5a0c57b6b112f4d7876a23db510149506f8d90b413812677665dafab
MD5 30305b7e2178e409adcf699239432cc7
BLAKE2b-256 4e0921374d772c2e15eda62b8df30fac6d62cca050ad684f806fcf24ee7a87ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d4b926d45e5c9e441019890f13bacea557c3f84717d568b3f8c685ac070056fe
MD5 b3a9a6c5cff2bd0adefea933f5ca6ede
BLAKE2b-256 946059e147bcae32136fa9b1e6cbc9c718ba3e0186ebacfba5a4969fe9462d4a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c60f6579de4321396e70b82fb074612565687a9fdc97d8e5d35e3dc8e3eb5f32
MD5 dde6f78c97e843c9d8fc6151ca5b645b
BLAKE2b-256 71dcae1858923636175aa1df31172584985dcf8afe23ffc8594469981ddc3f17

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.0-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.6.0-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 bd5c4b1cdfd687cc8f1db60608ae4f42bc6d9285504a5a2c0076e568284fa407
MD5 46ab8785eeb932097bc7694ff0887b59
BLAKE2b-256 aac81fca594c5f6b8e127f38d1a8104a0dd36e95c8e7ff339a129481d404cbf3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 f0f820fb4a1067c187ac964cb29932e149727b1ea10dffcaca95604d538a3d5b
MD5 7e930e416c7fd5842970759fb8ee72ff
BLAKE2b-256 c3c2cda052dd0890a530a8eff1821d709f547b6838af32f67047ab129e12d1aa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 87b71108519390d9e0fbac6f232a85b0e48916292eb7fdddcd598cbb9d443db5
MD5 1bd3a18b6f24adbadcc3b788203c4cf8
BLAKE2b-256 4bd9b340a47c3f1337eb96ae9b0ebcf1e363db8e32b905b66f5b98f09c8ba4f5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b14bae140a1590d1887effbc126a094b82ce9f8f6c70e936374f4ac70cd40149
MD5 1aaaa3bb7b8ee0626a2fd3109059d8a6
BLAKE2b-256 4cc79c0ff2b5a2fc40f80bc4e1e22bc196d51e8abfc741d29f7d50d37b89816f

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.0-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.6.0-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 d22a288b6697c924deba81198a56a68e343133f5b966da3f9120d9039cfee81f
MD5 d3197a982b61373b727b3c0acc99dc4a
BLAKE2b-256 69083156047139334e069b9eb507deb8ec733b18a1f518c14ffadbcab44747ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 73a6a2ac91593b96fcb0a59acda715f18bd04c8553847eb8067d5f863a31e600
MD5 43543c28729d84b92ea948ba36be2d8e
BLAKE2b-256 ce838c12f2a10076ec70ca1204e7d93a1cb55a64ebd1b27c588a29c29df71ecc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 634984b96eabcf6c7900b22cc9709d656509cf6febfcfd35b740410f22fa403b
MD5 4c7b3baa8e9c4e228310c75da85dd4e2
BLAKE2b-256 5eabda8cc91cb0581accf5552e69d0e42be1aca7d45e22356099e2e214223d3b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 39e1b2209029fc60efdfee0f5685926c7bc45dc5c7aeb68c07a850c7bd4c31de
MD5 a3c1106186dc754999cf2848e0bd6b01
BLAKE2b-256 e0f85e1b26636d4e2728ae9ba7c547c85e768fe5ef34275165ee22d7b66e0353

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.0-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.6.0-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 f0e1881c9cf59d5bd7783aa30f0eb9f3985d3430e0d272f1fc3bfa50973f42b6
MD5 5a3c0e419e76b593767113e6d5ae85f6
BLAKE2b-256 23828f15bdc95d18784c81ddec1e88aae60b7b849f2034c169e0057ddc4c6fa5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8bf43c41f599e8af57b7dd046848ffd65ee5eb4bae23ce656bc6460bb2875ee9
MD5 4b357898a0734825762da5e8f7ebc355
BLAKE2b-256 8efad54a3812ed236e739289d458c240063f94fb6a67fedf9ac464b41632c86a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e8fba9b99d9cd84dccc243746d23012ebe44838b1d59ed9d41c29d10d09f3bbd
MD5 c147bfe0f40b4552e94e9f0741648777
BLAKE2b-256 c280c9b3365ee107da1211a9650149507eed06250b56b50cecd594a6bd0d31cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6bdd00f8dd59d802b56412f3ae100d0a2b303513abf4b906cc60cccb79431f7f
MD5 d1f5e41554a2f36dec12656dd208499e
BLAKE2b-256 20b3d3c2e9e348e0b5902ebb835b654a03b5dcd6bf853a55c768e07e41e5902c

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.0-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.6.0-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 0641217ca68d05fcd95429b50071f2304648792538169cc548607df2b5e5a1a2
MD5 41288e8db20e11f59b8c7568f351a0aa
BLAKE2b-256 c7da79829d8384659019b42cccdf9c27dc40d435866ca1c36bd6ce575369c5a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f02276e8fd32311c67d149107def6eaefc417dbb95aa28e1ebc21214627d923d
MD5 7430d40d7bc36703f126be09076c43a7
BLAKE2b-256 93f71b3b77d4ac07027f264d0ff3ecf219dc02077b49caadc7889fbf78453456

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2004c913baf20a2dd6d580b23f23a0e5bb3c3eca91ca9279431b347087c213e1
MD5 c0dfdd657d1f816aa15aac6194c5342f
BLAKE2b-256 c5fdf8536ce23c006057c75405f4d30a48d6034d8031f98c8a672b5b23b1d208

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 99eca51b1b1f0e88f910976a6eec16025e94338dac413d25526fff2fdd2231f1
MD5 8e5223ff184b309403cf25896d70f8c0
BLAKE2b-256 2cf9b047a700f9afee43272d649c3e0f455e75b0d6d1f656e83d4e8e0faef763

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.0-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.6.0-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 855860e9343cb8789f49d6a7a2aaa8245ca78fc091e77516a1be58adcde4c4f4
MD5 3dbdb5a73434f71e7536e58391fb5e3b
BLAKE2b-256 b3a6ea8d3208cde110db0ed54fcef7a26dc1f367df3e7355d8b0485ede2c30be

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