Professional Python SDK for the BriteCore API — complete endpoint coverage, async support, OAuth/API key auth, and type hints.
Project description
britecore_sdk
Last updated: July 21, 2026 Document type: Living guide
A professional Python SDK for the BriteCore API — complete endpoint coverage, async support, OAuth/API key authentication, and type hints.
No existing BriteCore client library? Look no further. This SDK provides spec-aligned wrappers, domain models, validators, and clean async helpers.
Status: Stable (v2.0.4+) | License: Apache-2.0 | Python: 3.11+
Quick Start
1. Install
pip install britecore_sdk
2. Configure
Set target_site and credentials via config files or environment variables. The SDK discovers
config files automatically from several locations. For the canonical precedence table, see
docs/CONFIGURATION.md.
Recommended for most users: user-level config (~/.britecore/)
Works across all your projects without touching the SDK package files:
~/.britecore/settings.toml:
[default]
target_site = "production"
~/.britecore/.secrets.toml:
[production]
base_url = "https://your-britecore-instance.com"
api_key = "your_api_key_here"
Alternative: project-local config (current working directory)
Place britecore.toml and .britecore_secrets.toml in your project root. Add
.britecore_secrets.toml to .gitignore to keep secrets out of version control:
# britecore.toml (safe to commit)
[default]
target_site = "production"
# .britecore_secrets.toml (add to .gitignore!)
[production]
base_url = "https://your-britecore-instance.com"
api_key = "your_api_key_here"
Alternative: Environment variables
Note:
target_siteis required in standard file/env initialization. In explicit mode (init_api_client(base_url=..., ...)),target_siteis optional and defaults to"explicit". If all required credentials are set viaBRITECORE_SDK_*environment variables, those values always win;target_siteonly matters if the client needs to fall back to TOML sections.
Linux/macOS (bash):
export BRITECORE_SDK_BASE_URL="https://your-britecore-instance.com"
export BRITECORE_SDK_API_KEY="your_api_key_here"
export target_site="production" # selects .secrets.toml section; any name works when all creds are set via env vars
Windows (PowerShell):
$env:BRITECORE_SDK_BASE_URL="https://your-britecore-instance.com"
$env:BRITECORE_SDK_API_KEY="your_api_key_here"
$env:target_site="production" # selects .secrets.toml section; any name works when all creds are set via env vars
Or for OAuth:
Linux/macOS (bash):
export BRITECORE_SDK_BASE_URL="https://your-britecore-instance.com"
export BRITECORE_SDK_CLIENT_ID="your_client_id"
export BRITECORE_SDK_CLIENT_SECRET="your_client_secret"
export target_site="production" # selects .secrets.toml section; any name works when all creds are set via env vars
Windows (PowerShell):
$env:BRITECORE_SDK_BASE_URL="https://your-britecore-instance.com"
$env:BRITECORE_SDK_CLIENT_ID="your_client_id"
$env:BRITECORE_SDK_CLIENT_SECRET="your_client_secret"
$env:target_site="production" # selects .secrets.toml section; any name works when all creds are set via env vars
3. Use
from britecore_sdk.api.api_calls import get_api_client
from britecore_sdk.api.api_calls.v2 import policies
# Recommended: Use the lazy-initialized client (auto-loads config on first use)
client = get_api_client()
# Retrieve a policy
result = policies.retrieve_policy(policy_number="POL001")
print(result)
See examples/basic_api_usage.py for more detailed examples.
About API Client Initialization
The api_client proxy (from api.api_calls) initializes lazily on first use, avoiding import-time failures if config is missing. Use get_api_client() for explicit control over the shared lazy client. Use init_api_client() for advanced/manual initialization scenarios (for example explicit credentials or multi-site binding).
If you need to verify selected auth mode during initialization, enable SDK debug logging before client init. The client emits Auth mode selected during init_client: api_key or Auth mode selected during init_client: oauth at debug level.
Pattern A (app-owned logging, preferred for host apps):
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger("britecore_sdk").setLevel(logging.DEBUG)
Pattern B (SDK-managed handler, opt-in):
import logging
from britecore_sdk import configure_logging
configure_logging(level="INFO")
logging.getLogger("britecore_sdk").setLevel(logging.DEBUG)
You can also log directly through the package logger:
from britecore_sdk import logger
logger.info("SDK logger is configured")
Features
- ✅ Spec-aligned API coverage — wrapper/spec alignment checks against
api_specs/current/britecore.json - ✅ Async-ready — Cache-aware async wrappers for high-concurrency workflows
- ✅ Flexible auth — Automatic API key or OAuth2 token management
- ✅ Type hints — Full PEP 561 type information for IDE support
- ✅ Validators — Email, phone, address, and name validation utilities
- ✅ Models — Domain classes for Contact, Policy, and Quote payloads
- ✅ Config-first — Dynaconf-based environment and secrets management
- ✅ Production-ready — Stable API, comprehensive tests, security-focused
- ✅ Context manager —
with BritecoreAPIClient("site").init_client() as client: - ✅ Flat exceptions —
from britecore_sdk import NotFoundError, AuthenticationError - ✅ CLI commands —
britecore-healthcheck,britecore-check-config,britecore-run-checks - ✅ Debug dry-run — per-call
dry_run=Trueor client defaultinit_api_client(client_dry_run=True) - ✅ Rate limiting — Optional token bucket with adaptive backoff on 429 responses
- ✅ Batch operations — workflow helpers for parallel quote/contact/policy/risk creation
Documentation
| Topic | Link |
|---|---|
| Setup & examples | GETTING_STARTED.md |
| API reference | API.md |
| Async & caching | docs/ASYNC_CACHING.md |
| Rate limiting | docs/RATE_LIMITING.md |
| Batch operations | docs/BATCH_QUOTE_CREATION.md |
| Architecture | ARCHITECTURE.md |
| Python compatibility | PYTHON_COMPATIBILITY.md |
| Contributing | CONTRIBUTING.md |
| Code of Conduct | CODE_OF_CONDUCT.md |
| Troubleshooting | TROUBLESHOOTING.md |
| Security policy | SECURITY.md |
Installation & Configuration
Requirements
- Python
>=3.11
Install
# Base install (API client + wrappers)
pip install britecore_sdk
# With optional extras
pip install britecore_sdk[all] # All extras
pip install britecore_sdk[dev] # Development (tests, linting, type checking)
Configuration
The SDK loads settings from multiple locations in priority order — later sources override earlier ones.
BRITECORE_SDK_* environment variables always win over any file. See the canonical precedence
table in docs/CONFIGURATION.md.
Option A: User-level config (recommended for pip-installed users)
Create ~/.britecore/settings.toml and ~/.britecore/.secrets.toml. Settings here apply to all
projects on the machine without touching SDK package files:
~/.britecore/settings.toml (example):
[default]
target_site = "production"
~/.britecore/.secrets.toml (never commit):
API key authentication
[production]
base_url = "https://api.britecore.example.com"
api_key = "your_real_api_key"
[staging]
base_url = "https://api-staging.britecore.example.com"
api_key = "your_staging_api_key"
OAuth authentication
[production]
base_url = "https://api.britecore.example.com"
client_id = "your_real_client_id"
client_secret = "your_real_client_secret"
[staging]
base_url = "https://api-staging.britecore.example.com"
client_id = "your_staging_client_id"
client_secret = "your_staging_client_secret"
Option B: Project-local config
Place britecore.toml and .britecore_secrets.toml in your project's working directory.
Add .britecore_secrets.toml to .gitignore to keep secrets out of version control:
britecore.toml (safe to commit):
[default]
target_site = "production"
.britecore_secrets.toml (add to .gitignore!):
[production]
base_url = "https://api.britecore.example.com"
api_key = "your_real_api_key"
Option C: SDK package defaults (repo clones only)
If you have cloned the repo and are working directly from source, you can copy the sample files:
Linux/macOS (bash):
cp src/britecore_sdk/settings/sample/settings.toml src/britecore_sdk/settings/settings.toml
cp src/britecore_sdk/settings/sample/.secrets.toml src/britecore_sdk/settings/.secrets.toml
Windows (PowerShell):
Copy-Item src\britecore_sdk\settings\sample\settings.toml src\britecore_sdk\settings\settings.toml
Copy-Item src\britecore_sdk\settings\sample\.secrets.toml src\britecore_sdk\settings\.secrets.toml
Option D: Environment variables (highest priority, overrides all files)
Note on
target_sitewith env vars: In standard init mode,target_siteselects which section of.secrets.tomlto use for credentials. When all required credentials are supplied viaBRITECORE_SDK_*environment variables, the specifictarget_sitevalue does not affect which credentials are loaded — env vars take precedence regardless. If any credential is missing from env vars, the client falls back to the.secrets.tomlsection matchingtarget_site. Either way,target_siteis required unless you use explicit mode (init_api_client(base_url=..., ...)).
API key authentication:
Linux/macOS (bash):
export BRITECORE_SDK_BASE_URL="https://api.britecore.example.com"
export BRITECORE_SDK_API_KEY="your_api_key"
export target_site="production" # required; selects .secrets.toml section (any name works when all creds are in env vars)
Windows (PowerShell):
$env:BRITECORE_SDK_BASE_URL="https://api.britecore.example.com"
$env:BRITECORE_SDK_API_KEY="your_api_key"
$env:target_site="production" # required; selects .secrets.toml section (any name works when all creds are in env vars)
Or OAuth authentication:
Linux/macOS (bash):
export BRITECORE_SDK_BASE_URL="https://api.britecore.example.com"
export BRITECORE_SDK_CLIENT_ID="your_client_id"
export BRITECORE_SDK_CLIENT_SECRET="your_client_secret"
export target_site="production" # required; selects .secrets.toml section (any name works when all creds are in env vars)
Windows (PowerShell):
$env:BRITECORE_SDK_BASE_URL="https://api.britecore.example.com"
$env:BRITECORE_SDK_CLIENT_ID="your_client_id"
$env:BRITECORE_SDK_CLIENT_SECRET="your_client_secret"
$env:target_site="production" # required; selects .secrets.toml section (any name works when all creds are in env vars)
See GETTING_STARTED.md and docs/CONFIGURATION.md for detailed setup.
Validate configured sites before first API calls:
# As an installed command (after pip install) — works in bash and PowerShell:
britecore-check-config
# Or via python -m:
python -m britecore_sdk.utils.check_site_configs
Check whether the checked-in local API spec is current and whether upstream has a newer version:
python -m britecore_sdk.utils.check_api_spec_sync
Run an end-user readiness check (config + auth + safe API ping):
# As an installed command:
britecore-healthcheck --site production
# Or via python -m:
python -m britecore_sdk.utils.healthcheck --site production
Validation rule: each site needs base_url and either a full OAuth pair
(client_id + client_secret) or an api_key.
What This Package Provides
API Wrappers
- Endpoint modules: broad v2 domain coverage plus v1 compatibility wrappers (see
API.mdfor current module inventory) - Async wrappers: Cache-aware async versions of key endpoint workflows
Utilities
- Models:
BritecoreContact,BritecorePolicy,BritecoreQuotewith type hints - Validators: Email, phone, address, and name validation
- Auth: Automatic OAuth2 or API key selection based on config
- Config: Dynaconf-based environment/secrets management
- Logging: Structured logging with standard Python logging module
Optional Extras
- Interactive: Menu-driven CLI utilities (
questionary)
Using Async Wrappers
The v2 package exports async-aware wrappers (e.g., aget_quote, aget_contact, aretrieve_policy) with built-in caching for read operations.
import asyncio
from britecore_sdk.api.api_calls.v2 import async_policies
async def main():
policy = await async_policies.aretrieve_policy(policy_number="POL001")
print(policy)
asyncio.run(main())
See docs/ASYNC_CACHING.md for cache configuration and invalidation.
Development
Install for Development
pip install -e ".[dev]"
Run Tests
# All tests
pytest tests/ -v
# By category
pytest tests/unit -m unit -v
pytest tests/integration -m integration -v
# Core client changes
pytest tests/unit/test_api_client.py tests/unit/test_core_client_coverage.py -v
Linting & Type Checking
ruff check src/
black --check src/
mypy src/britecore_sdk/api/britecore_api_client.py
Release Publishing (GitHub Actions)
- TestPyPI dry-run workflow:
.github/workflows/publish-testpypi.yml(manual trigger only viaworkflow_dispatch) - Production PyPI workflow:
.github/workflows/publish.yml(automatic after.github/workflows/release.ymlcompletes successfully, and also manually runnable viaworkflow_dispatch)
Both workflows use OIDC trusted publishing and include build + publish + install smoke tests. Depending on your GitHub environment protection rules, the publish job may still pause for environment approval even when the workflow itself was triggered automatically.
- Create GitHub environments:
testpypiandpypi. - In TestPyPI, add a Trusted Publisher entry for:
- Repository:
sshimek42/britecore_sdk - Workflow:
.github/workflows/publish-testpypi.yml - Environment:
testpypi
- Repository:
- In PyPI, add a Trusted Publisher entry for:
- Repository:
sshimek42/britecore_sdk - Workflow:
.github/workflows/publish.yml - Environment:
pypi
- Repository:
- Run
Publish to TestPyPIfrom the Actions tab before cutting a production release. - Push a version tag (for example
v2.0.3) to trigger.github/workflows/release.yml, which builds artifacts and creates the GitHub Release automatically. - After
.github/workflows/release.ymlcompletes successfully,.github/workflows/publish.ymlruns automatically and publishes to PyPI. You can also runPublish to PyPImanually from the Actions tab when needed.
Contributing
See CONTRIBUTING.md for:
- Workflow and branch conventions
- Endpoint wrapper patterns
- Code quality expectations
- Repository-specific guidance in AGENTS.md
Architecture
BritecoreAPIClient— Core HTTP transport and response processing- Context manager —
with client:pattern closes the connection pool on exit - Fluent init —
client = BritecoreAPIClient("site").init_client()(one-liner) - Endpoint modules — Build request JSON → call
do_request()→ returnprocess_result() - Auth modes — Automatic: API key (when
client_id/client_secretblank) or OAuth2 (when both provided) - Config — Dynaconf-based layered config: SDK defaults →
~/.britecore/→./britecore.toml→BRITECORE_SDK_SETTINGS_FILE→ env vars - Lazy initialization — API client initializes on first use to avoid import-time failures (see "About API Client Initialization" above)
- Flat exceptions — Import
NotFoundError,AuthenticationErroretc. directly frombritecore_sdk
See ARCHITECTURE.md for detailed design.
Support & Links
- Issues & feedback: GitHub Issues
- Security concerns: See SECURITY.md
- Roadmap & stability: See STABILITY.md
- External API docs: api.britecore.com (supplemental reference)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file britecore_sdk-2.0.5.tar.gz.
File metadata
- Download URL: britecore_sdk-2.0.5.tar.gz
- Upload date:
- Size: 1.1 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
71a23b6a5d5fa0770bcc2991f4f7d88f295b9d8801ab345711b11be9409adefb
|
|
| MD5 |
6fb0cd9939fc1d2347387bcdda11cbcc
|
|
| BLAKE2b-256 |
1013ffd263e3ac9b7c9134da7f6d28495b210cbeec8bbb59db5ca6a015628363
|
Provenance
The following attestation bundles were made for britecore_sdk-2.0.5.tar.gz:
Publisher:
publish.yml on sshimek42/britecore_sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
britecore_sdk-2.0.5.tar.gz -
Subject digest:
71a23b6a5d5fa0770bcc2991f4f7d88f295b9d8801ab345711b11be9409adefb - Sigstore transparency entry: 2213214413
- Sigstore integration time:
-
Permalink:
sshimek42/britecore_sdk@b75371645ecf6eacedc39dbc200b50c02c7e3da5 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/sshimek42
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b75371645ecf6eacedc39dbc200b50c02c7e3da5 -
Trigger Event:
workflow_run
-
Statement type:
File details
Details for the file britecore_sdk-2.0.5-py3-none-any.whl.
File metadata
- Download URL: britecore_sdk-2.0.5-py3-none-any.whl
- Upload date:
- Size: 1.2 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
361d74f777a8fb639a2e14f12f0d6fb52f210fea13c29bf68790edaf9befb36e
|
|
| MD5 |
45998dc68ce8eacf1cde8967fe9a6225
|
|
| BLAKE2b-256 |
b5456b83df15d9f49e5396be3088bdd997d42712086d1e582fddbac1612e1156
|
Provenance
The following attestation bundles were made for britecore_sdk-2.0.5-py3-none-any.whl:
Publisher:
publish.yml on sshimek42/britecore_sdk
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
britecore_sdk-2.0.5-py3-none-any.whl -
Subject digest:
361d74f777a8fb639a2e14f12f0d6fb52f210fea13c29bf68790edaf9befb36e - Sigstore transparency entry: 2213214508
- Sigstore integration time:
-
Permalink:
sshimek42/britecore_sdk@b75371645ecf6eacedc39dbc200b50c02c7e3da5 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/sshimek42
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b75371645ecf6eacedc39dbc200b50c02c7e3da5 -
Trigger Event:
workflow_run
-
Statement type: