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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

genai_pyo3-0.1.17-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.17-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.17-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.1 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.17-cp310-cp310-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.10Windows x86-64

genai_pyo3-0.1.17-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.17-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.17-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.1 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.17-cp39-cp39-win_amd64.whl (4.0 MB view details)

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.1.17-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.17-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.17-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.1 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.17.tar.gz.

File metadata

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

File hashes

Hashes for genai_pyo3-0.1.17.tar.gz
Algorithm Hash digest
SHA256 5186ea2d0ee8dcebe987baddcaf0beab1d3d6daafd0d8bc8bfba7ca11ae3468a
MD5 f04bcfdb35c259fee44096a161f7daac
BLAKE2b-256 57b7a1d362af5aa23014fbd49224089a668962b7a880c8700c819663f30a5be5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.17-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 210bd03d21dd6288087096f8b18fe11729fb6b4fda902d93e0b9d0949b9ce3fa
MD5 0fb375c14712e4b5726a06004857168b
BLAKE2b-256 9242e06c5d7a78a3fb064dfabfb871e88eb4a7e8fffc4c1d675796144ef15bc6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.17-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8cf8f0d5867672e0849b5ada5fb8e6611fbf52534ebc32ceb90fca7c4f871df4
MD5 9209ba2794f6ad29e861f4cf061584d2
BLAKE2b-256 01289036f20f0f242b5d6fc6eee4d1fd16b53fee298dbe9a754ac3a91bde695b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.17-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f15bc4c513d80f812395a865e1637e92c0fd0316a8880c71ebe711bb5c5a65de
MD5 b9738088994b27930255c4f6f30ebbe3
BLAKE2b-256 3d984b81afd51f81225268d848f2110eaef25a47b4f90f80cd0a2dc238eb9d23

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.17-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.17-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 c63ad39318f9fc74403833bd7bbbffcbf954573e5cc2a372a29cedfc691071d1
MD5 c03daadfa149fda02a83818ffe83cdfd
BLAKE2b-256 4b50cee9a503d03bfbd91ea059effcd2256f86f6442728b86f7316fed827c4f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.17-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 d84f090ed6754e6946e31b6055ddca2be3ff7c352b6d3671e9f325268c3dc12b
MD5 5737782759fcf288a3355c5a0d981ce0
BLAKE2b-256 5d70ae3f741f3546c9c15becd119eda54448937b5a1c7ce74d4d2e603f02c6ad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.17-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9dcbadfd1f37e1e0635837caa4924011a49a30c8a377fde0393d73f90e108040
MD5 7698d27255e44936c1736405ba4d3406
BLAKE2b-256 75fc6127348f71450fc97ddc23acb1c0cae0a1f7ec7bdf2b9238e9a5d1053deb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.17-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2e563a4512c71f734800f0740db406c3fe2dbe5e49377fb9527c1b1ec148f2d7
MD5 7e8040ea7d6a3f9aaa5dc865696bb2b4
BLAKE2b-256 0e41faff7a1ca8d4ff0d7d9a0cd4de85dd4e2f7059a00bd6309cf7cab3bc7cea

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.17-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.17-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 85fa64e16e881b420058e99bb13052d71d443defd937907a611e9be059b56a97
MD5 308ce5f96960994d69cd05d2c9f74e2f
BLAKE2b-256 1e59f01230f44ed3c51f291516cdd5cb983891bb259270fee34773cb71a8a066

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.17-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 931581d4e7ebbadb6c8e14eb9d3e593722b00f1419c5b45b77a240c2e07a7641
MD5 20375c69933082a0507fbf2bd406b94c
BLAKE2b-256 6e849962da41c393af595c3edfb9303026126504fc06bc8a24cfbb603571c628

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.17-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8e104959cb129c2058f9ca0d38f015a99c6668244a2330f6f28feec49111b7af
MD5 52778f9b05889321628f368bdcf9c6d2
BLAKE2b-256 f70a6639f953467a9e686d54e30e2304a1e0a4af49ea54f4cba194b3d05a52f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.17-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c95c742e80d67a194ae47fc34de5289ccecca06978dcc52e3cf7f0eb7bbc494c
MD5 5c2734faea4843704ebb71d0c06f323b
BLAKE2b-256 d701569c9b6e270a30409808ad271c874f757a6d3e9038257fbc831767201e36

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.17-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.17-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 ffd406accec25fc2c4e8fdc30a65ec555f142431303095ccb6e58af08cfa37c9
MD5 fe6eab58f279b55bc9215d50a6b8a612
BLAKE2b-256 018019a0f8c659549ebbbfeeb30ce155dfd6b052bedd3e3e69e5d58ece100d07

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.17-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 85d6b842447f633161afeb245e67abfeab27d9917fed8a2e38ccd53c212ab593
MD5 7b292a298ea67f18619bbf46be3eac62
BLAKE2b-256 7901889e65fc5186c2ee2ec72f049d3df0a11847a9ede43fe5265bf5814a807f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.17-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 06f4307fc4bc0eb8b560fb1b986907c23eeca01cc072d937a0a74c099ce08017
MD5 ecf4eb1cde1bdc78f2211fee661c46e5
BLAKE2b-256 f2ec18b98dad130c433fadaf765c3d36df7c1060430e7fcbbe63bf97a8803838

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.17-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6d7811f28955081e838bf0e00041086df4e2b083d7aab46df3ac8d014dad152f
MD5 fb179f7dcdec7a223a1cfb8eaceb6274
BLAKE2b-256 faf719ebf4b784a36cecf778831f3ffbfbdd7acf91eb515f46197e9d95218a3b

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.17-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.17-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 6b5c6c5df0505ec79aea551385e1d7f782cdc15dce7213ea2af1ae274a8c40d8
MD5 770524a23c516b9cbc9cb9ce178ef8ee
BLAKE2b-256 84a64b3e5b8b027386baf2e015e41a81a5f09ad4fc18c32ec02f406c417a975f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.17-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 5c6005d511b6128e351b184aa081445f5eabbb56747eb3a98168bbd7609d842c
MD5 fa5d1ec3d10293325e2d88443108531c
BLAKE2b-256 5bf08e59964aef6bda97c17807384e11cbc0e5ce7cf617d64e4566fd389f3c32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.17-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d677cab1936bd6cc6b341237057a25112dbf6c240a2707cd972997e48c0f4307
MD5 e76fb85d5459cb961361695586a66447
BLAKE2b-256 4bab6d4b4ec6701647f79cc9933b0a5049d78eb9542ae1bc03006bafaf9a4562

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.17-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d391f513451e8ecba1f5ef4f417d5cb5878767c822c6cd6b0312eb2ef88efa29
MD5 0ba366ec5a7c957fef218b4b4e4ff06b
BLAKE2b-256 fb9fc9ad1bf15d219fcb1bef49e351cb7c5a776190cfbf6424625e8d32d6aafd

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.17-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.17-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 fc4944d72295b298d7717d583189ed6727504e80ec93dcf689a8ad4861d11666
MD5 aba9f247a026183c1d6a4d7d6a766146
BLAKE2b-256 3494e581b584c5ea83a8175f89ad7890a73149fa2e06ea71e5514d6e18b46b07

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