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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.1.16-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.16-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.16-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.16.tar.gz.

File metadata

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

File hashes

Hashes for genai_pyo3-0.1.16.tar.gz
Algorithm Hash digest
SHA256 1da0d4eb175bd6877bc7a5f36a79817887ce0b3b8f881d381305898bf5557388
MD5 bb93584764194f93dd3ba904f3af7e2c
BLAKE2b-256 2388f1b7026d7a14a8d7f306e30dab1d29edf2ddbb6e48665531d28f9675a5ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.16-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 d885051792250253808b2dec3b1e0efda035d4021f8adcf04d52de9467f3cba7
MD5 d85b87577594e88eb1464d5069f9a782
BLAKE2b-256 fd5b961066e768b833ab7e961f479d58581bfe6f761d5a8fe1c94e136f98b565

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.16-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 318c6f7dbfce12a8109501a1b41842399fe65673bd5019ca18056f2c6d74f0c7
MD5 1ee4f0c9300a1f6732e76dce088b23d5
BLAKE2b-256 8ead66b32d78f12c8fa3e2fc2f1518248ccfc0b7bac78bf3b825633e2dcdddb4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.16-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 fd199322989c23fd681803830b3b154a5e0ccbea12c89f023ccc3466ac8920c1
MD5 4ab0af59af1b3c735e2189248eb3a0f6
BLAKE2b-256 fe2260a9ce359c46b7b1f1d1247bb76fb2ec13111e810142aff202ae1adb2397

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.16-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.16-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 c70bee672d42bf60cecee422304c2ca51d0f601fb7e1b09472dec6f22894675c
MD5 2f52af0d0ed902e58810d40124dc94f1
BLAKE2b-256 83443a0873033fe8c76199bcbd50d1d2534d8a72e488497cf7a85d3b4bcb1fd9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.16-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 801c38dcb6980d559edaa4e4707563b5e0ce6fd2c68112908aa6dd3a4a972ac9
MD5 b2759cc5e01381460af4dde002ebed62
BLAKE2b-256 2cb1421ae886dfbcb657112d9cf8d9cf02dd8a873fecf7f6bc67e5693883cb85

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.16-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ca6f7ad1e7a2c62be0d7ecf66e5b14508cb4012dc960540718f21376a1975cd6
MD5 b2ed0316ed5974dd11faf1abf527aea0
BLAKE2b-256 4c3f5dfb607a932f9d23f746ead8632b92b934e790b6bd84b9de4bdfd0a14cb2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.16-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 95f83a428114254c3d76fd55c8db4190da7a4b47b19b38b0a093726c8bda1c7c
MD5 c81a8df87060919666687b6f8f78d069
BLAKE2b-256 8c5a9b5423edef17cb3c7755b69d4e12093f88ea6c07c1480c35f9166e9d1d1c

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.16-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.16-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 10b3786db54f9dc121323713209f7e80a8369d413a7bed8220a2ee4c64640996
MD5 773a86b97734c03ac378644137ce1415
BLAKE2b-256 548242dbd182dc69e8700eb42c838cf473f270a4edc7c994a7457e52d680d4d0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.16-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c767bc67243b1cd6ecfcf6434657dd05364b5609068f796744dc1a5ce9114d78
MD5 af70c69d96ddc92b84366e8865c7c9f6
BLAKE2b-256 2a0b07f3868225404f66a49665b366ad85ccb4f875c188debdd9dafef90a20a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.16-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b3ed0d8e294d12e6d67d9ef09b54f3ec8e3f8e4f266eada47032bc7648bce7c3
MD5 a5a24c39048eae4a96a2762d0d6b3740
BLAKE2b-256 4e9ac7e0696f381abe6e873ab71aace861436473460586e9d361d96dc953c489

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.16-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b13a50bc0380bcc518039b424fa4e3b9d7db0ee7fe5b4261489ca754ceb0a77e
MD5 8f1255154e9a99d31f10cbcd7b6040c6
BLAKE2b-256 b8cd87688580048fe151a86b1b699c57d67bc98869c61ce3256aaf909d2bc879

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.16-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.16-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 dd9c436c9622a0b2103c4f7d32d5b363fbe0bff0a2d0d27c25dcc24186982706
MD5 08da037e77924c2f2f6d7630d5647d30
BLAKE2b-256 037ba6ef4aba4df74407d64f1358980fe21893fe0ab9e50e939552ae0a4ea344

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.16-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 f442d7b5c4dc84e423219c0e122543ab532124396491c5495f587dd72877ad72
MD5 27220762017a5069226698b9a879224e
BLAKE2b-256 03b54b7c59901a435c339ff72466a78a4ea6f5d51e715be12471e4d49b684be4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.16-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 79130b51381bcb3d5c0f7d7090ff6144b294accee1ab6c43a68d3c7609670ac8
MD5 653ebdd4b301257baf13891e268ed84f
BLAKE2b-256 dc1f60364fcad2e76c0af3874a5aa97d8f1f647df5626478df8ecbb921bc4ae3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.16-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6e88e2e316d25a107eceab391b150a9649cdcb21f1c9262e71150d288a5fc960
MD5 1908c7ba0014ddc2a04907d3a13745e4
BLAKE2b-256 5871d412ff29b99fe37c4300f7b0ebb033d499b3637e530b34aba59713ebe089

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.16-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.16-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 59bc47ba3a76341fe7c292c5b843444c622a9c3f004069f741f1579ed351573d
MD5 20f1620b67c33caad9d04ee9d86e0f1a
BLAKE2b-256 68568abba47cb9c3d15a2e4e2f2fb1d0a073137a8d0f9b349dc2db751746958e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.16-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 17c80e92cae5f973af6fce112a7f3f82f0591dd916a46d3b9da0132ea0c7ca58
MD5 3454bbeb0f01fab0bc15f55041fa3773
BLAKE2b-256 d0d545cb2480e4620b23339d81f5c987849985338bfe2023a8b1fe4b24f0da0e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.16-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ec5200218c299d22c36015084d492f9001583a475323a62da4cb989ac054bac9
MD5 a8fc5d55cc2f00a64d747b180e7952cf
BLAKE2b-256 07f17cf24ba94c970de2e5ae8f165fcd7b6a389fc5c203bc1770843ee61e58a0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.16-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b697f72793fd21c29fdee110ae8607faaed8e4e2de2f398c022735b568d55355
MD5 79cf27df4660983e3206b25f1ec0bf71
BLAKE2b-256 9b353b104f193d4145870025d7387e4c5393784688f822497eabfc85c2345b63

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.16-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.16-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 069198496e52784710a4c7e3dd4186b06f6ee8926d2aba2f156f1bd491957650
MD5 51fbb0e13c174845541939d149c89399
BLAKE2b-256 2772e4d971abe01efccec0dafc43012fbc5e6c9c194d57cbe3e8f867e708dadf

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