Skip to main content

regcite

[!IMPORTANT] This package is still in development and is not production ready.

Static analysis for UK financial regulatory citations in Python code.

regcite lets you annotate Python functions with citations to UK financial regulation — CRR, the PRA Rulebook, PRA Policy Statements, PRA Supervisory Statements — and then check those citations against a bundled, versioned snapshot of the rulebook. The intent is to make the mapping from compliance code to the regulation it implements executable: runs in CI, lives next to the code, and breaks the build when it drifts.

Why this exists

Regulatory engineering teams in UK banks need an auditable trail from every formula in their RWA / capital code back to a specific article of the CRR or rule in the PRA Rulebook. Today that trail is produced by hand in Word documents that drift the moment anyone changes the code. regcite puts the mapping where the code is, checks it on every commit, and gives reviewers, auditors, and the PRA something verifiable to look at instead of a stale spreadsheet.

The first real user is OpenAfterHours/rwa_calculator — a UK CRR / Basel 3.1 credit-risk RWA library whose formulas need to trace back to specific articles. If you're building something similar, regcite is for you.

Install

uv add regcite
# or
pip install regcite

Python 3.11+.

Quickstart

Decorate a function with the regulation it implements:

from regcite import cites


@cites("CRR Art. 153(1)(a)")
def corporate_rw(pd: float, lgd: float, maturity: float) -> float:
    """Risk-weight under the IRB approach for corporates."""
    ...

Add a [tool.regcite] table to your pyproject.toml:

[tool.regcite]
rulebook_version = "2024-07-09"
instruments = ["CRR", "PRA_RULEBOOK", "PS", "SS"]
source_paths = ["src"]

Run the checker:

$ uv run regcite check
regcite: checked 47 citation(s); no issues found.

If a citation fails to parse or points at something the bundled index doesn't know about, regcite check exits non-zero and prints a line per finding with file, line number, and reason — suitable for CI:

src/myproj/sa.py:31: sovereign_rw: unknown_article: citation 'CRR Art. 999' points to CRR Article 999, which is not in the bundled rulebook index
regcite: 1 failing finding(s), 0 unresolved, out of 12 resolved citation(s).

@cites is a no-op at runtime — it attaches the parsed citation to the function as __regcite__ and returns the function unchanged. No wrapping, no overhead, nothing to debug.

Citation grammar

The parser accepts canonical UK regulatory citation strings. The shape that comes out the other side is a frozen Citation dataclass; see regcite.Citation for the field list.

Input Meaning
CRR Art. 153 Whole article
CRR Article 153 (alternate spelling)
CRR Art. 153(1) Paragraph
CRR Art. 153(1)(a) Point
CRR Art. 153(1)(a)(ii) Sub-point
CRR Art. 4(1)(75) Numeric point (CRR definitions)
PRA Rulebook, Credit Risk, 3.2 Rulebook section
PS9/24 PRA Policy Statement, whole document
SS1/23, paragraph 2.5 Supervisory Statement with paragraph reference
Delegated Regulation 2018/171 Art. 3 UK on-shored EU Delegated Regulation

The keyword for an article accepts Art, Art., Article, or article in any case. Whitespace is normalised. Anything that doesn't parse is a CitationParseError, which regcite check reports with the offending input — these are code-review events, not silent skips.

Configuration reference

[tool.regcite]
# Snapshot of the rulebook to pin to. Decorators that omit `version=`
# inherit this pin. ISO-8601 date.
rulebook_version = "2024-07-09"

# Citation instruments allowed in this project. A citation whose
# instrument is not in this list is reported by `regcite check`.
instruments = ["CRR", "PRA_RULEBOOK", "PS", "SS", "DELEGATED_REG"]

# Directories to walk when running `regcite check` with no arguments.
source_paths = ["src"]

Public API

from regcite import (
    Citation,            # frozen dataclass: instrument, article, paragraph, ...
    parse_citation,      # str -> Citation, raises CitationParseError
    CitationParseError,
    cites,               # the @cites decorator
)

Everything else (regcite.ast_walker, regcite.index, regcite.checks, regcite.cli) is internal and may change between releases.

Roadmap

regcite v0.1 is intentionally a narrow vertical slice: get the citation grammar right against real usage in rwa_calculator, ship the decorator and CLI, then expand.

Version Adds
v0.1 Citation grammar, @cites, regcite check, bundled CRR index
v0.2 regcite matrix (traceability matrix), regcite stale (rulebook diff)
v0.3+ Automated scraping of legislation.gov.uk + the PRA Rulebook

If you have feedback on the citation grammar specifically, please open an issue — the grammar is the foundation, and getting it wrong now is much cheaper to fix than getting it wrong later.

Licence

Apache 2.0. See LICENSE.

Release files for regcite 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for regcite 0.1.0
File Size Uploaded
regcite-0.1.0.tar.gz 87.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for regcite 0.1.0
File Interpreter ABI Platform
regcite-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 115.3 kB

Release files / regcite-0.1.0.tar.gz

Download URL regcite-0.1.0.tar.gz
Size 87.1 kB
Tags Source
SHA-256 checksum
How to use checksums
2d9d9d8414c958ed69ab0565cd0db0d692ec09419ee70a7082c3741368e89cf4
BLAKE2b-256 checksum
How to use checksums
e10e9b965dab334e7426c585daa63bc6be4604aa40535a6b8a11c4be5f5fa048
Upload date
Uploaded using Trusted Publishing?
What is 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":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / regcite-0.1.0-py3-none-any.whl

Download URL regcite-0.1.0-py3-none-any.whl
Size 28.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
76ad564db62a20b2cf1d522843a3e8b89131494cc08eedb108b17b472a1f7ca6
BLAKE2b-256 checksum
How to use checksums
6ace0c1563d9ab55d33d374647cec0586d13b680e05433477f7b7ed61e0bbdac
Upload date
Uploaded using Trusted Publishing?
What is 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":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page