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

Uploaded CPython 3.13Windows x86-64

genai_pyo3-0.1.7-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.7-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.7-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.6 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.7-cp312-cp312-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.12Windows x86-64

genai_pyo3-0.1.7-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.7-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.7-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.6 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.7-cp311-cp311-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.11Windows x86-64

genai_pyo3-0.1.7-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.7-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.7-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.6 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.7-cp310-cp310-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.10Windows x86-64

genai_pyo3-0.1.7-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.7-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.7-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.6 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.7-cp39-cp39-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.1.7-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.7-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.7-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.6 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.7.tar.gz.

File metadata

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

File hashes

Hashes for genai_pyo3-0.1.7.tar.gz
Algorithm Hash digest
SHA256 ce4e96e0d5672a6243b18da26ce9b4e5eab7cd639e801877d16cf74265a697cd
MD5 49a7c842b829c625ff3897039ad43946
BLAKE2b-256 81b3877e2a190a1ee605847e74b35ef8bf125a64bad072151b6270ac60c21c4f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.7-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 15db0c88539b988ae1460435abf21022d61dfed9911d6471f7d1d6cf428e475c
MD5 60cd178a94c3226b6e9e8d0322093ca5
BLAKE2b-256 91882711e2fff063ee2a127cf8a9104cd74c4940536c6b498f550849f9c1f219

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.7-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 58d72b890fa2d10422d169381aa2934b76f46fb9a5c5fdc8e68e33a459c96bbf
MD5 9de250583d8db2604348faad41558019
BLAKE2b-256 a4f7c49fa2da01d53651e47c36fcca49903e8db0ea1148c9458f7626e548972f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.7-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c0653ecd0d6c53c065a22d943c5a4758f246f2fd08abd346bd601ef219bb898a
MD5 a3f296048b52054b48e49b7aa15c0022
BLAKE2b-256 f58b146ceecc466a5e79abb931575bd7ccb62eb79a8264a1277f7cf059484255

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.7-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.7-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 64cac7f1c1ea14e83ab12350a60f2c114e97a972b7b93aafbcab9b6ba4cb4abc
MD5 6cec93b5a5db2bc0068f7f6e6336c33a
BLAKE2b-256 58ae945de344983743f5ff1fbcaf761affcdab92742ebe9ef804c9d895f11b96

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.7-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 eee35ac89bf6b0384385a59a4b3e607c2780fb37ef07cbe81639d6f31064657d
MD5 c2af4dc5fbd09fc12c48dca689b2e5ce
BLAKE2b-256 add3bc735782345409e90094c762350e0841be5f6a852c11255ca97d11973295

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.7-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2a8a19a24f7dc29837ff9f784de7fa3204a6f3f0afcc3f50d61c74bd37a1f9cf
MD5 2fbf6dfbcabb1b9344296299de1ebd20
BLAKE2b-256 03aa5f28d93a0fddb3bed63cbcd0c2eb97bd8d6466f8e0695191448e63c12892

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.7-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9bf6ae5da22815f0092b0cbac2e41a7bb84ba2090ef6f90d89065a8a5b8eb1f1
MD5 11e14e4d1aef01ba42822cc4f5c6053f
BLAKE2b-256 b0e10d257a08c8027fa29c828445506d3616ae70db0458c8de779b388848232e

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.7-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.7-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 54e9c6af405f6460ef5ecd24ff42b508b692e1c71456041693defef639d7df28
MD5 b7318becf92e74cbdcb06d2a588dd21b
BLAKE2b-256 2d7e8f2ba71c94f8b76a38d63a143560f1a93be5b82f49af82d3615ef2c0dc29

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.7-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 55da862b99600b23945d28a30c6e3ceb735dc8bc22b86d288ba881a052b42845
MD5 9f1de0d1f8a5841e4e880607bd16c9eb
BLAKE2b-256 b48da6321e56fec211b1516260edba89b36e6e4243c5593240a41b7b407e3f32

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.7-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f164ff247b8228924b7a1059932847d0dfa9cbfe74e90cbd2c24ac9221ab332c
MD5 03cb9334df495a31cb41bdc9caae6da4
BLAKE2b-256 29c6508dca4514271af53c27c8349b74f35082284125ee0d46cfed05cf94ea09

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.7-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e63d76ee310ee0357a92c02a4166dd6d14c0309977eb9a6bf020f1933c254d3f
MD5 20a2a6739ea8cbeb10bb091c0276506e
BLAKE2b-256 73bba2d46cec2926f5d92e9bd07242fc0f16df1131ca1fb2d131b8d7b17bca30

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.7-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.7-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 bc7de1bc8491bd3816f2e180c92925e44f3b7001f89cc45e4da6188b2d780b05
MD5 9e23a529617e6f90db887845835a15ce
BLAKE2b-256 ad4fc1e83f377ab21ef4885abbfe23fe5f1947d36564642f528b956f01ef8234

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.7-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 a8e0c0b138dd33986496f1c7e689c8d5f44a6b5bf4cd37e883600ff81eccfb89
MD5 203fecd5f1161ece343fdaba67bc9d49
BLAKE2b-256 de709983dd854bb626b5802cda4c5988e32220f853061d562849cdf20a36af4b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.7-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f0b45dee98640ef6b05e824d6f9c151c032a89f8996032a90d98e30abaa8af2d
MD5 3fd8cdf3e750c1f3af8e57492fddf65d
BLAKE2b-256 ef57a993ee4f867d7a9dc2ec6924057462df57bf1b889ef267b2f01d0cf150d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.7-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a8bcc834111b0cc107808427bc8495cdfd756a78cc0855f09b6810aee99ccb55
MD5 7b5d519f2c3e345c93129a23f040ee88
BLAKE2b-256 3cb04a9ec441656480a6fcd93c25b57e899d7b0b3c198b4d1e2723338b675e60

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.7-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.7-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 8c4cb6abf007b1a2716a053a98a0ec8c386e458b5b77dd232a859d9848adda23
MD5 8a32dc1bc6888bdec0a3a564c27ff6f2
BLAKE2b-256 5a99ce59d0ec176737238d47cd2376af822032d848ac95c598296ca13322c126

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.7-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 838c65b3db56dcbb118e20b4a2ee43b36b8f2eb3e46c257d62cf5d2e7a1a2640
MD5 f3a1f5f4dda9fc0bc016b94699eec04f
BLAKE2b-256 1c66dd97d2d2c27d2d009c8e17411d1551afe3f005158509f121ca01c11dd6fb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.7-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e60479f12bbce430ca0722441737950ce464afcd253ef87fcd2ef5e721f2f9b0
MD5 627fbb077e42d70baa123e627c0875d7
BLAKE2b-256 85fe2036531cc4d2868dfa108ead26634df826f75e560c5efcafddd42c646c04

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.7-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 60793f4f439106ab73247bdef03d0f998dde10156aa22323f299aa42876339cb
MD5 b661e633174efd1d7ef265438d6ad709
BLAKE2b-256 ef69b822b2c6db7dba821a1d0fd03ef50468745660d7a96e1b721ac1fdf2f3b6

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.7-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.7-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 c10277726c4a0077de317abd45de4806cb127f6948dbad6d36206f5be0888c4d
MD5 59abbca2b0e28d66ec31129965be9ccd
BLAKE2b-256 19317901b92b7a9d22c4d2ebe795c63eeabcfa97fa4ce23af785f6bdd17b5541

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