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

Uploaded CPython 3.13Windows x86-64

genai_pyo3-0.5.0-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.5.0-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.5.0-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.1 MB view details)

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

genai_pyo3-0.5.0-cp312-cp312-win_amd64.whl (4.0 MB view details)

Uploaded CPython 3.12Windows x86-64

genai_pyo3-0.5.0-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.5.0-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.5.0-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.1 MB view details)

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

genai_pyo3-0.5.0-cp311-cp311-win_amd64.whl (4.0 MB view details)

Uploaded CPython 3.11Windows x86-64

genai_pyo3-0.5.0-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.5.0-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.5.0-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.1 MB view details)

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

genai_pyo3-0.5.0-cp310-cp310-win_amd64.whl (4.0 MB view details)

Uploaded CPython 3.10Windows x86-64

genai_pyo3-0.5.0-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.5.0-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.5.0-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.1 MB view details)

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

genai_pyo3-0.5.0-cp39-cp39-win_amd64.whl (4.0 MB view details)

Uploaded CPython 3.9Windows x86-64

genai_pyo3-0.5.0-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.5.0-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.5.0-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl (9.1 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.5.0.tar.gz.

File metadata

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

File hashes

Hashes for genai_pyo3-0.5.0.tar.gz
Algorithm Hash digest
SHA256 016d3f13f1b9f29ac74101afeccef7bbe72f6757f03ef77446b0b591e9dcb237
MD5 8565801a268a949497f4586011b5776c
BLAKE2b-256 999b1c24c3508333becc3608a0eab0d694b553a7b8afb7d124ea1bbe2287b99a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.0-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 97df1be5fa8fe9ccd9a384ac39a8c355fa6420c2a01fa3869f850ee7e0aef43f
MD5 4cd963a056217599714c543606193217
BLAKE2b-256 b39eed3d75e170b2bf969454693492b2d5ec0dcd01954a5adbaa1899e21ecdf2

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.0-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f0e677538d1a0f3c807aff820520d51524ae5d16b3ac1306570c5df88d36c3d9
MD5 d233ad7cb8b6b9786648705ea31913fe
BLAKE2b-256 0a3e19ec05cf7d2c757b6bba198f0d426c1af01dcb57931ff9891c1725dd7217

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 e4656265af7fd94e52c10e30495488170b920842a102494e1928c55d18ade61b
MD5 0466bbf5c4714eb9248e79518092ea67
BLAKE2b-256 ad0e51660fa56c08810d68a094b050236d4e33bef6e4d1665e510c992b89672c

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.5.0-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.5.0-cp313-cp313-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 f5e45391fe567e47950ef399584ab1db9a524ac6e98b6bbddb0370ad5a1897a2
MD5 d992174a3181fa0ba95fdbe0a979b5fc
BLAKE2b-256 3075e6e2648e2d7fd14de2ebc651290f71fdcf4c10323c26daafe106a9b598a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.0-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 3ca7092ab1c583cb0dc153b536ba7ae00a7972b52ea0a24e909764fb426d5478
MD5 ba4955e3a357114f938ba93329c27528
BLAKE2b-256 c4ac2c973618b55a82fb36227b038af61496f23b1a4c9b543bf91bc2e7e06343

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.0-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 f67025157a6c42c3022d85574d1faf5bb57ae4a7494ca6fe339e73f08d227899
MD5 e82558033cad2c01bd99287d9a0fe9fe
BLAKE2b-256 6dc2d08708ab1309c7f53512d62b41b5c84c65a76f59594a32aa1dd9183968ff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 50683370e4bf440cf62840f1f327f7c00cff61a2808e7ff2b86630e7bf1ec60f
MD5 d5ac58801fe6a6ba1c096037bc7cc56e
BLAKE2b-256 810f8c8be66f276900ce1fb47426b3184b96c81f3f60344a1cc94ecdc323f5a8

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.5.0-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.5.0-cp312-cp312-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 529526a34351da2d4dcaa9f43ffd7ebcef37e6bb42292b568a0cf21e2bc2baf5
MD5 c3594f665c3df0254b6b39b6e2af4396
BLAKE2b-256 be1ec244c17a50b8140b083bfb81a05cdc445cf83d94eb71ec1981f660dfa5d6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 bf90090f8b639914b9eec68bd4e54f98460618671d243fbaa18a40f668b4a9cf
MD5 6b0fde2bdda290c85ff48ac0770c95ff
BLAKE2b-256 2a7e5c2340bea40021e3d37158e85a825b10446b7f29791e4807d5d641620c13

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.0-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 27787188f1f5c478b9aed59096fc4167a77fdae5d36e3141dd6a34a487fb9989
MD5 02ace4a3ec4a2c35d8dc490d75c2e80b
BLAKE2b-256 361341c9ebaf336e1eac04cd753264658503130e96a37fd40c09dd7429683c35

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 4b3f39803f1151800334cf19cce6e05bc9c74675885cc4e715a687ff2f4b8c23
MD5 4bf81160f8f959a520c86fb3e3c91c27
BLAKE2b-256 cbead0c5f15bbe24554c9e2a467f0aa0e4d6fa7733bb62af391b723dc40fbdbf

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.5.0-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.5.0-cp311-cp311-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 c26dd484d5e82d556229c978f8138da97f1bf8da3cd4a22004d4903d9bbb290f
MD5 83970916b6abfafb890c68d511b2f574
BLAKE2b-256 3caae5e5f8dbd88c3805458affa3ca58329fa126098e08f0e4c3a2a7f2f21287

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 61254984a5b15804f1d9d28fa4cf2e33e6c6b8209a0a0e9b19fcb9c200b16539
MD5 086d6774f0473cbd72a1efdce638bf39
BLAKE2b-256 ea29587fa5299b45460788ad637bafb230e267b883ef00964797b43a9a50468c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.0-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 5b310589e2e43c7f94204f9c9148d7ad71014afd517331c51e3208fe5a932ee5
MD5 3df020b0d7d2b305c39d83c90d407fd9
BLAKE2b-256 bd075c12937d5e76ebe35d1736835077a43957a171a66a69df32f363780d20e5

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 38e8de2003248d497fe5f34a3abb3924a6433b62eaee027d0131546953b0281f
MD5 b7c858281ccdcca7be16a54bdf96df7d
BLAKE2b-256 839cdc08302934c6a01940416d36ae98cf7734c33775f152645b373de7a59c46

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.5.0-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.5.0-cp310-cp310-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 8e4a7411e46d935cac85519648b2aee2cf0deb15c78f06aab13278415efeea16
MD5 dd9ef9b08d6ac8ed5043d5f3cd62a467
BLAKE2b-256 58b0e6090dbedf54a33a66be35a0ddaecec1b526b96d20d3eadd272790228d7e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 fe03129a690a35342dbde014e1311efa6881e978435ff3c78d8400b9df0adab8
MD5 f5c73197cba80aab29b7ba36fbf36853
BLAKE2b-256 f83d80f9a34f70571853c4ec4b8d3cea8b9d022801b7c4fcb4bc08370ab6e487

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.0-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a4ee81d5ea3da0c4fdbded14f30bf99b9af7bee29fc03f603941e439956beb2b
MD5 4717f4e1ae2123041fb7b05ac97d5c90
BLAKE2b-256 70ac937e8b8477876776de626130d1b78ce1e193c74fab198cf39ed3395cfc74

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for genai_pyo3-0.5.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 83b90559e5a4bdfe74f51264690de6faa50ba4d19c7e7e9c12303c95d8312799
MD5 edfccac18b78d605f6c51a7e39d07d4b
BLAKE2b-256 b8176e868cd65b4fb35b1912af86c2b3e8a1ad582b4244f29af82494ad49429d

See more details on using hashes here.

File details

Details for the file genai_pyo3-0.5.0-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.5.0-cp39-cp39-macosx_10_12_x86_64.macosx_11_0_arm64.macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 70f25ba420f6f511c1cf4ba2b8745594240fba38222b89c203280a6c8143d88e
MD5 34f09d728a44ef47456d46ca70a42d79
BLAKE2b-256 dd05f7058bc3c8168da626edcfbf96934f59471253661d1320ec4f48893111e8

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