UK Companies SDK
A modern Python SDK for accessing the UK Companies House API.
Features
- Async-first: Built with modern async/await patterns for optimal performance
- Type-safe: Full type hints and Pydantic models for data validation
- Developer-friendly: Intuitive API with comprehensive documentation
- Lightweight: Minimal dependencies, fast installation
- Well-tested: Extensive test coverage with unit and integration tests
- Automatic Retry: Smart retry logic with exponential backoff for rate-limited requests
- Rate Limit Aware: Intelligent handling of API rate limits with configurable retry strategies
- Production Ready: Published on PyPI, thoroughly tested with live API
Installation
# Install from PyPI
pip install ukcompanies
# Or with uv
uv add ukcompanies
Quick Start
import asyncio
from ukcompanies import AsyncClient
async def main():
# Initialize the client with your API key
async with AsyncClient(api_key="your-api-key") as client:
# Search for companies
results = await client.search_companies("OpenAI")
for company in results.items:
print(f"{company.title} - {company.company_number}")
# Get detailed company information
company = await client.profile("12345678")
print(f"Company: {company.company_name}")
print(f"Status: {company.company_status}")
asyncio.run(main())
Configuration
API Key
You'll need an API key from Companies House. Get one by:
- Registering at Companies House Developer Hub
- Creating an application
- Getting your API key
Environment Variables
Create a .env file in your project root:
COMPANIES_HOUSE_API_KEY=your-api-key-here
Advanced Configuration
Retry Settings
The SDK automatically handles rate limits with intelligent retry logic. You can customize retry behavior:
from ukcompanies import AsyncClient
# Custom retry configuration
async with AsyncClient(
api_key="your-api-key",
auto_retry=True, # Enable automatic retry (default: True)
max_retries=5, # Maximum retry attempts (default: 3)
backoff="exponential", # Backoff strategy: "exponential" or "fixed" (default: "exponential")
base_delay=1.0, # Base delay in seconds (default: 1.0)
max_delay=60.0, # Maximum delay between retries (default: 60.0)
jitter_range=1.0, # Random jitter range (default: 1.0)
on_retry=my_callback # Optional callback for retry events
) as client:
# Use client here
pass
# Custom retry callback
async def my_retry_callback(attempt, delay, response):
print(f"Retry attempt {attempt} after {delay}s delay")
async with AsyncClient(
api_key="your-api-key",
on_retry=my_retry_callback
) as client:
# Use client here
pass
The SDK respects X-Ratelimit-Reset headers from the API for intelligent wait times and uses exponential backoff with jitter to prevent thundering herd problems.
Development
Setup
This project uses uv for dependency management:
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# Install dependencies
uv pip install -e ".[dev]"
Testing
# Run tests
pytest
# Run tests with coverage
pytest --cov=ukcompanies
# Run type checking
mypy src/ukcompanies
# Run linting
ruff check src/ tests/
# Format code
ruff format src/ tests/
Documentation
Documentation is built with MkDocs:
# Install documentation dependencies
uv pip install -e ".[docs]"
# Serve documentation locally
mkdocs serve
# Build documentation
mkdocs build
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Links
Metadata
Release files for ukcompanies 0.7.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ukcompanies-0.7.2.tar.gz | 1.4 MB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ukcompanies-0.7.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.5 MB
Release files / ukcompanies-0.7.2.tar.gz
| Download URL | ukcompanies-0.7.2.tar.gz |
|---|---|
| Size | 1.4 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bb7953d75fbae21f0187cd2b60a9060a954740c2570bf6d2d28264e99d940742
|
|
BLAKE2b-256 checksum How to use checksums |
f61fe0fe41f7751e2cce95d2f641cbb6d980308a4af1e144c96cbe192df34221
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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}
|
Release files / ukcompanies-0.7.2-py3-none-any.whl
| Download URL | ukcompanies-0.7.2-py3-none-any.whl |
|---|---|
| Size | 37.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4d3041c97a796c20f91bb5716bc06501fd7c0d49dbd27dbaf8be2e2767ca9070
|
|
BLAKE2b-256 checksum How to use checksums |
8331b86c3c8c38ca2e7b4f7c21ab6b8a0397be4c7270c532ccfba26a9548cde6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.28 {"installer":{"name":"uv","version":"0.11.28","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}
|