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.6.3.tar.gz (47.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.6.3-cp313-cp313-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.13Windows x86-64

genai_pyo3-0.6.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

genai_pyo3-0.6.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.6.3-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.3 MB view details)

Uploaded CPython 3.13macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

genai_pyo3-0.6.3-cp312-cp312-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.12Windows x86-64

genai_pyo3-0.6.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

genai_pyo3-0.6.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.6.3-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.3 MB view details)

Uploaded CPython 3.12macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

genai_pyo3-0.6.3-cp311-cp311-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.11Windows x86-64

genai_pyo3-0.6.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

genai_pyo3-0.6.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.6.3-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.3 MB view details)

Uploaded CPython 3.11macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

genai_pyo3-0.6.3-cp310-cp310-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.10Windows x86-64

genai_pyo3-0.6.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

genai_pyo3-0.6.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.6.3-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.3 MB view details)

Uploaded CPython 3.10macOS 10.12+ universal2 (ARM64, x86-64)macOS 10.12+ x86-64macOS 11.0+ ARM64

genai_pyo3-0.6.3-cp39-cp39-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.6.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (5.0 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

genai_pyo3-0.6.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.6.3-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.3 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.6.3.tar.gz.

File metadata

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

File hashes

Hashes for genai_pyo3-0.6.3.tar.gz
Algorithm Hash digest
SHA256 60e31c4b4795b87d616cb9bd0cb56b2e1e511afeb3013307c2975b983cd3b8fb
MD5 a803eae9a514ecfa4f4ec5cf132db9cb
BLAKE2b-256 e7bf59b0edfb1e9a25a0585bf4b424f7fde8a417abce7cb62507252789015ae6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.3-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 458ccf9f1a47a5e4361cecc2674e38b343b4397cd886fbe9c5bad16bd9962a03
MD5 1998dea5f302642339ab895a2e6d528b
BLAKE2b-256 a13969de2273859dc95949a9a065dcb9bdefb5ce52be9dbfea275afb510b104d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.3-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a477e643ec67fb470976708e03a1a55f900ab1a0be8f05421a8a69621543c419
MD5 a73c60fc5e18003865d1b11b5ccac1d5
BLAKE2b-256 f6c0d0d22c44805d0b1869a14b15fa26e96c7f8bcd9d0fe9ce951d6b28d49447

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.3-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 32fcc730200527899d16d8d6e488d8e9a69eb9698f31b38b0c11a37fe877f33a
MD5 8f835810ff9d23f7eff40703eb6996be
BLAKE2b-256 f4b410ee924282a71c77f0faa40bb58e763d36afac40ede9c409d72f0c53b104

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.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.6.3-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 f31d85f1476fbb3dbf993edf71073aec568e4ff4ed7c3eadde224914696564cd
MD5 2e7fbdede959403aa86506f33266a01a
BLAKE2b-256 fddd9d2d0162723b2e356716d95fb06b30f1119344b37a6f5fa578ad56e564f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 fecdcffe2566f5deb7f8bd45308786ba6dfcc7e915a5d2f2248294cf86dbe6a1
MD5 76034bab62b741140b821a5fb9bd3f2a
BLAKE2b-256 3d395e3abaeb6c1d07d44ed76a976a92925ff2db82892c5214ffcbee4a21ae71

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 910b8a6cbefdbeb18a1660b36dab843b1ab327b24eb85a5403b59f56e808d64b
MD5 9ba96d2eccd5eaae626cc6f043a32a6a
BLAKE2b-256 aa356bb846e07e360fba1df8ee71d18eb9579a25c05d0922adb581fee20e93cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.3-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f20e18be9a04dcae76ece6a95cadbdfea7ba1288b90be10a14f8dc6304be0472
MD5 07b76050efdd6f5e9a7c5c20d8fef1ac
BLAKE2b-256 54913a6650d315a52f160341a3de4cd3dde906976b30f5d591acf57d6579587c

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.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.6.3-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 29d48f315c789ec846a2c290bb529f040474eab0b8d09c872be86f9501520c36
MD5 044299adfce307232d5d4bad311e6299
BLAKE2b-256 b77e840809b2d6f9f47cc1c85ed33b38afcc99a8f82be4cd7c4cc860daadcff9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 892d7586c9586ed46920d774af8432bc17d9af0b91c0ec1974c09c23cf9e5f64
MD5 2bd5aa5dd375c7490c43cc68305ed739
BLAKE2b-256 dcf259fb00daef68c16df8bfd4fd896901c893515081597b30bf13dc9ab9ee75

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 86d95323cbb3bd550dd4b95e36aa315417311028fbec44935ad5832fcff0b77d
MD5 2069d01bea7e6abf316e982d420a0aff
BLAKE2b-256 f0bdd9df1f7d10759cfb04066600c741b50b0273008edf5bf0e11a82954c5f58

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.3-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bc1c4eed6813c39e2e764c41bdb6cfd50fcaf846d2a9192c58d344b5c39d4c13
MD5 5741a9fe93e4ad7fcccfc87c8907f362
BLAKE2b-256 6a335168d7d81509f78a3ea4bb65412090fe1d96a1d8022f2956d610ab361f5a

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.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.6.3-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 0d4ad37090931b5d65d1e00e7cf7be2efa0f01fc5ce8d43198f998da4103bb99
MD5 276c4d63cb4bba3730c082d45061d8c6
BLAKE2b-256 6eb9a33557cd23e8f985f884db829adcbfc2ec034bb4dcb13347e67a8a84fa2c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 1bfdeb3675475816b4e7db5800d48497216787d2d59bb0ba15530bd009a1fd4c
MD5 5c576237c0b610babcee05fa1985e756
BLAKE2b-256 e1b4318fb609e8b396768f4566ceea8fb4eb1b0c30e191065e2bab8bfc806066

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 b230f261b2ea0372d2683f87d304f57e170f0824faac534387847c0607549f33
MD5 d564fe0624003fa31ab9099f352736c0
BLAKE2b-256 e9fa156fef667ee9a7cd6f550c9d76fd0d4fb2e2c971f17cbf2cf87c8f674abc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.3-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 96d35a216d6bb8088bb468216097d295e63ccad12c0fd23de6bf1079f02f997e
MD5 7cc314dcc986255a4fc7477ca931a3f0
BLAKE2b-256 21bb749e771426d7a38898962abe731952972eac7667a3891fe3f46dc82c08a7

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.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.6.3-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 60a6186f6afde4e5836a7e103d53e2b686a2cd8dd47a067c219a5ae8ab1ea4dd
MD5 a18f729e1061482a03d663503a107102
BLAKE2b-256 da4d1ba09e975db2e850fbbb412c1dc56dcb93a9190fbaef45b2470d6dac0127

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.3-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 b1eb8609a06dcccc9187ce82b106e6aa3ddcba03d53bc18a85b06fafe858d5e0
MD5 025e5ff8b52c7c2d34f01220e5a6ec8c
BLAKE2b-256 5de37d05c4a1f8e131c862256ea73bf4404967466c841db2a7c925839b8f5f8a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.3-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e04f85f7ab66483e80d3f795567f6149922d69dda3545a6a1f6e7624ad756cae
MD5 06a01eea010412cb999d3d3746dfb307
BLAKE2b-256 3520e4550e575970bcf4f3baeb8184ace245d03e7ee661d3ac1828e0568b1cd4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.6.3-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9d00d10c7edd176ad477c51e749c2e9a6e7f479b0a5a9cd77d655aeebf7040ae
MD5 e903f262f2ec44965169e7c8281adbd4
BLAKE2b-256 77ee552fbd5bcded83720a28c9d6c8bfbaac317e2df7101620b014e549329cbf

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.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.6.3-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 f9647ea2f472c615c8e9de9f77a99a8ea24eaba89f5b66ec5838199341e5ce2b
MD5 0c3d3c4e8e7a36330057dd32efca2792
BLAKE2b-256 f3ab34c48c2d7fd040c7454ca7517bbc6f795a8267fc2eb6bde1aa8f5ca55142

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