Skip to content
Musher Docs

Authentication

Both the Python and TypeScript SDKs discover credentials automatically. This guide covers the credential resolution chain, how to override it, and how to configure the SDK for different environments.

Credential Resolution Order

The SDK checks four sources in order and uses the first credential found:

  1. Programmatic — pass a token directly via configure() or the client constructor (takes precedence over all other sources)
  2. MUSHER_API_KEY environment variable — the simplest option for CI pipelines and local development
  3. OS keyring (musher/<host>) — automatically set when you run musher auth login via the CLI
  4. Credential file (~/.local/share/musher/credentials/<host>/api-key) — file-based fallback for environments without a keyring

Environment Variable

Set the MUSHER_API_KEY environment variable before running your application:

bash
export MUSHER_API_KEY="mush_..."

This is the recommended approach for CI pipelines and server deployments.

Programmatic Configuration

Override credential discovery entirely by passing a token directly. This takes precedence over all other sources.

python
import musher

# Global configuration — affects all subsequent calls
musher.configure(token="mush_...")

# Or per-client
from musher import Client

with Client(config=musher.MusherConfig(token="mush_...")) as client:
    bundle = client.pull("acme/code-review-kit")

SDK Configuration Options

Beyond authentication, you can configure the base URL, caching, timeouts, and verification behavior.

python
import musher

musher.configure(
    token="mush_...",              # API token
    registry_url="https://...",     # Custom registry (default: https://api.musher.dev)
    verify_checksums=True,          # SHA-256 verification on pull (default: True)
    timeout=30.0,                   # HTTP timeout in seconds (default: 30.0)
    max_retries=2,                  # Retry count for transient failures (default: 2)
)

Python configuration fields

FieldTypeDefaultDescription
tokenstr | NoneAuto-discoveredAPI token (overrides credential discovery)
registry_urlstrhttps://api.musher.devRegistry base URL
verify_checksumsboolTrueVerify SHA-256 checksums during pull
timeoutfloat30.0HTTP timeout in seconds
max_retriesint2Retry count for transient failures
cache_dirPathPlatform defaultLocal cache directory for pulled bundles

TypeScript configuration fields

FieldTypeDefaultDescription
apiKeystringAuto-discoveredAPI token (overrides credential discovery)
baseUrlstring"https://api.musher.dev"Registry base URL
cacheDirstringPlatform defaultLocal cache directory for pulled bundles
manifestTtlSecondsnumber86400Manifest cache TTL in seconds (24 hours)
timeoutnumber60000HTTP timeout in milliseconds
retriesnumber3Retry count for transient failures

Inspect Active Configuration

python
import musher

config = musher.get_config()
print(f"Registry: {config.registry_url}")
print(f"Cache: {config.cache_dir}")
print(f"Verify: {config.verify_checksums}")