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.3.tar.gz (46.1 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.3-cp313-cp313-win_amd64.whl (4.0 MB view details)

Uploaded CPython 3.13Windows x86-64

genai_pyo3-0.5.3-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.3-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.3-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.3-cp312-cp312-win_amd64.whl (4.0 MB view details)

Uploaded CPython 3.12Windows x86-64

genai_pyo3-0.5.3-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.5.3-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.3-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.3-cp311-cp311-win_amd64.whl (4.0 MB view details)

Uploaded CPython 3.11Windows x86-64

genai_pyo3-0.5.3-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.5.3-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.3-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.3-cp310-cp310-win_amd64.whl (4.0 MB view details)

Uploaded CPython 3.10Windows x86-64

genai_pyo3-0.5.3-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.5.3-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.3-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.3-cp39-cp39-win_amd64.whl (4.0 MB view details)

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.5.3-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.5.3-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.3-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.3.tar.gz.

File metadata

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

File hashes

Hashes for genai_pyo3-0.5.3.tar.gz
Algorithm Hash digest
SHA256 e53474c5bb4de06cf8cabea2d968c7f451ce6314fdb0a67ed24079b0b6746ef3
MD5 ceabd3f1edc04622ef6af57263424630
BLAKE2b-256 a6446e66205af8d7099195087d0a8e6c15d183d1f2bd6f23a9aa7b93a29dbd88

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 29f5d38a5348dcf71cb0f3e5df84acd49d0f2e84f83c2de57e517d33491f2041
MD5 d0f9b85a96d1b6875026696e39ffded2
BLAKE2b-256 889c13510db4e4de392013a6cc11978bba1f50bc01c9e0f587ef12fae482f69f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bb37cb729893178ba7e97621530aa1a6790f367033e443c92b64c51823f94b1c
MD5 8b3eeec15f8355ae6ba069f529672008
BLAKE2b-256 70c5e00ed0d7d3fc191f9a6df34a58d04ed7c0e2e875510e9798b72121b00fc0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5ad3825dd8eda284229fc07adc1972c9523ce2b6b63eea19f32b45b31b310ec0
MD5 54cf96f68c27efe0589661c4beb8120f
BLAKE2b-256 1be44d4fdb51ddd16687d9b5990b6383469cea0014b26fcfc7df4d4995f7bcd1

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.5.3-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.3-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 37de32fb4051a04f00926ae5cc2ba572396857bcb8e2908b7c551fdf98c8085d
MD5 3ade323e1c25b19d8d890a09329ec57c
BLAKE2b-256 4026751a4ac14241ba01107a908e7d10131708b25281d88eba33a54d76843b15

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 73cabe850cf9789bf32fe4666724202ec8732c33438897da1456893af8bf5fe9
MD5 1bd703f4768f350ba0bc14099b4c9d1e
BLAKE2b-256 e7af159f27175956597e1aeffa9775a00618103bf5537503d6904eab6b13c847

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 15b13c3fb0ae147218e8dd572e238c9994037f17694c64f27a4bbb2993386c83
MD5 2ecadc2a46a0e5eb06fb58ebda34f6d8
BLAKE2b-256 b7f02b94958df8eceb5247c81767951d96ef27b7aeed2e53416bde266338d851

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f20edd13c7b6dc47c8fd964a44b45b70a56873170cd61d92b08bea1eaccf4d8f
MD5 b61a487e017c08bfe0456af05ca451e0
BLAKE2b-256 4a5270004758e6210679bc50bae7a84f52045aab4606db621cba64861295e895

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.5.3-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.3-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 738486defaa78d9c21420ccee5bde1947ea66b9e51971544944bb16e9509068c
MD5 e9163b97e35f093567bd682a270fc1ae
BLAKE2b-256 aec7c5c06a61ef919a34009d89d081503237f6421666489943fb44f16aaaefdb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 db2d4b1ee9098cfae2980ee83f6e6e68413ccb17010d2557cad588e2eb629efa
MD5 f27f2618e43ca37778d6e800c391aa84
BLAKE2b-256 713e437ab257f05bfe3a0cf34c42095312c8efaddee680f76c12a998db06860e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0609197cc215404c0568f2337005510360a9a90fdd1792cedd1735e002b92461
MD5 13ea9bedea4c93e5bc5247344460140e
BLAKE2b-256 6bbc77a7ad624d12b14e0fe0a6aba22d38b26aeda0c77dd9fb92a3205b5a96f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 96d0070c5af0b51f8b1371b86dc121692ae802847ec927814e13f08e0b1a7ce6
MD5 6ff4e707d932db4374794c69810ad41b
BLAKE2b-256 7aa4e7bd16a67fdbf77cacc9254636bb610b5a112c16ced8e1697a541150c733

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.5.3-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.3-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 527e6ac9acc908e861426700525bce2409f17e7eae66a552a255c15d986a7214
MD5 e5fa97cdf0a442d7ce762886d7a5e19a
BLAKE2b-256 cf494e5bc1a2f74811521b4807b9f8cfa9b5ae24c8a85f9086571f2856f9db22

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 deeafdb83e70cc6613df4ab291daacf89246167a204e7e60c9e005182c662dbf
MD5 d68bde29accfccad844b4f75a5f651bc
BLAKE2b-256 bdb37c36b3032a552e342b1a8b28ed70a9105a1501a24cab79c4a79c37d06938

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 74a8a16f8b5423b348c4837de7dae09c19ee1ae7b7a86650b4a4149d899809bb
MD5 c03c2a8acc057edadbebbbe30ed283d3
BLAKE2b-256 6be74abc363abec3bb9e5fe0e3afb281306a12ceb10c773c3391c063d0acc9cd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8220c2619ee009f863bef05febf7987e024258807589a15eecc0c18d45fd764e
MD5 a151f97716a27a00163d89ba5a23a76f
BLAKE2b-256 735546097f7511ea8aaa6f036e65c2a40c16ff44532be6e4b5c844ecc5c583eb

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.5.3-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.3-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 0f700e2678c80a368915864852b81ea181d8f9ba34f7322988f0eaa813941cd6
MD5 093a92b73ba675fb5cd5bf381767a306
BLAKE2b-256 01170e0a0ff34504acc44b7a004b461db6e71cd4d5f647397d0f21f9c12d2816

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 1b8d81d4fa7b2f60aff71ec02b178cf2858a8484c48eeb2a9c671a5f1b528f04
MD5 758ae22f86216ea5f656e60c990108a8
BLAKE2b-256 7dae151f2562f3e012781e841ad193e8586ff11265a173142ab2af332c37d138

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0b07b1b2d842ea623e5940791b7fd40a222210cd5d191b7a557e1fb740bcb5a3
MD5 b114c6c71ac448bbde7af9b672c450e8
BLAKE2b-256 762f042f7c9e46a8e703655125b7f3ed09f03e20daf8698989787c149d6a8cc4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d1f2083b61e84990f0fef305141eb3fbcbd64352bda40db57916cfe447d3fd88
MD5 d62bf53e55fa285fd442b200924f8b90
BLAKE2b-256 3581bece88ea19b830e9d6a9231e7e4576ba75a4b52278251e6771534c39d004

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.5.3-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.3-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 8bfe690091ef28c6e6f8674cdc40f9b83202ec6815cadaede26903314631cd0f
MD5 8fcbc81c03883b5f415eb3254860758c
BLAKE2b-256 8a0a4f6cb18f838daec238b983f52b77759d1b864795b35d938b76efb18b4e17

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