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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.1.15-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.15-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.15-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.15.tar.gz.

File metadata

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

File hashes

Hashes for genai_pyo3-0.1.15.tar.gz
Algorithm Hash digest
SHA256 39be65d833d98432e88fed72f34d14b14b5458fbb6620f83ee92da1d130182f8
MD5 dc220d48259d5e6a6bccff536406b1ae
BLAKE2b-256 d6b7a5ab69f8a3097d83891af9922907500414aadbd0a8d6a6230271136df6de

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.15-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 792a1ad203b1c27804db17b5d06d388724c0952350a6097a85f1f9dd265ac0e3
MD5 797ba119cbaf41359f7025cdc2c4fece
BLAKE2b-256 bf5f0594b8d5f30673b9fc1a5f37cc765da2d15c7b2f65f23910fe69d682f4da

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.15-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a235184c7e247886aaaab2601d33cb9b616eeacfc425bcca7823056e813637ad
MD5 cb765e10cbf0fa60cee5cd88812db92d
BLAKE2b-256 fb9affb2ee6c5be4cc5a46714b52518ef81efc8e276a631ada47ac8dc72c7a67

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.15-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 82b0592b7892847c5c765ffbe165de997818a9e5ac1b08184251b8b6b36c9953
MD5 e475c4f6a8b2ebae6ab0bb7a517a6fd5
BLAKE2b-256 d90857b3a32716f191e69cb8eb481568f81b3cf8682872028ca46d4c204794e2

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.15-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.15-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 141cca77faed6e70de4b7ce9a696d6f2bde70e20b7db9b5b8f0d401c54e5132e
MD5 68a1b6b2437daa8ef10dec9c03ce510f
BLAKE2b-256 765a804addc8b4b3066722734f748a4f5dbb1ebbee4b447c4373470d4ddc5909

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.15-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 8afc3acc661686ddc462f374ab5f8d9a681c94286646c473a6d69856780e160d
MD5 a42d9c1a02654ad4ce9e9bf02e61fa82
BLAKE2b-256 20a34f3f801074a3ceb744f7cff91fdeb73a20f648767f17e49cba1516a73094

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.15-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 30b370252f3bfe6df40550b5eda35b6a44d4e2d91be1d3463422adbf312b2988
MD5 24c74e0eeb2c141f357d4d9bd66867dd
BLAKE2b-256 157c413002dd68b2e475d40a26ef4816099d13f5b9ee8a1b944eaf20d924fb9e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.15-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a6d069a3670df9f9b71e4e7cb3e322ed65535decba99790cc5a5292b8cd8d4eb
MD5 d201bb560aedd859829496d5d4b0e5e0
BLAKE2b-256 24a62805f28ad430e23a32e8c11a441dfd3b71d355165ce5fb9fcdae9bb64715

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.15-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.15-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 caeb8c9b1982db21ff0c21eed9c0c8ff564c9157e4057ccc82a89cba934e6ccb
MD5 b1c61cac4ac447260fcb88f838c1f07b
BLAKE2b-256 bd8bd8ca4bcbff2adf917c00bc5f585152392ec19cb55cc08e13b7ea501372b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.15-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 a1629bfeb873eff54ca0beb28b73712e14c9444332a8176d598fa3b1d6829814
MD5 c663bbea9156cf7f094e171999f38362
BLAKE2b-256 04bf21646d6b7aeeb52e8b005a9236d806865970f67e55b939e797b8d5a2218f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.15-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 34f8b007dd04d43363330c3a23d19af8f813c06522ddffc7ba49d394fdfa7c1b
MD5 e48db4779285276c43950b735bff8ffb
BLAKE2b-256 cc983b5eb1498d4d80265cf9e2cead6f31cf9b11271e34f19c20683cd33e6e3f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.15-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 94e570166648d641e5231dfdd2368448e616449354bda7710ebedc23d3c0b136
MD5 a40723c650a43739ce20dde52957b276
BLAKE2b-256 32b37f72c69e481b8c8e28eb4b1275ff78f60b2055659969d5bdb2d1dd41613f

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.15-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.15-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 e4cde56f1eb77935df7792be34d5d65936e83ba492e3a8bbe0c201220ba5854a
MD5 7933f867e72bf44db3ac91f83d1108ff
BLAKE2b-256 fd6ceb8aa4826dbc7fb8e10f592b3df4521742fae559241ac8af0e542ebca9ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.15-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b5cd75bf6a5d8483414c017b18f2a27edb1152e7fba4b7c7362e6a8afa7419bb
MD5 4d867a5f70d628c1fc42746d17d91d6d
BLAKE2b-256 e2d5357587bcc0d9c985b4d649dd226e5f93ba1f115245d0c650bb46782b18a4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.15-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c7b202d2580b1a11b851dc0b2b3a40dd623d86753a85fd95022e06c6ef352df8
MD5 898618faef9124cc73fd7c5310dad9b8
BLAKE2b-256 53861f5ac3295be1d62b27ee7834545cf408d7243164371cfc6b1dabe3b04175

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.15-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 3dd494b7fa1daf88f057ce5cbeacb88d30806468045b3ca6075f051093a9e865
MD5 0b09a97f45509f91f1c2fd2dfc70b52c
BLAKE2b-256 5e3ee8505fa3449a45cf5aa81e63a29cc3b5fd7628e3bd07daa1d1e22383b4b1

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.15-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.15-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 81e88b54ce0ffe906090f690981528feba66e75530a9afc7266b6812d3c399c8
MD5 21c4f066675a054ec85be882608e19da
BLAKE2b-256 f81508dad87221aaf14c8523fd4779e79f98edbe364d006067bd1c9d735bfadf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.15-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 361a38d9a1e09d7e5c0ed2cc1206bfa8de631f54d3a7d60cf8e5cc240a0c384f
MD5 faf238e420eda02c5e29662347b883b1
BLAKE2b-256 255b0aaf3bdc57ea1d21d15582205b53740af0344d6018f04e24053832388af6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.15-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 05ea1886db293225d4d13a08b5cc8a530d8f0fe81518dd790ef7ce9396185c03
MD5 1ddda9c024fd4374b15cfffdf957a1e1
BLAKE2b-256 b2c87cbbea8dac2af3d841cd9f31af23bce62db561937a77da779ab5f35c7153

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.15-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a3738976b12ba420006452ad4a44105c4f383332ea253a1d629a85962abeac6e
MD5 a1e0faf3ac61b5356c37ac2726c27293
BLAKE2b-256 b0167a30e05537f51478f240f88020b8378f54b42912732244ddaeb81771ccaa

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.15-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.15-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 e23206c633c38f511358e79dc178d372160ee9365dd09e8f83b36dfd38a0e281
MD5 b1cfafbab69030f8ae6953dc50fd3a18
BLAKE2b-256 659d3542dc95e59b504bc8d5ceb9dc7f4b114bfc8629f4c8f0f8c504045b72fb

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