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.4.tar.gz (36.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.4-cp313-cp313-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.13Windows x86-64

genai_pyo3-0.1.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.4-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.4-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.4-cp312-cp312-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.12Windows x86-64

genai_pyo3-0.1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.4-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.4-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.4-cp311-cp311-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.11Windows x86-64

genai_pyo3-0.1.4-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.4-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.4-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.4-cp310-cp310-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.10Windows x86-64

genai_pyo3-0.1.4-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.4-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.4-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.4-cp39-cp39-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.1.4-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.4-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.4-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.4.tar.gz.

File metadata

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

File hashes

Hashes for genai_pyo3-0.1.4.tar.gz
Algorithm Hash digest
SHA256 22a7295ea20ccfe83d26b545689ee6345b2e0b495e7b6e6b038fe194bc92389c
MD5 186c236d783928831d0444a660d30fe4
BLAKE2b-256 68da4e5836b69958d396ff2f0e9d08f8fc77e5ed0cbb7723756bda235efb3c6d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.4-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 74d38d9caaa9fe9027a4053b6e8103bc620e2715c40f1dcfbab01b1179b6b750
MD5 cad0d5d8b0df603b9e9098412afd8c61
BLAKE2b-256 eead58331397f47ac3cfd00ca831ba4ccaec31a466a73e5b09495f526c485ecb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.4-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 903ec7b941b5a7eb66a6970fd6bd0746887f6a1a2d643b87cc8722c2dd51f6c5
MD5 cc63f9fc1e7fcf308a08d43297963772
BLAKE2b-256 363fa0e272c7d49e37a90d6d8bfe2aa495b609145313b7b1e2192994c9fac07d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 6549f9416d935ee6bad41aa875990f9c61b36d22daad175d2a5536d8688d1ba8
MD5 4d9bd318bbaf3777c7ef68ece67f38fd
BLAKE2b-256 a7f002bcf214214f7f47f93a9ae855634c6c71dee973d45ef1f2f09eeecd8381

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.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.1.4-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 053753624acb3bc4b7a30813d99dbbf5210bbea0cb1925c9118fc4e62678b9e9
MD5 74d2175cf1055d41b5e1411e39d585bd
BLAKE2b-256 43e5f5db0d56352c3c2c52c3adda163292e712717e71a0dc5251af3f1f26710d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.4-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 ff92162ce4c595412a5f90e3b5a762954fd5fb1510fb8521fb297177ce4ced78
MD5 f72be01cd33af23258ef3f6783f6a498
BLAKE2b-256 c4496215373c6df2d3d09c4d07b9640a173f7d27cdd2455e0a2622675c6138bd

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.4-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3ea142c70ab3853e2045920ed588caf7b2bfe041e44c8d5638b56a83a467be8d
MD5 93cb3faa2c693ef3b433057e8f7cc225
BLAKE2b-256 5f042f2de29f1776bc5eb75a1b2ac4552f23e9baa8831896a8cc5b26f2ddcd8f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2884995c9aa60958407e8e48393d75b285366b947ef184e1cb4189da1a02e2ce
MD5 cd33696b1a0d71fa41711911cd2aae99
BLAKE2b-256 5c1f65aeca6746bafb6d728dc02034d084263498c26457b15c5f5aa92b6b22f2

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.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.1.4-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 58f34be110d039be71c9a071efc12aa820900e5e7c86511df476388364fa35b7
MD5 c8b971f9373ee587c7d7c1fac5e519ea
BLAKE2b-256 46e72f731c5cae2cd57d7b599c9730d62aacf84783363ca74d65fe437c19ed93

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.4-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 f1f070cc205d3ccd440264279c0686f06785584979efa30281d7d19ed9f73325
MD5 96bf93f489e950d6145a19a2d333c884
BLAKE2b-256 32fe5bbee86c78362fde78e8e61ce177d55acd9299c79c35b138d7da49fccde7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.4-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 aaf194c901edfcf97ca62e327130a52b99c368cec3d91b7586d766e7fc6e34f0
MD5 403659ae2325b42a716ca3d2665833f2
BLAKE2b-256 798c501af3364e8c2ce1e8b7c4e6c65b2227b1742fd827e0da191c2987558e1a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.4-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 42de2256a214e7ffcc420b56fd92e17607a19e709e8f2e61f0664a376b22db53
MD5 120a074c7709b15e520543e3b0a8a788
BLAKE2b-256 1e3f6a1f70fd7db0965c3750d7a36ad881b9ad0548ca449291851728473bef1e

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.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.1.4-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 8deed093f7a47439253443079405f9f5408f379e2cce540d612403eb42215890
MD5 156f7d465dd4ecfa7adb34691e9c6ac9
BLAKE2b-256 083da9fbf38e7a0209d32f15df99ab3432533019ec6c928c21b27345bad09529

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.4-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 65c88a1d975d8a3d9103a05a4a1df09797b0cab4115a58c2b53f13f7261a0221
MD5 ba87581ca4c27206ce494bd24ecd8531
BLAKE2b-256 86ea380ce7168860ec6ea4d9d28a9ec0d4e0a8a7599205ead98f387d19a79fb0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.4-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 93785dcbb863351709cba79e20580261282ab7751308fce55cca9c149e718cf1
MD5 9efbccfbac569923c9579c15b753e82f
BLAKE2b-256 f67697b28f3715c62008aa7def9bb260d11107bd6b5c850819a2c3590a8a76de

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.4-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 5b8837a794c7caa10cfbfed0dcf42f193c4439e5351b7f19d46b3f4afefcebb3
MD5 0048a7ad858eca260f36c0599a042709
BLAKE2b-256 029698aee6a3218eb65472aab09da8b374755acf1dcb04fea80684df28ecc18d

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.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.1.4-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 347faefb80faa7700cdb5266e60e5eca1c41554410164065fb9571b914d0ef43
MD5 6d3cfb4966618c0f8b6994de6f2548f7
BLAKE2b-256 fe6c640182bc3b5c1131de7417a31e07c95b16a389468a757726eb3ae30a466b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.4-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 93dd8c4d5be8c6e52265a8d85d3e572da6a4915ef5781012f55b05c9d04f79f1
MD5 6e6850ff221a679983155d897b360a5e
BLAKE2b-256 18db8a89105ea624dd0e3d508f60d2b491e8baffe9c66765f545a5687efc7139

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.4-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e8f2e76bfc459981e479c5555ab0dd94dcbd0146c721e657fe8ab829d94a2ad3
MD5 26506f8be217b226d0e814cb5e5b9bf6
BLAKE2b-256 553059857b59aaa2ff1db78b3c7acb31827f3da8e071194407bde23260fcecf7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.4-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8ca0db5a28e3c525fc8776b3bb6b6e5a012794c9aac28ce1f985459de649ec57
MD5 b044c131aa39a5d5110e01297a4f109e
BLAKE2b-256 0515eabf16c6edd40388a0a524e75a951f75e3bec97a6317b487c5aa5a3f9639

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.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.1.4-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 d5ad9f71eb863791f8dd393e16f589162a8976513150cf08b8f3b6927557abf1
MD5 95eba7b8fe87363a3a41c34ccc7869fb
BLAKE2b-256 a587b5b12b1e9c35e3af9e3bb5bb5ea7175fe8919b8f69baca8a3407e2ccd65f

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