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

Uploaded CPython 3.13Windows x86-64

genai_pyo3-0.1.8-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.8-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.8-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.8-cp312-cp312-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.12Windows x86-64

genai_pyo3-0.1.8-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.8-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.8-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.8-cp311-cp311-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.11Windows x86-64

genai_pyo3-0.1.8-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.8-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.8-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.8-cp310-cp310-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.10Windows x86-64

genai_pyo3-0.1.8-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.8-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.8-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.8-cp39-cp39-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.1.8-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.8-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.8-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.8.tar.gz.

File metadata

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

File hashes

Hashes for genai_pyo3-0.1.8.tar.gz
Algorithm Hash digest
SHA256 7a31c804bba2fc7f0733584d5b4f1f23d08d109bcef1868e503a372fa29faf85
MD5 0e25d9f7c05607517a4a741e139ec6ca
BLAKE2b-256 a8ad74a0ddcf30bc4a86eb289df832adf08b6f786aa8cbab9b21ee8b85c23a61

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.8-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 55ba496afb047057ef145136648faf0e4c6c18705bb0aa90b95e300db9819248
MD5 ce0a1504bd685195ab53e6d25fa8ea18
BLAKE2b-256 f53d9f4313717bed94133a836a8d0364b62b69d87bc56bb913095a861e1bcec4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.8-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0f64db7b816c251c3d12aee8f3bcd62824eada4c4e00d74366c4f32995372128
MD5 6e1df0890bb24c625746cf1c21145991
BLAKE2b-256 e67c510d041cd496258fcde0d05cdbabc555c82245fbc16e0da91c1260dc01a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.8-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bc5007470cf014ffc15bf1725f11cd292d20b84c1280d2c1116236dcc32a9704
MD5 ec8e88658387f55fad629861439ca7fd
BLAKE2b-256 979bcca81dab41676d241aac10fd77b223068aa0bc268d35fa2994ccaaf8e556

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.8-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.8-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 ac2ab7e904ba758bee6206bd27d29048bd0b2812d2e2008b10c5b451e02e888a
MD5 b94e1548d2d30ba94835718d88b6e903
BLAKE2b-256 eab6803a0c225633856899054f6efc55243ca35a07fef14307dedc0867bd7bb6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.8-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 538a396460e9a598ebd5c1843ddf70991dbf9715bb1cc6e1a3c7c29a736e262a
MD5 cf01645aa867a8685ece59850a2a5f57
BLAKE2b-256 2d5981de76f284aadc9a09764167991ece28820dd2e9c2038335a82bea40b6a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.8-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 68eeefa41ccf40c4e74f2fbf9ea24e22416585e5789fbcda34eee4eabde8efd3
MD5 23b05b6689a4867c60e3ba9055abb176
BLAKE2b-256 bd5eccc8ec48d90cedf062642edc02f6ab244758bb430a51b76e447e95a71f14

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.8-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b99590f630fd4ea53a4e90c004a606bc685f2c6f3e4b6b47f14fba10807d3a40
MD5 8ada4945567eb6ca8d173b2362b9734f
BLAKE2b-256 6eb7150b63c5d5b169f5a12663deed1b740923ff0517fb6a10e42206fe780444

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.8-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.8-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 291620f97602ba9eea7b89c2fb48e2a3432e9f7a623a691670ae9ba21ff30aa1
MD5 2c21e61860b61cca63bf1a53221bedd2
BLAKE2b-256 5e7d3809658534e4f7ab0feb5de7b66895ddb91c63cc78823ccb7d1a2d5e1e04

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.8-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 8daaa35893eda42576f8faaf0dd85bb570869f410188f63e6aace81f8416829e
MD5 ff00ce9be02ac3e3d584591b9b1ddd38
BLAKE2b-256 ecd56f1726fa2689383a2c34b1530cd076b7067c968a719bfbb8dc55a5ac256b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.8-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0d7848640c3a6fad7eab6f3767311e344b30d7d42d209f985c36e39ce99602c4
MD5 7ca91912c481b5f53329a7b1160dd789
BLAKE2b-256 8c1703c01f9a7622b3921b87a0fd8cdf298a8d4916bf99cb16d4d64be18d91a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.8-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 13b37a745d992050e28f5e94ee2a328304eb00673f31b1ebabd2a057a336ed4f
MD5 d1d74f805de305765dea157c6769543f
BLAKE2b-256 6fe351f1ee8b3cf90abe115dfc6acc7a1283f5f819afd2b733c333014fbe0824

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.8-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.8-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 9ded7aa02bf45bd455a56fd19299f191b271340071e638f3ddea7c5ef3adf3e1
MD5 0ddc82c11beaa3dfd2d1e61c2781f079
BLAKE2b-256 3990f5718acf183d00aea0cc3987c409beeae56dea935a5a905b2673122f1af8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.8-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 3ac06b2a33a8f16cccac32c751a88d81bf913a170a3818ad4c0c694cdc54e130
MD5 7c75882f72919ffbea752f4fa234f40b
BLAKE2b-256 138dc5e37eff7afa0707d38196edfada7711c8cb8add1dd41c841e85088600b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.8-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 21dc365b853f89ef06b5d94062e2fe41e3cec43c9e1c0d759e42052193baeaf1
MD5 d4a27fc5ce7cac947e8fb6fa1657be3a
BLAKE2b-256 307330bde15ead876660ffef53c35f6b8dc76763e2a58bee4f0badb115c94546

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.8-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ce1bfdba8ed555d8ac602341f17f5f9577490fe965917513f5bc582e0b813227
MD5 1de6d05a36fcb1e5afdfd2db73d29d2c
BLAKE2b-256 6bfe26fbae62df673078acae843d4f301015d70453b9dee587fa2172e6157437

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.8-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.8-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 527f72599081862239e8532827107b02bec34477e72786f9445c9a0af9bcb380
MD5 bbcef0b4c29683dce588467e13bf6a17
BLAKE2b-256 2fa2c1c42127cd6d8bf29a1bf613e68f59f8cd907af3a061eef05e01dd52c53b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.8-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 895c8c1b86d2f152f3f68033f29e033cf04f4139805fd80bd6583d616b6d4ec3
MD5 cd01b5f8671dac9e45eb80af7719117f
BLAKE2b-256 a6ea53d54bcaea898cd50ee1d8f989b31e5a86f30aae78cdcc6b6890344c4d37

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.8-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 046464f758122b481b0214295cfc6b33c745b0aecce3d011a7055baa3165f52f
MD5 508ae36a4cc59d33979215ef9cb3e51e
BLAKE2b-256 6333693ce097d7907a42dda6b05db92409e9cc6b71d60fdbbe240e1f19ae2b79

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.8-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a454ce53330b58c66280304ccae5f4c9f96e269e530bfdf97707508c9df3dcd7
MD5 31f9f9f98faafd1f26467a66e20e8817
BLAKE2b-256 a73524c6433c2c1e69eb2530bcaa3855751b4ef06e7613718c6d9010712b7ee1

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.8-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.8-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 d28c875bb58f9465dc38b0ec1b628c757421e1cb1034094241bd98b6f27620fc
MD5 cd0a9afdb61c9544ad53da555457e518
BLAKE2b-256 9d0522eaa9e9c69ca01ed1993cdbee99c8937608abbae293d3439f9870a9a1ac

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