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.6.tar.gz (37.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.1.6-cp313-cp313-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.13Windows x86-64

genai_pyo3-0.1.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.6-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.6-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.6-cp312-cp312-win_amd64.whl (3.3 MB view details)

Uploaded CPython 3.12Windows x86-64

genai_pyo3-0.1.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.1.6-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.6-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.6-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.6.tar.gz.

File metadata

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

File hashes

Hashes for genai_pyo3-0.1.6.tar.gz
Algorithm Hash digest
SHA256 238f661c67c57470e69f067d7f6b6f5b79d01920e6cb55e81629bef587e2ce66
MD5 d5e184b2d3eef11b7b44da13b6b0cd55
BLAKE2b-256 3d97f58b1a2d7924965b7993d964de24a5745188dd7d66893aa4e7e660b96c54

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.6-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 541bea0dd74027b4dc67dc0a5f7bc93871fbffc37f34999d71aa466f998302d1
MD5 c02084f9ae3461d5ccec87ea8118e358
BLAKE2b-256 45ca7584396036540ef807c125dfee6bf9c737b5efbda9413585c7b28b363449

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.6-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 30076c8e8fee4e04ddce8d5c72da59a6bd6de2ce0fb9437b02db45a57264a75b
MD5 a617f967187ddcc1ef44895827124b9d
BLAKE2b-256 36f348821b6d4cd62639b3b301d8101644e840cc90ad3c8a6c800e651cc7b656

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.6-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 1c4602de4e8806417fa5b6b53d96a62aa11fdd76163539b7a30a42aa02b00945
MD5 75514cc15e724444cc4b3aea6e3b8c2d
BLAKE2b-256 cc26cdf02f5304ac9f1eaa348ec98eb0c3cce512777b41b29fd794d6d2e72b59

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.6-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.6-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 556753a429f4f520bd5b1ce40e92c457e7dfdf540e067e0725a5094d31bf69cf
MD5 a0cc4636b4635246ee2facf0b66b0ce4
BLAKE2b-256 42ec9ae182564e0754e7a284e05a75c58128680341ce878cc87b8862a776499a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 c7fefebfc196021ea61ba21e4779128fd9c4fb81ef7ad60225e7c3d999fc7ae7
MD5 f5987d8c13f1e8f6b0bdb2aafcd89735
BLAKE2b-256 1b863dd98ad29f959a7894eeacdab371033d0eb003b8a69291832195009d6b1c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.6-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 8cc89de808137abe3f8f6a7e2f67911ab9d7c9aba245f974cda0460cd7496d71
MD5 d2ee1d45349f5bd1291bc525932f1c5b
BLAKE2b-256 cd2dc24ab8517aadf06e172d6a4a9b0e859a1f88d1547e2bc2c1e1dc0ce09b52

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.6-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e1a58d20b0bafff075a35dcc58a04337d35362c401081a8c3e5857c026f12d31
MD5 40e0f47891e8ab80035b8a826227d8e4
BLAKE2b-256 9c8dc057db720844c177c629459588bf44d6f99c8d0ccdd34238e8f29cf5fa74

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.6-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.6-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 958d0e1ba7e3e30a500230359b3245e57f0ec99a4b321e84d6ecbc086117aec3
MD5 f469519ce88364dc8893d96fc93f61c8
BLAKE2b-256 fa863f69159c997ddbc5985bf64484e75f476823f5190c1ad8ef86a4a673d13a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.6-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 575789418891d4da24e78e041e20052294e63649243fcf31cacd9e4cd0b1789f
MD5 f6cbaecdf7a5135aa0861394890aa838
BLAKE2b-256 8129f9cd44db6f21e084c904e4b76123ee68a3c10b712949603794ab47e37dac

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.6-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d26376294b2fb9959b1276c2d5b71cc1840c777e7d7e2c60b5f1248dcacbf10a
MD5 5577a80892086e30439e67ed4cd2af5c
BLAKE2b-256 fcb0718fe19ba5d2ec2cffe8fef377f2d36fc04da753d87cf317f6c0d52bf110

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.6-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 346dd1233fab2bea7692fb6e382581c143e04feacfe62d1c4245270fb37f2443
MD5 5007ebb94fa71bb04f49909536d29776
BLAKE2b-256 82df40ba97c08f26e1d60654b8c59a9947eca99548538d1dd9791c76be9e8fa8

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.6-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.6-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 ad8e5eaa6fc9b2d0154d22f769a5bf7cf070707644df46754579ae158e7d0b1b
MD5 4bec7b847caa03b27dc2bbc25f8cfde1
BLAKE2b-256 6661260e4320c16c92f08e126994f96eeb49a15cef8fb67c084f070b16836f11

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.6-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 506f019fcc6c27fd5d2df8ed02e65e4845bf3aab6b4aa9bec6d952c66b571268
MD5 b309ac0c3999d704e3c4d72041865552
BLAKE2b-256 d5f99abf67e76abd1970a1b1838e2ef0f658e3c4a139528e7dd98a073d07c0ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.6-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 63bcd1d4e806cd765ed699c15591aaa473ad6edcadc5cb75961a2dd59f5b2ef1
MD5 41dd80cfadb1707cb47c232032526fd6
BLAKE2b-256 a7ccf3641be24db7e551dda3389a420cc57d227b23dc29bfc2a978ec4801d8be

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.6-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f8148da084dab464d28ee67b3adad63bc1b7950210f14a68974741c1e5c12f01
MD5 2287cd5608fbbee2b52de0ccc8f4ff1d
BLAKE2b-256 caaacc64620729759db62a9b1a02c5694e06c78dc19fea0f92e4445652077554

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.6-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.6-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 0d3a05dd22c08895cbfab86f7f703d880a1cf7005ef20d5b3e18fc44df220bdf
MD5 8fb31c9dbe02c6d2706e0d9e21e7e799
BLAKE2b-256 df7c0bd06632190c39ed182dfd6937c0698b1aa5ce1d9bbe6132601ee2a9837f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.6-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 edb811d09059570048b67528281a19cc570f443d3d6ca44c1236c38d831dbfd6
MD5 688598ada9c9c1bb60ec290ecf7237e5
BLAKE2b-256 95d2576db78384cbefdcaf498840ef0388ae194f84e44ed7b70c67bbc4e097e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.6-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 38e9f6b92610131bc5645bf2983d1a081b6e8cea2c2a184be7c1e6217c1e209c
MD5 888d664b8ccbcc73bde4238a95de8245
BLAKE2b-256 cfdacc61ef191efe38662d73cc7e96c6e029547670c0ac28faf59cf283c930e4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.6-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 070ad329449aab8e1116d605d56de3e25d70b84526337539c363be89e7556de3
MD5 62ce2fb45121492ee32c8660b24e5780
BLAKE2b-256 29a37c4c77b1d751a45096a8a3d417c52a0c2d3df7639e6cacf74fd382b50747

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.6-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.6-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 42bd15f36fca11e0ddcbadbbc99a0599cb3fb93bb9831551651366e51812cb84
MD5 b06b5c3eae51969b94a89b54ca4f58ca
BLAKE2b-256 05ca3dde07ce89a86699f3e519daa4ce1841cc6e34bf4db18edf02ce32f55056

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