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

Uploaded CPython 3.13Windows x86-64

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

Uploaded CPython 3.12Windows x86-64

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

Uploaded CPython 3.11Windows x86-64

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

Uploaded CPython 3.10Windows x86-64

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

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.1.5-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.5-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.5-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.5.tar.gz.

File metadata

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

File hashes

Hashes for genai_pyo3-0.1.5.tar.gz
Algorithm Hash digest
SHA256 38c65c2d937febfe00c79254795e9c46a92f7a736d3c13171a115f1d6c3b6bec
MD5 c876797b77c4465d859f90dd1d8c43f5
BLAKE2b-256 ed08b2e024801c9f30018537a868eebbf20169b872c685fe7bbad90eb315d77a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 20fc0a5f74cafe738f180bfe01d5b125f6d3c27fe34836438d675d5670e5e382
MD5 898f20a0d5754c0c0e30774220fe54b0
BLAKE2b-256 81b407823ea1885a8f3e52c39b8760712d857878a950d2803fe7c5e908c25431

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.5-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6b27ecdd061ca34f1592cfd81726d0fb70f658b64bb7ad1d3c80fddedf7b4596
MD5 43c6af6190586ccb2728f9d1d0fd5034
BLAKE2b-256 3331b7cb9163f023dd7b2fb2ae110fbcdb95f33fd7f5f05d3296994501fb2a40

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 b610237a1c0d26a82231936e1ce4bc7a4405b25438591f71a0cb9ffe80836592
MD5 54d6d70f51afa1b4677c363bf60825ac
BLAKE2b-256 68fface8f5ad0203e2d01744656e93e60ad403cab0b43bbcdd3e5fcfc7fa4ab0

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.5-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.5-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 a84aaab835c867e618397d0818093e919e3ac1b1fa635e679325006acce0b409
MD5 b4a56b88624c5d20155289dd815a4f5d
BLAKE2b-256 a99feef1df4f77afe40276d64c7fb22e6ab77f7b137cabdb38d852626c79cf8e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3e9484d3f33359fac6f12f5606f00ba23c71795a133f694cc6330fc2bf7b33ec
MD5 4a3715f530e2047f2a50af38284fc29b
BLAKE2b-256 2caa2a531590a04d29288ea72d17cd43f020c4309cb1faabf2bcc5c5ba285e0d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.5-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 9a6788a1555b1071dc91fdd9908f5dfd803d767a34ab3efdddd13c3b50129001
MD5 9aa9e14de634241336a67e9d1ece79bb
BLAKE2b-256 c6a7111f7add811ac83be5d18a80ab9a4c61fd7f0069547b08582e516082f050

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c1df00d823b413de2be9019b89c7c25646f20c88c70ee3b0f6c11d9baa2998a3
MD5 a41fd0c1af4dc53a7cb9c24e65cd00f6
BLAKE2b-256 fb6a8eeb417e9452fbf9b1bcf3a4c2db7ac61ad6088685d5ebc2abde97683b82

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.5-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.5-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 c12c66de2f1636224ae7be3f5a66e08796cd25c0e834ed7931bfb6375c33efb1
MD5 2640247dbf4d28e4c05d7f29d585f292
BLAKE2b-256 0d1a1c63a68f3d4c06813f9547483fe3d51d3a7b3b67b3102485ff10fe71cb0f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.5-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 be668a06ca88805879bff0c928faa92ad472884b11389cf1d6f7877100573b33
MD5 0353c081c4b7e0b572d0a201aade62da
BLAKE2b-256 6d7e53dd96e72acc3ffcec71a121f5867a69cc5b72a45f48ad686fe607a1c6e2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.5-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d01f98f7189dcc118cf6b07a1162d8a2fa49c2fc3e8368ce9f8f9599b2cfa40f
MD5 b102da57fda22aa3de81e0742b6bbca6
BLAKE2b-256 f52eb71690f079297d427f0acca5604f57ed082c1e9fea2f5d50cc17b2d7952e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.5-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 629071ee19d6e427d644d146b4b1244a8593f15d947fc1b1fd7871b8d3b7d619
MD5 4b1d7e1928a09ce951057728d07b708e
BLAKE2b-256 21e59ac13871d45760f37dd861f87a63342e63a236e9b1c6261d14b764454961

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.5-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.5-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 af3053ca61107e9db201ce570d7bdb2466e55807db60249c63074b165b0d7bba
MD5 1643f892c95b29f11241c8c699ede1ee
BLAKE2b-256 751052a19ce38540de920ca95a63fe7138d07c95cedba13541310ad678db7c56

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.5-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 9061d5eef441522d4a2f735ff69570f1f975b16a68295ad7e14284af963a4950
MD5 b9089f47372ce116ccc63e52a1fa0fc7
BLAKE2b-256 3e22f08d4915cde8aff6d1118b6f4f21d7bb178909b975ef529d3bc35a4a0aff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.5-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 e642e274409d72b64eb302d975a1a14ce91914d6eb76fd91719fdd638e22f739
MD5 4e578b1b9544dd68d90944b27c9aa8a0
BLAKE2b-256 925081beb8ec2af80a3d94201597293c44a0bc6f4a56f4d67d6e8642dc5259b4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4ef6dd17fc086c4b2fb7dca16c56c69fcfcf99f69f89d35e76943c02f65e4d46
MD5 8c580527ad2f4220ff7f8b04c7b3313d
BLAKE2b-256 3bbbbb6d731cddf44d419e4294037e51886c00bde85641ac2b77c6780511f891

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.5-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.5-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 231dd3eef9648a15409efddf96d952202577708b07523d4df82602f79b4e1701
MD5 d5ec7ec0dbde26dc42aa61a97bb17a43
BLAKE2b-256 1ee1f9579e71abf083117f0188ed1c6539fec3af5cd634bcf7252528afffb3a3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.5-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 fb8b60e2f50a2c4c3b1413f2181c16b28bff1fb758224403f3f5273ded11253d
MD5 783ea266f124ffde4f8e790a4b0dd1d2
BLAKE2b-256 0267fee86976189552140f06cf3533d93f0ebd92c2f280da459666f1c11c50f3

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.5-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 281f53af820826ea28ea3c6f8388dba7b713f62e738bdd59dfe58a519f3d3eb6
MD5 5cdce753010d0d2caa2509b98b6eba5d
BLAKE2b-256 72df04a209495d6245bbbf554eefa0af3c86775552e83ffc16e7b28a29a1278a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.5-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 f97c4403b26559ee623eee878535fbde0cdae86e3ae8c5ee26a15660aa189f02
MD5 14b07ccc21829d095c3bbe8671b56a35
BLAKE2b-256 0fb61643623c40c252df507b1f59bdc4966a89c3f2e21a1c91a387616eb663b7

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.5-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.5-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 2d1ebfbea4b959be07f43e9e4f152b28d438cb91e043a8b48271219b78b92782
MD5 bd9f43f0477eba993a95945c39d18bb9
BLAKE2b-256 87d99e53e171fe87106f46778a80a45855f974fb843b7b04ebdf2490bccfbd29

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