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

Uploaded CPython 3.13Windows x86-64

genai_pyo3-0.6.1rc0-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.1rc0-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.1rc0-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.1rc0-cp312-cp312-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.12Windows x86-64

genai_pyo3-0.6.1rc0-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.1rc0-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.1rc0-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.1rc0-cp311-cp311-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.11Windows x86-64

genai_pyo3-0.6.1rc0-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.1rc0-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.1rc0-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.1rc0-cp310-cp310-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.10Windows x86-64

genai_pyo3-0.6.1rc0-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.1rc0-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.1rc0-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.1rc0-cp39-cp39-win_amd64.whl (4.1 MB view details)

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.6.1rc0-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.1rc0-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.1rc0-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.1rc0.tar.gz.

File metadata

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

File hashes

Hashes for genai_pyo3-0.6.1rc0.tar.gz
Algorithm Hash digest
SHA256 4264b5033acfc00040782c8f0ef46c240aea244c213d763b253456f6f50e0046
MD5 f0eb97ef592bdca2f64cef89e77eb790
BLAKE2b-256 1f30c893983d3bf57f3e7fb6a5c9cdc67a4302d5326d7e09af1d4e6c0d95a0cf

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.1rc0-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.6.1rc0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 c71ed543e0ff3850a51a19fbfb066117087be98c10f9678eb408f23c36298a2a
MD5 45711f463e8769e7f9fa0c68cc3886a9
BLAKE2b-256 3385606558aaaaf57b92c6631ce15c2abb2b949f635ffc526b2d13dc26578eb8

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.1rc0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.6.1rc0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 50102d440d4b36799ccd01da0f5abe295f7abd0abb7bb4879dd3cd41f3637ff0
MD5 c609c6c377edff737a06d6224777c90d
BLAKE2b-256 5bf2b38bea861dc0930a14dc8a3440c05af2f334d6bc7a45e3a98e8c6ec2d179

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.1rc0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.6.1rc0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 98dfb11fb58cd260d2f427b1745ca96bfc42c739e6c123b7dd71d670dcfb29fd
MD5 42cbc5e30d3c225b06ab22b295b6518d
BLAKE2b-256 c984088c009e2103e7d011e48316cf218094780f0bac183f62d80edf8e18cd1d

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.1rc0-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.1rc0-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 1b04238819232af168df9414c57bd62e185d8f2534085998215095c269e80c1b
MD5 b569ee330711fa2dc80646c1eee889ba
BLAKE2b-256 2733986bb39c8dc34a9784e87a94d78f6697cbc0a73031875c72c796676e6270

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.1rc0-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.6.1rc0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c6a63acd6190eb9fe72386bd98bd4a4809bf9baaf2297ed3c6ac6e9a37255e2d
MD5 0264081226721458ae97be839e968288
BLAKE2b-256 65aed84ee5491f1d58216adb094d93e22d1c4e6d35d260c1efa29e73bb7ffcbb

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.1rc0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.6.1rc0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 863e5782d1278766b589074d058898a60c150cb7cfc063d08f19bd641811ee26
MD5 42b4676fb6384b55dd83f6ef62e6ac2d
BLAKE2b-256 ab81aade002e336c3f927b84cf4f8813801cdbcab30d775efb204c1109ac8349

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.1rc0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.6.1rc0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 a76dd0301a8027ca1ede42b19621c4379393c8d4b15f3ea9a7c22ba3924a18b9
MD5 d8cf2bcb88068c689fb85768696c4f9b
BLAKE2b-256 fc95b62a540903fac14e2a5b8b23d6e11a597ec063aa9a0c04aa690f6592ec6c

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.1rc0-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.1rc0-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 cf5c3d605dc2db22a28d34b856a36a055bd9c0accc32f9ef7d6fddab6db3adda
MD5 8d5d468b8512e9fa4932cb5c492640aa
BLAKE2b-256 d1bffbe1bed27089efaa0a98dc302cbe1ad4412454e4e35469397263b304e1d0

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.1rc0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.6.1rc0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 16518029303f9e59e2602fbff7a351b2803bd5c66e51d43ba7711924f5025b3b
MD5 1adb14731e5cabf1049f5f3259814099
BLAKE2b-256 8246d60b5cf51dd500c7ed3b108faf818c1103abb0ea6fc538b4b57fb3301761

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.1rc0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.6.1rc0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e22081a2ea330c921453a6c3ef5d61ecdd626d3f7e0d59e6613503669a5e153a
MD5 5dd327598643ca8aa08a0d63833d0942
BLAKE2b-256 bf1c2fbbf17dd6e3a63395150a6f36ed36e54315337d12e33d481c8b2d0b3645

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.1rc0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.6.1rc0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 477fde26cdaee02e7a8ece74c22f3b9e033e78a8767ed6b97fc7dc5efb5f1455
MD5 f459d28a8f186e5e126b24cd024231fb
BLAKE2b-256 c2cf3437bd1d1eaa4f663d84d94c198f541bbee190f1ad62ec1b8677ebb5e15b

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.1rc0-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.1rc0-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 28794b981fc1ea01ff086d8c29d495f0afb040532515c6624c2bf1d1b92d5a76
MD5 07eabd1f7076a2e0571fab5b7391aa04
BLAKE2b-256 de068f852c32ad57651427e67b996b2783328aa48e6360ae656b83c08a3abbc7

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.1rc0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.6.1rc0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 ead5be838fd5bd1d29f56a45ba68bd8b5eab87dd078a8f2424de00b45c6aa597
MD5 45bdb32f06e47b0c0e69e77716f057e5
BLAKE2b-256 7139d7368819f564a9a6f271240aa92968b6225cb2426550c50f03cd7cf6c8e3

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.1rc0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.6.1rc0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7431fe5e813292451edbaf81288c2b60a0981f03de5456c0f764a5aad1af4646
MD5 d0f26c1ac77b17b4010a4aa1db9b60dd
BLAKE2b-256 b773ed072d726944e0a930efc7715fdbf5cd5a1e7d5a8251083c13bd3683b41a

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.1rc0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.6.1rc0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 56496a04aebf5750454084d6d058050804134873c19df7d6725513566c8cc2cf
MD5 a8015609db3425ec7771b96b044057a0
BLAKE2b-256 1b39ed420eb663c7ce7eb1d2e59257cf6457ee599934033e5b06e9572abfb6c7

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.1rc0-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.1rc0-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 97add7c8b2be2fdd9c2faef3c2688a8ea480b9082d40ce6669e537c8f8691ebc
MD5 d7d9e04ec70bff71f0c535b4aa828a09
BLAKE2b-256 63e1a29745756e375242a4140bb996716b97dd487afb7f8f7cf9c4519ac1bd9a

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.1rc0-cp39-cp39-win_amd64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.6.1rc0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f444c8d15a997b91092d88774f9662472c44add037fce9bc38151331f8783f5a
MD5 3395959c7ed96f06f7168eb0ff180e1a
BLAKE2b-256 2e49cbb102849674dc678e08eecd358d069ac60960d9ce7c308217b9c45dd306

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.1rc0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.6.1rc0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 7401fe76db8f378444e546395495d118630a83874ce2cc5211ea06ffa6c3d861
MD5 75f8b9cdb606138ec089e868eac5d390
BLAKE2b-256 70bef1db522076740025845b5cb773b3b3b180981f0c775ded57d65ca816d306

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.1rc0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for genai_pyo3-0.6.1rc0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 8fcbe0a8e04e7f1d79a445b5578af80302a3fb8928a9314c546e9cde6ebaaeda
MD5 6269bc5b678cde345d0f2ce8678ea3d8
BLAKE2b-256 3e7ea6099c8b69e50be8300a467ce2a070265edda85f7ae3667d2b66cffed291

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.6.1rc0-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.1rc0-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 7080d6bcb48d5f8c598d6276481922d137c445f28ac2bd15fced9057113a66fe
MD5 584fc66c4213792482d6f240b7068aec
BLAKE2b-256 694124d910602633841d7f70b6ed725c12475c6cd4ef52174374341bfc81bb80

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