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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.1.10-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.10-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.10-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.10.tar.gz.

File metadata

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

File hashes

Hashes for genai_pyo3-0.1.10.tar.gz
Algorithm Hash digest
SHA256 44dcb7539bddabe2a65ed32455c77b8525e9171cb495b08fa7c3fbf5222f1a6d
MD5 f3e59d0d3e3b15c5886d1a959ab89735
BLAKE2b-256 6324888d1af9dcb75ed4805e88d2474b00b3b528a7e870e00b3541e0657a8094

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.10-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ef471470102858bebe40aa83d79c0e3111ee46fe3356dcb16b4c2c678350fa93
MD5 6f8604c5b83164d230fab137bc66d0e7
BLAKE2b-256 c619ece7ff01779403327c414eb8723761f7bd834d57df6d3916afb86594630d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.10-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ae72067ea05637930168156918da326f82ae48bf045d323fb5d0eae45d5d1807
MD5 a6d2d54d993683454e856731bf18e053
BLAKE2b-256 511874caf65142927fd1fbe487514e1672bb6dee5d7bf6374b3646ddd57749f2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.10-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1981500bb03f11aaf7fcdc93b30d85e586b68b32a0cba5d915954572e8608981
MD5 cda667b030e208b356a02ddb060385b1
BLAKE2b-256 1f7a860aaa9990622104cdafec6c31bab0ae9401f57440002ce0b3bb9415a46e

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.10-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.10-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 0da7baa12e60a2a069841ff901f43424c3e4dcc87ad47382c7d88c5e54c8b271
MD5 e910e4caa6029e542ce204f609e3ef27
BLAKE2b-256 6ce6f46e6e52f9becd32d00794c34cfd6819ba6053d1baa84b3e34fcc5386382

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.10-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 321b1cb5bd2f12377e7fddb68f23316cb432cbc812b323fe105a865e2dfa6e7e
MD5 c6b59514b5a8228ec9f6abff1b5fe4fc
BLAKE2b-256 b6fcea18edeb45a9c8cacf89e7439cf19afbe2f9f09b23bd3cedd2e3e7b386fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.10-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 1b7d5493a288d3819e257d5fb2b91bac7f33de105fe3fff367fe1568709b3ffd
MD5 51874b0d23039f748c9548177721603b
BLAKE2b-256 2e39479f3e2caa84d4231c91cabd35a9f6081e6e5e5f2fdea1edf275825d8c61

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.10-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ae27e602bc3a072d087f970fb326e65436ab61c9825a7e345f5aebbb50b2ae31
MD5 2f960909f9f31ac212040e2b233be0a9
BLAKE2b-256 bffc534bab18d8405c908e670657690cb057c73c8f9b170170391265f3d806e3

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.10-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.10-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 46433edc0387eb0cba4df7b8f4da79e1d6430e1dcbf5679c625de4d685bc122e
MD5 0c30f0973319564322073837e05a80b6
BLAKE2b-256 1f19df4df22eddd5d4aa9e4e1eef04b4196221d5899a468c4d821a34e9f54668

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.10-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 410cc21e72eeca4955f97a3f70fafb228c0b4a6fb6001a701db572826fd63662
MD5 1be8043feb955a5df065ee44d7b8a433
BLAKE2b-256 fef66c149dc815e3bc8ea7bcca2ac685d55c469edfefa562bb2cb664711630c5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.10-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b0d219b32abd719a95482eacce9f77984c7946e3a869d8f018279fe028aa02b9
MD5 81707ae7a8c46319ad371c86c1960346
BLAKE2b-256 fa536d876685237ba01c187c7f57d1d0c1b31091e22e19ad8e2582246eae196d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.10-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 cc695101c8e36363f362b9c64e826fc0c073dea71532acb83c8d50ba89db3a91
MD5 81681ffbc8999253a85ab36662647f2e
BLAKE2b-256 d30684a6b7a7221189ee58c6e03aad7c39d6a3065eb26427bcaf43bce5330a14

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.10-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.10-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 8ec41530f234a927c30cea46fd74eedeee5675dfb6d069ed587d8b4bac536727
MD5 da3fea39721619dc5c2d566a506ff824
BLAKE2b-256 5971ce48aa08ee61b2002afab940f1cf90c713ac5d0449525b8c045e506af59b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.10-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 adfe98e25f9cbfa14cd6d5972302944e06c3ce3396d3f46ca3be32af527d4cb6
MD5 5d5af1dbd566f825c2122029bd91ccfc
BLAKE2b-256 3afc1c6bd9460d00f7400652f2e1cc7f810ba5776147ded6765ff9bc81ff11ed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.10-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 632e08d320013f2a56ba31e392f0c5b6baf018c1027863cd131f3cdbd9b85122
MD5 9515a6247c2a35a47c221d85c7984b80
BLAKE2b-256 aaf4bd87f1eb1ee4e11a7b80f3bc19d2b84c9663d873246a83359d92c006234a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.10-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 218c5d86cdcf3cc574324b2fda8c92eb6229d498b21a0a302c3e0004747c2cb0
MD5 0be1ad79211f2d1ba9ed01714ae8708f
BLAKE2b-256 ecb44fb61137cddfb3c48527226dd5a65e8807b4242d7e2825071bcd034bf385

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.10-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.10-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 bebce671ced084ff800efade0ec4fd73f86dedc7f1fa9d04d498f97333fdd809
MD5 661946aa2130f5991d1955dd47ae7c65
BLAKE2b-256 32e89be7603c65961b1dcbc7ca0845103e742980a81f6feb262b369d76758442

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.10-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 49c5594c918bb59f3b77f871f5cbb2ee9e83db0aa233a5af0b88628610e8e85b
MD5 5581a204c695378aeeb919465f352e2f
BLAKE2b-256 861dbc48dfda2a244763714beecdd6dce227023482288c667af7fa9c7d2c14fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.10-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 79621fd6c6b7841ee1f35931cdfb4a3158349fc3c63fdd128a8422fab0e65291
MD5 b71ba816024b2b7520a320a5e8ae7cc6
BLAKE2b-256 6fb9bad60fd1640f9ab090f81db886a56055ca538732bb1a3d83ab091747829b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.10-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f5aeb54604e8ba44f80aa218944396c7fddb1ab3b809391e1c9f7a590451dfdf
MD5 5e406654ac5d86c313b4adaba158e89d
BLAKE2b-256 3fe0e964d3b0d77e7cb9a55ecee806f570b329e4eb86f6788a2e06a293e2ff37

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.10-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.10-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 8b4c94154cf27488784fd9cc82e9198c81aab908b2c94588207e74e09762eb36
MD5 32e3ff274bc300a234002dfba69aca3c
BLAKE2b-256 b4dc029244d80a9bc8021dbbc79f5340b9e105e62a9c5a648da3179d3278d6c8

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