Skip to main content

Build LLM workflows like normal Python while keeping a full audit trail by default.

Project description

Republic

Release Build status codecov Commit activity License

Build LLM workflows like normal Python while keeping a full audit trail by default.

Visit https://getrepublic.org for concepts, guides, and API reference.

Republic is a tape-first LLM client: messages, tool calls, tool results, errors, and usage are all recorded as structured data. You can make the workflow explicit first, then decide where intelligence should be added.

Quick Start

pip install republic
from __future__ import annotations

import os

from republic import LLM

api_key = os.getenv("LLM_API_KEY")
if not api_key:
    raise RuntimeError("Set LLM_API_KEY before running this example.")

llm = LLM(model="openrouter:openrouter/free", api_key=api_key)
result = llm.chat("Describe Republic in one sentence.", max_tokens=48)
print(result)

Why It Feels Natural

  • Plain Python: The main flow is regular functions and branches, no extra DSL.
  • Structured error handling: Errors are explicit and typed, so retry and fallback logic stays deterministic.
  • Tools without magic: Supports both automatic and manual tool execution with clear debugging and auditing.
  • Tape-first memory: Use anchor/handoff to bound context windows and replay full evidence.
  • Event streaming: Subscribe to text deltas, tool calls, tool results, usage, and final state.

Provider Auth Resolver

Republic can resolve provider keys dynamically via api_key_resolver.

from republic import LLM, login_openai_codex_oauth, openai_codex_oauth_resolver

# First-time login (paste redirect URL when prompted by your app/CLI wrapper).
# You can wire `prompt_for_redirect` to your own input UI.
login_openai_codex_oauth(
    prompt_for_redirect=lambda authorize_url: input(f"Open this URL and paste callback URL:\n{authorize_url}\n> "),
)

llm = LLM(
    model="openai:gpt-5.3-codex",
    api_key_resolver=openai_codex_oauth_resolver(),
)
print(llm.chat("Say hello in one sentence."))

openai_codex_oauth_resolver() reads ~/.codex/auth.json (or $CODEX_HOME/auth.json) and returns the current access token for openai, refreshing it automatically when it is near expiry. If you omit prompt_for_redirect, login will try to capture the callback from redirect_uri automatically.

Development

make check
make test

See CONTRIBUTING.md for local setup, testing, and release guidance.

License

Apache 2.0


This project is derived from lightning-ai/litai and inspired by pydantic/pydantic-ai; we hope you like them too.

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

republic-0.5.4.tar.gz (132.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

republic-0.5.4-py3-none-any.whl (57.9 kB view details)

Uploaded Python 3

File details

Details for the file republic-0.5.4.tar.gz.

File metadata

  • Download URL: republic-0.5.4.tar.gz
  • Upload date:
  • Size: 132.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for republic-0.5.4.tar.gz
Algorithm Hash digest
SHA256 1a1870d75933d7c05d7abee09172c3b3c7473a5c65a52aaf25c161d034f440d9
MD5 1661648788aef5c909bf2627b5972f1b
BLAKE2b-256 af4cf0d776d498f4ed6e92c2e26f6bd99e5b4395961cdbc567668e6cf67e96f5

See more details on using hashes here.

File details

Details for the file republic-0.5.4-py3-none-any.whl.

File metadata

  • Download URL: republic-0.5.4-py3-none-any.whl
  • Upload date:
  • Size: 57.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.21 {"installer":{"name":"uv","version":"0.9.21","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for republic-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 04699f629dd023e411ffd0143c558f8ba695c8831c705eff647f81e8c5a8f38a
MD5 5071c871510e6930140f335e1343d167
BLAKE2b-256 e6d1e54222cb7916a6844df6edd5f054d143fb0c9cf2c0b0b4973d7f241c3ace

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