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.12.tar.gz (42.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.12-cp313-cp313-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.13Windows x86-64

genai_pyo3-0.1.12-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.12-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.8 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

genai_pyo3-0.1.12-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.0 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.12-cp312-cp312-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.12Windows x86-64

genai_pyo3-0.1.12-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.12-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.8 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

genai_pyo3-0.1.12-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.0 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.12-cp311-cp311-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.11Windows x86-64

genai_pyo3-0.1.12-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.12-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.8 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

genai_pyo3-0.1.12-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.0 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.12-cp310-cp310-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.10Windows x86-64

genai_pyo3-0.1.12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.12-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.8 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ ARM64

genai_pyo3-0.1.12-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.0 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.12-cp39-cp39-win_amd64.whl (3.9 MB view details)

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.1.12-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (4.9 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ x86-64

genai_pyo3-0.1.12-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (4.8 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.17+ ARM64

genai_pyo3-0.1.12-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.0 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.12.tar.gz.

File metadata

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

File hashes

Hashes for genai_pyo3-0.1.12.tar.gz
Algorithm Hash digest
SHA256 ce4f9b81132dd7dbd8254b8798cffe2a416614b59906ec6a63c3731b74b961aa
MD5 a7b3ce5985201f041cabd4632ce7f7cf
BLAKE2b-256 56ad43c540fe56a33f8ccfe17abfead6515b52a57e2e3d5c51013aba24452ac5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.12-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 a07dfeb252fcae77bd122153aa30427d9e5f2f0c5eff36196bffbf75e5ffa282
MD5 e17d1d928d07709d9e00ebcf33098975
BLAKE2b-256 a05037cafa3974a507d6f4e21a3fefd493e4ca644e968421b266a78e0b064d57

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.12-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a8273f1c7da1b45e3799c1a8f0b26b2036664a466387a6e89e64b647bed2bbe5
MD5 6fb9dce8e4ab5f269983c783fbf8fa1e
BLAKE2b-256 ab52a5370c3cb244c4d9cc0a54aa5405042c22c49fd577d6094812062f0a47fc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.12-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 070ca084b0a26a4e0df5e9f7853e616bdd0d4085fec498fd4451d00bb6260681
MD5 f0da30e4ed5e3cecd3a1319bba79dbf4
BLAKE2b-256 f16dd26eb93bef823d77472ffdd62b75475936594aa668f76107030b1c907615

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.12-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.12-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 6c9e79a389477a049d77d7c5881cb6fb3505b512d794d35c810ac37ff6a89a6f
MD5 85dd3de70f59cf25166a3bbe7c26e0b6
BLAKE2b-256 e66f1a9ca2e7d7768fc9f2d70db589616cc1bbeffac825b76cace6d3b35097a2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.12-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 e7bf9a1b4ca4883ab8b12a5b3b5e9b14ea406bc0cf2c72a1f26ff6da91944cb6
MD5 d571230a07090786c42b1bbcd7370a02
BLAKE2b-256 baa97ae364a02b711a4e2328b9e4960a8899ad2a03fbcd3f6f0e78f292424876

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.12-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a75ecaea52f52ea2677d65409f9c1aba14df349834205761ea7b971493465596
MD5 15956418177cf6f0580c0559f0cdbafe
BLAKE2b-256 1392e8ee7d9b59e306288e4052dd753fccf32f247ff5b1cbbae110287c16e48e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.12-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 43953d558cbc9ecef8456c7f4ded974e24845815805e615d608ca8392f9c97bf
MD5 e733ce9b44697ba63c87fca4e7771596
BLAKE2b-256 a4c7e747a3695494b6296bf7e40fcc1db86d17b5f84e8b1df2b2b8ed38e96dea

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.12-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.12-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 cb54ec8eb8bf46609058dc42586ef5916f5058f1b8b65ab0c5ab60a97f3f28ee
MD5 ce247f521e9879b8138a1dc09aa08921
BLAKE2b-256 ce710ad004ea35fccda93788eac8a1ab9db3235ccc8c15d167fa19b1035305b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.12-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 525bc4153c4d1560589d5351ee5b8bc1ce4ee7796aab086e0e8a6a10e29cddc9
MD5 89ce66ab1872f2c2cecedabb723076f5
BLAKE2b-256 f24caafb1887f2e1d589d1402c57de6005143dd61a9b204966db3945e0c77800

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.12-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 081c873cbe836acf4dfcd834bcbf84c6b88a6a3065aba6e6088f5fc4724f6031
MD5 d51daeeb411950beff8d63caf9bd3934
BLAKE2b-256 90e8f027705ee45f348f6b2e1722e6dbe00027bd203876c37408a42040c711cf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.12-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 2390cee2350e6d9dfba84b05fdbb9ad9d133538d606af815abf00f1074ff455a
MD5 aca46ce6403b262598e169bba4220ce5
BLAKE2b-256 ba7debf0c0ec92ef5cc2023649d65df3e4c1c4170a31648bb5e14b4d62370691

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.12-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.12-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 b4da6c708431ebc6cb170d0616d14d603da51c8c3b981e791ed8dd36831b4841
MD5 6399121927f6ad9b7a29e290056a8977
BLAKE2b-256 ab9fa34155e9c071f59f28aa03b1d0ebef645947db9a8deb84a0af80f8584996

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.12-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 7c29686a72729885c66cce5c701c1bdbcbf6e42a49390b06cdbc2cca62170402
MD5 1b3a87b10f74109a54494145447cc802
BLAKE2b-256 5ab8d0b7668958b6124bb5f83b2f847c89e2c51e8ee98aec74bdeface9d4c379

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.12-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 eb465ec8ed14e41048e28aa2cf15fbd5f2eb48f4132918d3c73254be66ed144e
MD5 2f6c60aba1569a2129382a305f808411
BLAKE2b-256 718ee6526d83683a4210da3a7164b68256117d449d7a9dc814f8667f348911c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.12-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 c9e1d4d51d67f98c55be497d51afa408559a722f1538dd01c7e17f4787a57195
MD5 d0f350ebf0d68dfed6c0d0e90ff4d480
BLAKE2b-256 23e92c5aa2ff7ed9f46b160bda960232dcdc9ea2c18a411d4b00119500176d2e

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.12-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.12-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 11e10361ac171e4418b62e9b4cf006716e173812b361e9ce8104bcb9ab2bec20
MD5 908fb8da95e8011a2be3277b7de64096
BLAKE2b-256 ff5666b7da60c3e56d6db54d6993f70a04b6ff461599ca12d3532488c72963b9

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.12-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 c3f88590f0d1fe6c2b8b8a128bd34c62b2fba37e81b6e81ff042a71fe26def98
MD5 6c412b3058f2970730f8de85537b293c
BLAKE2b-256 20fea6857447a249405d3181d82cf1d0ef53f7bb752d0b72416c7e92491f7114

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.12-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 fcf44e1619dd52526bd5871078fa55d0565e7514cf8bc7a3b56b487509a3da8e
MD5 9f7e9f69a37f2916278f45677aebf3bf
BLAKE2b-256 409072bebbcea236931110d7d1c74aa4830eec83bdc6bdef3f82cce8f3c0300f

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.1.12-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 bef039a82d612720098d052f2b87567f432142963cb966f6e0e384f7ba5f0ac8
MD5 58b7c8daf58cbf780aef31beedcf635f
BLAKE2b-256 83123ce3e85a72747de11bf9537a57c9b3fc23d8b7e1827ec257e0b200acdeaa

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.1.12-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.12-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 b0f3275a4f099fb962e5370b9763f590bb6c0608bd62f59ac56e801d301e3f6d
MD5 b6e7fd43b87f4f5ded3067f5ee86c4bc
BLAKE2b-256 a96bc3901ebb8b09cb2a3d42f176a7ca214786741be72f42a9ee6e830b83d654

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