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

Uploaded CPython 3.13Windows x86-64

genai_pyo3-0.1.3-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.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

genai_pyo3-0.1.3-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.4 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.3-cp312-cp312-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.12Windows x86-64

genai_pyo3-0.1.3-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.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

genai_pyo3-0.1.3-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.4 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.3-cp311-cp311-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.11Windows x86-64

genai_pyo3-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

genai_pyo3-0.1.3-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.4 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.3-cp310-cp310-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.10Windows x86-64

genai_pyo3-0.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

genai_pyo3-0.1.3-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.4 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.3-cp39-cp39-win_amd64.whl (3.2 MB view details)

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.1.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (3.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

genai_pyo3-0.1.3-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (7.5 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.3.tar.gz.

File metadata

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

File hashes

Hashes for genai_pyo3-0.1.3.tar.gz
Algorithm Hash digest
SHA256 8188bc0232f2276b6c1f50585d2bdfdcdaef274490acbd9c291517870a2aa074
MD5 714f772b07e56a8de238ef1ab7871a37
BLAKE2b-256 12cff84057a7efdb1d01c624dd1e168f836c2032bf31f3305c5e8ddf59abb76d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 115f831893e24cfcbf2ab38aff94e8ae0369b6114e9216669313bad6e1cfb63f
MD5 3c14c3a89d74f123bd1f3b6921ce39ed
BLAKE2b-256 2930cb7d386cf051eaa771c8ab80d816c9faa2f914e20c3d4e85433ee2919324

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d00fc9cae3000e4b2548de1e0078ddd62dcbb8e57f7a1664b415dc75925ba4d7
MD5 1c82cef861d341e44b3874dd763cffe1
BLAKE2b-256 e397c3d1b7e7b2ed370eea2d7e3731b93ea30eb478e39f33aaf299f853f5267f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 36cf4d5146aaa94f44b2bdd94c1069ccae4c16a91913950c9750027956f2a96f
MD5 8647e2be168d23bfdc909e389093ab57
BLAKE2b-256 a8b59ca5fbd5b946902a00b2b849074c9523f16d33718612c95978f1f1913c8c

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.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.1.3-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 313e4d05d30a0cc106a387fd2e5a5eed53bcf011fceab175c376c7e1351406f5
MD5 8c6d26b9b67484f0991200caf994cba3
BLAKE2b-256 f1e0973e3bb16db36eef58e6539d7a0f64d223012f1daad9d518b8b3869f6eeb

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 6b272cd3382559594d6c7c0100726c606d9dcc1f748381b3c09418501661449a
MD5 09a2fa19c5ceed724c5d1b40d8f2e5a6
BLAKE2b-256 ddcb6ee0d84fea89614df4037661d3b3e9f7560e7ce68169f79c15a496367bb3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 4bad99e15c8f4ed3e68cc8f7adcf121462425a99ac690288734fdc9ff9635d6b
MD5 aeb8ad5dce4b89b2762822d370b4a63a
BLAKE2b-256 b3c1ad696c4782d53805b1ed3f43811379d7b56f7af611ec44ac487f733d241e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 ef7ed09d01384fdc8c30c93465e2975a5d1b36377d6e407daae3390d7548fdb8
MD5 f2a8d741f525df7226daccd8e0ba9799
BLAKE2b-256 934195dd0048bf307369275427b7f3f5ab20320c4aa1fa813c2b9c8e387cd875

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.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.1.3-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 a59dff79e4848c90e6e5f0e0343eedf1c3dcaea9c72c163f25c215e7ced34da7
MD5 ede847acf16f2260385fbaff83b5e14a
BLAKE2b-256 303d430ba76c11608d23a66ade34f044c4ed666ac6aaaff34121019ec17315b8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 c6ee564d836f006a3b15917dfa0e410c48f5293137ef200be3e392ba922b0225
MD5 8a0fa929c4fd222e416d87aab566f60a
BLAKE2b-256 887678d0bc00c20628da139c3338fbce8d0fe9564ed653af307c87cfba58aa4e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 714d319053eef94dc960d00e43cc2292b38e527a50a5804b55742473658e548d
MD5 ed5fbe0987cea6f6ecebc8ac3f79e4e0
BLAKE2b-256 bf8f4133f0f2ec9e45534f9062572ecd27cd0dacb23387d1d09d0d2f27887634

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8f296fb2654490ec29bf4f5f9bb3e1dae1184a227f0e473835f92d300beca937
MD5 b58b9afeb5d9caa16438b01b2b60c134
BLAKE2b-256 4cb13bcabbceddb4a0023a81bf58751c1e4a8408279534c0421684f979a5e8c0

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.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.1.3-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 dabfa7424e957c8d709f0a02562dbe7e297a314fdc4f886ffcbfbce77da0fb16
MD5 68138b98c6669679251331481c6b37a5
BLAKE2b-256 d66dbecce026faf7035bab5582e5ec941187d8a98e266c06c28877e6f40bb847

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 2d33cba4eed8d0da39e52f5f5c275545cfadfda7a6fe2b8f10af46977f7d1ba7
MD5 d0560bafbc3583ae91b9c7bce0c2ec59
BLAKE2b-256 6861fc33e8274391e8881a40da0d4e76792fd966b737461fcc85779adfa5a337

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 2318244dc0df9f17c353c437973e5f07c6a4f791b7b9608d7273a23ed09d4c6c
MD5 5cebc656a22bf10bcb8da8e0342d0e20
BLAKE2b-256 329918c2ff0ce86b0626a47765dd39108cab4e4bd340362264fc01f5fa74a30c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 35a40876a79e60f384efc232ffe736d3815c04db35e9478e16b819492319e929
MD5 e4b1c30721e951b4d886b910b44faad3
BLAKE2b-256 c644f5d2592e9e412d9d253ebbf1d71aaf8342a3e181350ff50f841e16493e48

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.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.1.3-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 b3d0d4e5aba6f893af5f549c6ea7608ba91654894a2b7bf2e7af956dc357c786
MD5 12a8c30e93a0f3c0498fee39e501514e
BLAKE2b-256 08ce65d4877985b0053b12ff1ba91adbf3402c0de05bd2729143964663dcd126

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 341a78555b976f4b8eb50afd6d6b95684f915dbe9606d6de90c771781442417a
MD5 02066c90019f8060844d61ceabf22661
BLAKE2b-256 77dba25a502aa5ee45e811bb4548b1a65a75b540c6ff03c8a804e3388e833b6b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 691ab4d9281f88487b3619c3bbe6bac9ecccd76b635693d34532417384e37a5b
MD5 f1b4c9fec3a6569a004fbfb2652b3388
BLAKE2b-256 5618b973298c66bf7ed009688e2de4942f142405a1d57e9e6b67be9d774f8438

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 42a8c730bec00f9f5dcc71df7c19d14508f09e629bb13485e1701965caf1a812
MD5 31e9ec52f0caca8c318512d6d1b37d88
BLAKE2b-256 a08ebd8dbcebc1c9d7d3828c01c64eb661eb6844140367e1ae7b94b53d232cc1

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.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.1.3-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 64f612b4808d492764a807cf17ca4413e95bedee06761e38d6ca3518a96d738a
MD5 577757174ca99f8207390afc17b6acbd
BLAKE2b-256 ab13f3f3e788b3addf0ceca1f704a60e7c3b259918430954f9b7e9ad6097fd98

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