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

Uploaded CPython 3.13Windows x86-64

genai_pyo3-0.5.2-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.2-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.5.2-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.2-cp312-cp312-win_amd64.whl (4.0 MB view details)

Uploaded CPython 3.12Windows x86-64

genai_pyo3-0.5.2-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.2-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.5.2-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.2-cp311-cp311-win_amd64.whl (4.0 MB view details)

Uploaded CPython 3.11Windows x86-64

genai_pyo3-0.5.2-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.2-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.2-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.2-cp310-cp310-win_amd64.whl (4.0 MB view details)

Uploaded CPython 3.10Windows x86-64

genai_pyo3-0.5.2-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.2-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.5.2-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.2-cp39-cp39-win_amd64.whl (4.0 MB view details)

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.5.2-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.2-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.2-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.2.tar.gz.

File metadata

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

File hashes

Hashes for genai_pyo3-0.5.2.tar.gz
Algorithm Hash digest
SHA256 adb1f9d76bfc6417f1504411dfb49525a9d5a22161cf9061fb0f4ceab6d1f8fa
MD5 7a3a5ee0e8a791a632078cee992e2276
BLAKE2b-256 51d2402490b94854bdd7d3e31453159467c10126a540088dc0239d9694830e67

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.2-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c06e492176ab016e689913efe6fd6427991417dfe69fb65eb1ae1d67a9db9a1f
MD5 289922add3fccb17b1b327bca2705a04
BLAKE2b-256 ce8dd3835311bf23d8c0c08977eb1fba2f9338a1266ce29bf5f948148554a778

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 71ab1a714a8dca9cac4168b93a85645ca29e771ca65449b47b6a2c69c434082b
MD5 3913480cf35e0a89671e1f4292d75767
BLAKE2b-256 2c91a229e4374e96f05553ea8d45c441ea7aec4e4f6f92662708ddda862fa062

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.2-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 31aecd893bd63ec58d062a25e696006a6fc767bc60d510ff6c6c5b3835cbdb19
MD5 afcaef57844753e1e2b63ebf64c05a00
BLAKE2b-256 4714e6df435f7ff8b618216350e0c862b29efccb04994de827bffab07e036f87

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.5.2-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.2-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 eb1abdfe1a6f36feab772c1b02187f53fb3735baffc40582256011ca2d0a8972
MD5 69c8b4d0c9a2ccf005c2f3c74bea35d4
BLAKE2b-256 2ef2c15d824a02e5d5b272787123aff57f0321ee7dde9e5e1079326d16e3de70

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.2-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 534666d2bc6fb29b3a268df5b3b836bab843a53f48017ab7d33fbdea2ee282c9
MD5 0cbc44138c36625383f1aeac8bec8970
BLAKE2b-256 6d518e475ec158563bf22d7d1234e9543dbc2beb98a7d3274e40499ca43f0f44

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.2-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d86ce8acdd6bca28883d45c4fae75eea2ddc5f6a503278976cba33ce6bba967f
MD5 0a7ff97b1a28f25119c4e27ec1a3da35
BLAKE2b-256 49bc4843f9f438041994dbd16992c172216f92bc3651378b49ffee3152d126ac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.2-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a2d37723c9c1497ce75fafcb4a0acf32d3e2998c0e65e0a3085f67c501584d31
MD5 dd11e8c27881829abaf97d3ba14c1e25
BLAKE2b-256 c892600dde480fbe44664d887a66f31f83f833fee7dc11259313c407f99659cf

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.5.2-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.2-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 f4edb71eac6ad7d803e230ea7ea344c56fdb6166c7927336f6d4a61c4941f02c
MD5 2e26ca8ccad6d6c9b42f9e6d5c8b34ae
BLAKE2b-256 0788ea0a642f9752686e8ac659a1af760fb3789f427c22fbe2bc3d4c337ba502

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.2-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 b71b2315fbea817c08ed4988ce3713261c07b1172ae7928da30ca81937496118
MD5 ecc6842fbe91eb248a795bf00e31d88b
BLAKE2b-256 f2d98f2a025cea6297d80538c614780953b5018a980e4e8e05cb2735e305aeff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.2-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 25bab6a5074f3d350151a1ddce63bbc8564b9a581a29ffa261f7bff7c57b5272
MD5 44a5fb65f103544a6868f88ba2eec04c
BLAKE2b-256 e8d3e78434757541e90e7f581e9c124ae24ad945f1b248c84e1fa20d711aa12c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.2-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9acb15e52af51cc33864ebb1f0053606f3ac546c90484486088f569c17e1b9ce
MD5 e6279ab3b97c9e645165c915c242684d
BLAKE2b-256 fa248be609e22e66e3c8d7ed69cb4eed14ee49106c7fe1729658c9444de0ade2

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.5.2-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.2-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 e13f15d85492c8d9a5ef84e25de4a3d4d99c42db7f10c5333470eb543f6d9f2d
MD5 f441d348b60cb8a5204d873e7dbb258d
BLAKE2b-256 241a58ad2dd2b1cae2693a9ea8e25593cf3ccd1b4aa030453317299276e1c432

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 0bdfcf448971023329224c2065d59d6e4993ce6e5dccfb1eb61b37391bfe4863
MD5 af08c6554c7032196aba2b44189f7415
BLAKE2b-256 6098ddda773557396593d0ca6ef8b7a09eb351946dd5c9b809e163de1372c2fa

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 c005aa23fbd4b4bc6c1c6674b7cd408691bc3d2e42eb54668b65b30a8f45b0ff
MD5 47199d46335baa2309c82e0149ff1845
BLAKE2b-256 f172a807ef8d2c0c8d5bf9fa78f3708b97c9d2fbd9545d35604ec218bc3a5a60

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.2-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7eb67de0bb9c12a7f70561ef8b13b5348cae87a885074cc49cbec7cf07a2f8aa
MD5 998fed7374a62eb62b82fc631c9e4863
BLAKE2b-256 21ec5c97eab98809d13a01206dbd5aef6472b404c508bf6f9e20dfab3df12a2f

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.5.2-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.2-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 03d67c46b87b05c30ec69d5da010d5152f5b72a33aaaf574df945f514ffba0d8
MD5 bff47db5bdb88467de8743dbd8b8167a
BLAKE2b-256 27c7aa6a55408570c8ac1c927ff7700adc8ad8a7edc7949a8753e3ed4a9641fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f33618880a20d15d63392ef8837134de9129cc1d2a85368435db24fedb34be5f
MD5 e743d2ff494b41c3aff5aad91beaa226
BLAKE2b-256 8c7be7569f0d511756d7dfa1a14d9b29dd76a0ace19fb7afb78e8a58cdf3afd5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eaf64cb85268d7d34851a47f0cb00e7036228a664b925f1bbec8d407d505b0c2
MD5 9381c8266cd6f4c3da189f893ed76ac6
BLAKE2b-256 21a74bf434a8180f64a77578488845d6a7695ca2dcc157f8d6117133b338451c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.2-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 02d731a4bee443dc184fea153f98c032112c176180132c3f9b91136642ebd92a
MD5 e3dfe3bbe66d774cdd8914a6518258e4
BLAKE2b-256 f3155fceb593781a377d4f6b430fff2445836ab9437dc84c18352f1450ce1bd8

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.5.2-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.2-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 f9b62fca35cc7d6bffc628d3b62e9255510a8c2f7917eabb9284b9e4623e12fd
MD5 3ec23a933bb244d1c35637c4f4a4a3f6
BLAKE2b-256 0df298141e2d1abea6a7ad8b9c1d0caa3298a857cbe7877f72f57b9ea6041bf2

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