diff --git a/packaging/litellm-gateway/pyproject.toml b/packaging/litellm-gateway/pyproject.toml new file mode 100644 index 00000000000..f84a11178cf --- /dev/null +++ b/packaging/litellm-gateway/pyproject.toml @@ -0,0 +1,16 @@ +[project] +name = "litellm-gateway" +version = "1.109.0" +description = "Opt-in Rust HTTP forwarding server for the LiteLLM Python proxy" +requires-python = ">=3.10, <3.16" +license = "MIT" + +[build-system] +requires = ["maturin==1.15.0"] +build-backend = "maturin" + +[tool.maturin] +manifest-path = "../../litellm-rust/crates/gateway/Cargo.toml" +bindings = "bin" +targets = [{ name = "litellm-gateway", kind = "bin" }] +profile = "release" diff --git a/pyproject.toml b/pyproject.toml index 5c23a64ebb3..9189e121905 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -55,6 +55,7 @@ Documentation = "https://docs.litellm.ai" # supply-chain-pinned to a vetted, aged release. [project.optional-dependencies] proxy = [ + "litellm-gateway==1.109.0", "gunicorn>=23.0.0,<24.0", "uvicorn>=0.33.0,<1.0", "granian>=2.7.4,<3.0; python_version < '3.15'", @@ -387,11 +388,12 @@ brotli = "2026-10-22T14:01:00Z" pypdf = "2026-10-28T17:01:00Z" [tool.uv.sources] +litellm-gateway = { workspace = true } litellm-proxy-extras = { workspace = true } litellm-enterprise = { workspace = true } [tool.uv.workspace] -members = ["enterprise", "litellm-proxy-extras"] +members = ["enterprise", "litellm-proxy-extras", "packaging/litellm-gateway"] [tool.commitizen] version = "1.109.0" diff --git a/scripts/build_core_distribution.py b/scripts/build_core_distribution.py index 41d7208d2c3..ee50422f6db 100644 --- a/scripts/build_core_distribution.py +++ b/scripts/build_core_distribution.py @@ -1,4 +1,4 @@ -"""Build the independent core distribution from shared repository sources.""" +"""Build standalone core or gateway distributions from shared repository sources.""" import argparse import shutil @@ -20,7 +20,13 @@ SOURCES: Final = ( ) -def stage_core_distribution(source: Path, destination: Path) -> None: +class BuildOptions(argparse.Namespace): + package: str + out_dir: Path + sdist_only: bool + + +def stage_core_distribution(source: Path, destination: Path, *, package: str = "litellm-core") -> None: version: Final = subprocess.run( ["uv", "version", "--short"], cwd=source, check=True, capture_output=True, text=True ).stdout.strip() @@ -53,8 +59,7 @@ def stage_core_distribution(source: Path, destination: Path) -> None: )(directory, names) destination.mkdir(parents=True, exist_ok=True) - for name in SOURCES: - path: Final = source / name + for name, path in ((name, source / name) for name in SOURCES if package == "litellm-core" or name != "litellm"): if path.is_dir(): shutil.copytree( path, @@ -63,15 +68,27 @@ def stage_core_distribution(source: Path, destination: Path) -> None: ) else: shutil.copy2(path, destination / name) - shutil.copy2(source / "packaging/litellm-core/pyproject.toml", destination / "pyproject.toml") + template: Final = (source / "packaging" / package / "pyproject.toml").read_text() + metadata: Final = ( + template.replace("../../litellm-rust/", "litellm-rust/") + + "\ninclude = [\n" + + ",\n".join( + f' {{ path = "{name}", format = "sdist" }}' + for name in ("rust-toolchain.toml", ".cargo/config.toml", "model_prices_and_context_window.json") + ) + + "\n]\n" + if package == "litellm-gateway" + else template + ) + (destination / "pyproject.toml").write_text(metadata) subprocess.run(["uv", "version", version, "--frozen"], cwd=destination, check=True) -def build_core_distribution(output: Path, *, sdist_only: bool = False) -> None: +def build_core_distribution(output: Path, *, sdist_only: bool = False, package: str = "litellm-core") -> None: output_path: Final = output.resolve() with tempfile.TemporaryDirectory(prefix="litellm-core-") as temporary: stage: Final = Path(temporary) - stage_core_distribution(ROOT, stage) + stage_core_distribution(ROOT, stage, package=package) subprocess.run( ["uv", "build", "--python", sys.executable, "--out-dir", str(output_path)] + (["--sdist"] if sdist_only else []), @@ -82,12 +99,13 @@ def build_core_distribution(output: Path, *, sdist_only: bool = False) -> None: def main() -> None: parser: Final = argparse.ArgumentParser(description=__doc__) + parser.add_argument("--package", choices=("litellm-core", "litellm-gateway"), default="litellm-core") parser.add_argument("--out-dir", type=Path, default=ROOT / "dist/core") parser.add_argument( "--sdist-only", action="store_true", help="Build only the source archive, without compiling a wheel" ) - args: Final = parser.parse_args() - build_core_distribution(Path(args.out_dir), sdist_only=args.sdist_only) + args: Final = parser.parse_args(namespace=BuildOptions()) + build_core_distribution(Path(args.out_dir), sdist_only=args.sdist_only, package=args.package) if __name__ == "__main__": diff --git a/tests/base_sdk_tests/test_core_distribution.py b/tests/base_sdk_tests/test_core_distribution.py index c22fa4e54fc..ce7f3d2bf15 100644 --- a/tests/base_sdk_tests/test_core_distribution.py +++ b/tests/base_sdk_tests/test_core_distribution.py @@ -53,7 +53,10 @@ def source_repository(tmp_path: Path) -> Path: return source -def test_staging_stamps_release_version_without_modifying_sources(tmp_path: Path, source_repository: Path) -> None: +@pytest.mark.parametrize("package", ["litellm-core", "litellm-gateway"]) +def test_staging_stamps_release_version_without_modifying_sources( + tmp_path: Path, source_repository: Path, package: str +) -> None: from scripts.build_core_distribution import SOURCES, stage_core_distribution source: Final = source_repository @@ -61,16 +64,17 @@ def test_staging_stamps_release_version_without_modifying_sources(tmp_path: Path path: Final = source / name path.write_text(f"shared {name}") (source / "pyproject.toml").write_text('[project]\nname = "litellm"\nversion = "9.8.7rc1"\n') - manifest: Final = source / "packaging/litellm-core/pyproject.toml" + manifest: Final = source / "packaging" / package / "pyproject.toml" manifest.parent.mkdir(parents=True) - manifest.write_bytes((ROOT / "packaging/litellm-core/pyproject.toml").read_bytes()) + manifest.write_bytes((ROOT / "packaging" / package / "pyproject.toml").read_bytes()) original: Final = manifest.read_bytes() stage: Final = tmp_path / "stage" - stage_core_distribution(source, stage) + stage_core_distribution(source, stage, package=package) assert tomllib.loads((stage / "pyproject.toml").read_text())["project"]["version"] == "9.8.7rc1" assert manifest.read_bytes() == original assert (source / "pyproject.toml").read_text() == '[project]\nname = "litellm"\nversion = "9.8.7rc1"\n' - assert all((stage / name).read_bytes() == (source / name).read_bytes() for name in SOURCES) + expected: Final = tuple(name for name in SOURCES if package == "litellm-core" or name != "litellm") + assert all((stage / name).read_bytes() == (source / name).read_bytes() for name in expected) @pytest.fixture(scope="module") @@ -99,7 +103,9 @@ def test_core_wheel_metadata_and_resources(distributions: tuple[Path, Path]) -> assert metadata["Version"] == tomllib.loads((ROOT / "pyproject.toml").read_text())["project"]["version"] assert not metadata.get_all("Provides-Extra") assert not any(n.endswith(".dist-info/entry_points.txt") for n in names) - requirements: Final = tomllib.loads((ROOT / "packaging/litellm-core/pyproject.toml").read_text())["project"]["dependencies"] + requirements: Final = tomllib.loads((ROOT / "packaging/litellm-core/pyproject.toml").read_text())["project"][ + "dependencies" + ] for python_version in ("3.10", "3.11", "3.12", "3.13", "3.14"): environment: Final = {"python_version": python_version, "python_full_version": python_version + ".0"} assert { diff --git a/uv.lock b/uv.lock index 19d3a1ffd4f..e51db9aed63 100644 --- a/uv.lock +++ b/uv.lock @@ -22,6 +22,7 @@ pypdf = "2026-10-28T17:01:00Z" members = [ "litellm", "litellm-enterprise", + "litellm-gateway", "litellm-proxy-extras", ] constraints = [ @@ -5040,6 +5041,7 @@ proxy = [ { name = "httpx2" }, { name = "inquirerpy" }, { name = "litellm-enterprise" }, + { name = "litellm-gateway" }, { name = "litellm-proxy-extras" }, { name = "mcp" }, { name = "orjson" }, @@ -5271,6 +5273,7 @@ requires-dist = [ { name = "keyring", marker = "extra == 'cli'", specifier = ">=25.6.0,<26.0" }, { name = "langfuse", marker = "extra == 'proxy-runtime'", specifier = ">=4.7,<5.0" }, { name = "litellm-enterprise", marker = "extra == 'proxy'", editable = "enterprise" }, + { name = "litellm-gateway", marker = "extra == 'proxy'", editable = "packaging/litellm-gateway" }, { name = "litellm-proxy-extras", marker = "extra == 'proxy'", editable = "litellm-proxy-extras" }, { name = "llm-sandbox", marker = "extra == 'proxy-runtime'", specifier = ">=0.3.39,<1.0" }, { name = "mangum", marker = "extra == 'proxy-runtime'", specifier = ">=0.17.0,<1.0" }, @@ -5471,6 +5474,11 @@ name = "litellm-enterprise" version = "0.1.81" source = { editable = "enterprise" } +[[package]] +name = "litellm-gateway" +version = "1.109.0" +source = { editable = "packaging/litellm-gateway" } + [[package]] name = "litellm-proxy-extras" version = "0.4.112"