Skip to content

Feat/pyo3 bindings#26

Merged
mmacedoeu merged 14 commits intonextfrom
feat/pyo3-bindings
Mar 12, 2026
Merged

Feat/pyo3 bindings#26
mmacedoeu merged 14 commits intonextfrom
feat/pyo3-bindings

Conversation

@mmacedoeu
Copy link
Contributor

Pull Request Checklist

  • All CI checks pass (green ✓)
  • Lint checks pass (no formatting issues)
  • Security scan passes
  • Tests added/updated for new functionality
  • Documentation updated (if applicable)
  • Commit messages follow Conventional Commits

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update
  • Refactoring (no functional changes)
  • AI-generated work (agent/* branch)

Branch Strategy

This PR follows the CipherOcto branch strategy:

From Branch To Branch Purpose
feat/* next New features
agent/* next AI-generated code
research/* next Experimental work
hotfix/* main Emergency fixes
next main Integration release

Current PR: <!-- source branch --><!-- target branch -->


Description


Related Issues

Closes #(issue)


Testing

  • Unit tests pass
  • Integration tests pass
  • Manual testing performed

Performance Impact

  • No performance impact
  • Performance improved (describe)
  • Performance degraded (describe, justify)

Security Considerations

  • No security implications
  • Security changes (describe)

Additional Notes

Add mission to align Rust CLI/library exports with Python SDK signatures:
- completion/acompletion functions
- embedding/aembedding functions
- Router struct with routing strategies
- LiteLLM-compatible exceptions
- OpenAI-compatible proxy endpoints
- LiteLLM-style CLI commands
Add detailed implementation design for RFC-0908 Python SDK:
- Updated RFC with separate crate structure (quota-router-pyo3, quota-router-core)
- Updated Mission 0908-a dependencies
- Created design document with implementation steps
Prepare for isolated worktree development.
Create quota-router-core crate (extracted from CLI):
- Move balance.rs, providers.rs, config.rs, proxy.rs
- CLI now depends on core library

Create quota-router-pyo3 crate:
- PyO3 bindings for Python SDK
- LiteLLM-compatible exceptions (AuthenticationError, RateLimitError, etc.)
- Types: Message, ChatCompletion, Choice, Usage, Embedding
- completion() and embedding() functions
- Drop-in replacement for LiteLLM

Build and test verified:
- cargo build --all
- cargo clippy --all-targets -- -D warnings
- cargo test --all
Tried adding async support but pyo3-asyncio 0.20 has API differences:
- async fn not directly supported as pyfunction
- try_init_runtime not available in this version

Keeping sync versions for now. Async (acompletion, aembedding)
can be added when:
- Python 3.11+ is minimum
- pyo3-asyncio has stable async fn support
- Or use manual Future polling approach

All tests pass.
- Add pyproject.toml for maturin build system
- Add .venv/ and .python-version to .gitignore
- Verified with Python 3.12.9

Python SDK now pip-installable and working:
- import quota_router works
- completion() returns LiteLLM-compatible response
- embedding() works
- Exception classes available
Using pyo3 0.21 with experimental-async feature:
- Add acompletion() async function
- Add aembedding() async function
- Verified working with Python 3.12

All sync and async functions working:
- completion()
- acompletion()
- embedding()
- aembedding()
- Add python/ directory with quota_router package
- Add type stubs (__init__.pyi) for IDE support
- Update root pyproject.toml for maturin
- Add python/pyproject.toml for pip installability

Python package now pip-installable:
- import quota_router
- import quota_router as litellm (LiteLLM alias)
- completion(), acompletion(), embedding(), aembedding()
- Exception classes
- docs/quota-router-python-sdk.md - Full SDK documentation
  - Installation instructions
  - Quick start examples
  - API reference
  - LiteLLM compatibility
  - Development setup
  - Publishing guide

- tests/smoke_test.py - Smoke tests
  - Import test
  - completion() test
  - acompletion() test
  - embedding() test
  - aembedding() test
  - Exceptions test
  - LiteLLM alias test

- .github/workflows/quota-router-python.yml - CI workflow
  - Build and test
  - Type checking
  - Wheel building
Mark completed missions:
- 0908-a: All criteria completed (PyO3, async, type stubs)
- 0908-c: Embedding functions completed

Mark partial progress:
- 0908-d: pyproject.toml, package, CI done
- 0908-e: Core extracted, functions via PyO3 done
Add #![allow(deprecated)] to suppress pyo3 deprecation warnings
for PyDict::new and PyList::new which will be replaced
in future versions.

Also run cargo fmt to fix formatting.
@mmacedoeu mmacedoeu merged commit ca15b3b into next Mar 12, 2026
21 of 39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant