Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions .github/workflows/quota-router-python.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
name: Quota Router Python SDK

on:
push:
branches: [main, next, feat/*]
pull_request:
paths:
- 'crates/quota-router-pyo3/**'
- 'python/**'

jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ['3.12']

steps:
- uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}

- name: Install Rust
uses: dtolnay/rust-action@stable

- name: Install dependencies
run: |
pip install maturin pytest

- name: Build and install
run: |
maturin develop --manifest-path crates/quota-router-pyo3/Cargo.toml

- name: Run smoke tests
run: python tests/smoke_test.py

- name: Run pytest
run: pytest

type-check:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install mypy
run: pip install mypy

- name: Install dependencies
run: |
pip install maturin
maturin develop --manifest-path crates/quota-router-pyo3/Cargo.toml

- name: Type check
run: mypy python/quota_router

build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install Rust
uses: dtolnay/rust-action@stable

- name: Install maturin
run: pip install maturin

- name: Build wheel
run: maturin build --manifest-path crates/quota-router-pyo3/Cargo.toml
env:
MATURIN_PYTHON_TAGS: true

- name: Upload wheel
uses: actions/upload-artifact@v4
with:
name: wheels
path: target/wheels/*.whl
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,12 @@ Thumbs.db
*.log
.gitnexus
Cargo.lock

# Worktrees
.worktrees/

# Python
.venv/
.python-version
**/__pycache__/
*.egg-info/
3 changes: 3 additions & 0 deletions crates/quota-router-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ authors.workspace = true
license.workspace = true

[dependencies]
# Core library
quota-router-core = { path = "../quota-router-core" }

# CLI
clap.workspace = true

Expand Down
8 changes: 4 additions & 4 deletions crates/quota-router-cli/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Quota Router CLI - Library
pub mod balance;
// Re-exports from quota-router-core

pub use quota_router_core::{balance, config, providers, proxy};

pub mod cli;
pub mod commands;
pub mod config;
pub mod providers;
pub mod proxy;
40 changes: 40 additions & 0 deletions crates/quota-router-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
[package]
name = "quota-router-core"
version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true

[dependencies]
# Async
tokio.workspace = true
async-trait.workspace = true

# HTTP/HTTP server
hyper.workspace = true
hyper-util.workspace = true
http-body-util.workspace = true
rustls.workspace = true
rustls-pemfile.workspace = true
reqwest.workspace = true

# Config
directories.workspace = true
serde.workspace = true
serde_json.workspace = true

# Utilities
uuid.workspace = true
parking_lot.workspace = true

# Logging
tracing.workspace = true
tracing-subscriber.workspace = true

# Errors
anyhow.workspace = true
thiserror.workspace = true

[lib]
name = "quota_router_core"
path = "src/lib.rs"
7 changes: 7 additions & 0 deletions crates/quota-router-core/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// quota-router-core - Core library for quota-router
// Contains business logic shared between CLI and PyO3 bindings

pub mod balance;
pub mod config;
pub mod providers;
pub mod proxy;
29 changes: 29 additions & 0 deletions crates/quota-router-pyo3/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
[package]
name = "quota-router-pyo3"
version.workspace = true
edition.workspace = true
authors.workspace = true
license.workspace = true

[lib]
crate-type = ["cdylib", "rlib"]

[dependencies]
# PyO3 for Python bindings - using 0.21 with experimental async
pyo3 = { version = "0.21", features = ["extension-module", "experimental-async"] }

# Core library
quota-router-core = { path = "../quota-router-core" }

# Serialization
serde.workspace = true
serde_json.workspace = true

# UUID generation
uuid.workspace = true

# Error handling
thiserror.workspace = true

[build-dependencies]
pyo3-build-config = "0.21"
10 changes: 10 additions & 0 deletions crates/quota-router-pyo3/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
use pyo3_build_config::use_pyo3_cfgs;

fn main() {
// Set linkage to static for musl
if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "linux" {
println!("cargo:rustc-link-libc=m");
}

use_pyo3_cfgs();
}
Loading
Loading