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

Uploaded CPython 3.13Windows x86-64

genai_pyo3-0.5.4-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.5.4-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.5.4-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.2 MB view details)

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

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

Uploaded CPython 3.12Windows x86-64

genai_pyo3-0.5.4-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.5.4-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.5.4-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.2 MB view details)

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

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

Uploaded CPython 3.11Windows x86-64

genai_pyo3-0.5.4-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.5.4-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.5.4-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.2 MB view details)

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

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

Uploaded CPython 3.10Windows x86-64

genai_pyo3-0.5.4-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.5.4-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.5.4-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.2 MB view details)

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

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

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.5.4-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.5.4-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.5.4-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.2 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.5.4.tar.gz.

File metadata

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

File hashes

Hashes for genai_pyo3-0.5.4.tar.gz
Algorithm Hash digest
SHA256 191038b3949a2d2f7d040de9b57fe2a63188cabffbd970da3a419cec5dfc666c
MD5 fffed22c73d95e8e75e21a382b0e2bbd
BLAKE2b-256 4a9c08efb6e42fd2585bf0181fadc268f32ade06df83430360ac619381eb2e14

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 fac8820cbe4c15e0ef911d69310055f32db4bf063d12a9f920dd7ac6d8f56423
MD5 5d1462efe072e125c44f67edefa06b58
BLAKE2b-256 b93d961af2dd74cc03f31daceaf0806e9f899cf16b572fa56af74118bf588910

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9b3b6e94cd2706cc6d2b4db2dff971186a41998ff8296bb206c0b7a06724fc87
MD5 2462fea85543039ea14cded7f344e444
BLAKE2b-256 4172eb8185753fd1f013fca34b3af4089e5eb12bb69e2f7c54096b5ad3313fd9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 524987772b11926a57487b2069098d048a3e32cc9a31edc66df1d51857418677
MD5 5aab77a8a760266e222a164f9463a947
BLAKE2b-256 07f2100546662dabc6125272ea82fb291eb06ad51dea666899744bbcc70db1d2

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.5.4-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.5.4-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 06379448365151c659e52bddaa5fcfbf92fd9b291f1413a3540b72a3cc0ea163
MD5 6af37ad31f9dae71b39306c15e15ee56
BLAKE2b-256 c591e78a0c89f7f9f9bf083b56ba2f8acdf0ea24f43aa1c921ca7477c6fb01c1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 a5fdcf1984a0161ff71077f78d6d392b0b5d9aa168228bb54727f08084a86787
MD5 c9454931459c871e3c3c79c65dc9ff19
BLAKE2b-256 db6d36b588b7e68200552a2f177d5f976ca73b9c351e129d61886fb52ea369db

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f6a04634be874c7fbcd88cd318d10107fa3c458b7b5869182ff3f5f522aad153
MD5 a9760c786e78c27363b6e0c15f0fecce
BLAKE2b-256 a8346dab8b6dcb84920c47e2a095494452421bc8ce4a9f10a73bd4486dac8ea4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 010b4f6605efb9d41aa4037b9067ef8ccb5614913b4c4af8d2764d3e8367e14d
MD5 8a3bb5e7f05e81788f68c9deb04975d5
BLAKE2b-256 44221b10fc45fd9c805403f3f4ebd4e564b85d8ab6dc1cdacf2218c82e0b5b2a

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.5.4-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.5.4-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 d2f8aa0e0c3d3e6c332ecb7b497eee9d7ff31067db315fe08afbc111d37ad36e
MD5 1423705f4a43165c36a377e7fa0e134d
BLAKE2b-256 3c2c2a1d99ee8d4cc8944903c0c0f26cabe41ed7e9b0843e3aa630ad3d906e4a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 6ba75c343d5ddc24b5986a6fbd216f733764110e6b4aeade514a9a6f03376bbb
MD5 0935cc292fb594491abc51114ed9513f
BLAKE2b-256 aefa005ff632d6d48b9f91b8fdc6c16e189045c7e10a9839d1b566d7339ab3c7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 53f1cd8bb8d63c010e657f5a26c983785423910d0db7a23b2ae23a50633e5038
MD5 255b68e248e99f43bc822c56ba5dac0f
BLAKE2b-256 65fae3701a74a9197e89921c20e83867c2931e47bc007c5d2a404e99c586d047

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f09063c159ea530c29859b4734056f0e7a5d30b46984ef374046afef703435a8
MD5 e4a434711053344c7a459122bdc51fc3
BLAKE2b-256 8b94d1d01aa87da0d9f2fde5dcbf9da39aaf9797330ce7bee98d1aba38390e87

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.5.4-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.5.4-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 b7bf48c4a34f4444fc4059b467e15cf52b9462cdc56c4e7f291af221dd856cb0
MD5 835fd5fda13b414f6d1626d88f4d74b5
BLAKE2b-256 03109cd169ffd1c74155ccd635b141a3b54d9d9e101f2fd932b3d6016bb06032

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 b123422d1499689d74cf421e85dacc1db62f968355e2009d6b1574cd784240a2
MD5 6c778e5d2eafed56c3ef43a2e5989622
BLAKE2b-256 edee15cd13ccc5f4c1cd7e098d09fd265f2161cfe0ae1cb6a85f09ae27c2a293

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 79d9d8f53215de6edaca40e81494300f22fa8357095f213751619906df606349
MD5 98efbdb5db76626996fc29a925c6ecb4
BLAKE2b-256 70b2dc78499eef9494907eef8d87cc18fef10b0242049b901171b655225c6b8a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bbcaca7e28d3fed1aeba1aaa2b86ca02a355d81b52157c5f35400ddf87313a3a
MD5 638a10e9863ff58e41d123f6b602533b
BLAKE2b-256 c58af291ac04ac9544586021e96ccd456025a27ba89fdb593e71de5a46e983e5

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.5.4-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.5.4-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 0b0e5059fab4175b65f4cb2001a5bd3bda18cf422d79928baa1eaa3a7fe68f70
MD5 d6aa3691ce1085e02342ed0c0b8d7155
BLAKE2b-256 bf09ae6883cb634d1a24752ddc6c483fb8b50b04259e88753111d572cd6f3e1a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 970e7502fb69734aafd7dbabceac1afe1e2910988b7cd535f1210b571b1f79a4
MD5 d43850f0d94c3f4d642c966cf69a7285
BLAKE2b-256 1b53a72a07e867fe673785aa4b3e34ea6564b7b259d819b0d1a75e431a929665

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 afd484aa67713cfb49fc4e23f2daf006ee567e1bb67c5383fc0ee4a590f2d0e1
MD5 220aa310e0afeb4b3a20e147b789991c
BLAKE2b-256 244e714b5508ced95d0db2b8ffce5849bbd5feb256a54c8a619fc5cfd2eb7d19

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e6702f30f37ced0a0c12a609425b9df730a059eb91a0594278075085ebeb223b
MD5 d1cdf09270d1b775a9fc0ebf7a793953
BLAKE2b-256 ddad73c6ace2c2fdcf6d4ca0ade72c2bfef7d8aeb294c1073d1004c129d11841

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.5.4-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.5.4-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 a2627ab56c98b7ab1ad8c10d5d95a1c048f162d5cd95b56fcf8b47c84fa18c10
MD5 e54dc2cd0c62d4b6b665ea78cd397ad5
BLAKE2b-256 e4670604b19546ada57140226f74ec6f1b3fd9b0ef2d5a80ed6829b25bb228a5

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