Validate, format, and identify UK Companies House company numbers
Project description
uk-company-number
Validate, format, and identify UK Companies House company numbers in Python.
Built by BORSCH.AI — UK Business Intelligence Platform covering 5.9M companies with AI-powered risk scores and 50M+ government signals.
Also available as an npm package for Node.js/TypeScript.
Installation
pip install uk-company-number
Quick Start
from uk_company_number import validate, parse, format_number
# Validate
validate("12345678") # True
validate("SC123456") # True
validate("XXXX") # False
# Parse into structured info
info = parse("SC123456")
print(info.jurisdiction) # "scotland"
print(info.jurisdiction_name) # "Scotland"
print(info.type) # "ltd"
print(info.type_name) # "Private Limited Company"
# Format to canonical form
format_number("1234") # "00001234"
format_number("sc123456") # "SC123456"
API
parse(number: str) -> CompanyNumberInfo | None
Parse a company number into structured information. Returns None for invalid numbers.
info = parse("OC301234")
info.number # "OC301234"
info.prefix # "OC"
info.numeric_part # "301234"
info.jurisdiction # "england-wales"
info.jurisdiction_name # "England & Wales"
info.type # "llp"
info.type_name # "Limited Liability Partnership"
validate(number: str) -> bool
Check if a string is a valid UK company number format.
validate("12345678") # True
validate("SC123456") # True
validate("00000000") # False
validate("") # False
format_number(number: str) -> str | None
Format a company number to its canonical (zero-padded, uppercase) form.
format_number("1234") # "00001234"
format_number("sc123456") # "SC123456"
format_number("invalid") # None
get_jurisdiction(number: str) -> str | None
Get the jurisdiction for a company number.
get_jurisdiction("12345678") # "england-wales"
get_jurisdiction("SC123456") # "scotland"
get_jurisdiction("NI654321") # "northern-ireland"
get_type(number: str) -> str | None
Get the company type for a company number.
get_type("12345678") # "ltd"
get_type("OC301234") # "llp"
get_type("LP123456") # "lp"
get_prefix(number: str) -> str | None
Get the prefix from a company number.
get_prefix("SC123456") # "SC"
get_prefix("12345678") # ""
equals(a: str, b: str) -> bool
Check if two company numbers refer to the same company (handles different formatting).
equals("1234", "00001234") # True
equals("sc123456", "SC123456") # True
equals("1234", "5678") # False
prefixes() -> list[dict]
Get all known prefixes and their descriptions.
for p in prefixes():
print(f"{p['prefix']}: {p['type_name']} ({p['jurisdiction_name']})")
Supported Prefixes
| Prefix | Type | Jurisdiction |
|---|---|---|
| (none) | Private Limited Company | England & Wales |
| SC | Private Limited Company | Scotland |
| NI | Private Limited Company | Northern Ireland |
| OC | Limited Liability Partnership | England & Wales |
| SO | Limited Liability Partnership | Scotland |
| NC | Limited Liability Partnership | Northern Ireland |
| LP | Limited Partnership | England & Wales |
| SL | Limited Partnership | Scotland |
| FC | Overseas Company | United Kingdom |
| SE | Societas Europaea | United Kingdom |
| CE | Community Interest Company | England & Wales |
| OE | Overseas Entity | United Kingdom |
| ... | and 15 more |
Data Types
@dataclass
class CompanyNumberInfo:
number: str # Canonical form, e.g. "SC123456"
prefix: str # Prefix, e.g. "SC"
numeric_part: str # Digits only, e.g. "123456"
jurisdiction: str # e.g. "scotland"
jurisdiction_name: str # e.g. "Scotland"
type: str # e.g. "ltd"
type_name: str # e.g. "Private Limited Company"
Data Source
Based on the official Companies House company number format specification. Full company data available at borsch.ai.
License
MIT
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 uk_company_number-1.0.0.tar.gz.
File metadata
- Download URL: uk_company_number-1.0.0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
297a291f3e4a50397cb208984596e436686b53d9b4308e5521d83e81d20dfec1
|
|
| MD5 |
cc11a97488ccca984e1a88df03942fb3
|
|
| BLAKE2b-256 |
59483159980ddd0ec39f7afc1dc8bc5aef8a3d6cd7215a5386c6d95415149212
|
File details
Details for the file uk_company_number-1.0.0-py3-none-any.whl.
File metadata
- Download URL: uk_company_number-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1d6fd202db8c84193410acd6f5079bc235679adda160af98862111e503a7677e
|
|
| MD5 |
5f6234a02fdf7457789a62e974f1bc7f
|
|
| BLAKE2b-256 |
778528e6bc77e3da0322f8be7e077e257a5b8332ad2acf95f8a05006487e01f8
|