statute-utils
statute-utils recognizes Philippine statutory citations, resolves them
against an explicit statute catalog, builds searchable SQLite artifacts from
curated legal trees, and renders those trees as reusable HTML.
Version 2.0 requires Python 3.14 or newer and publishes inline type information.
uv add statute-utils
Start with extraction
The package-root API is intentionally small. extract_rules() returns the
shared prelawsql.Rule model when category and serial are enough:
from statute_utils import extract_rules
rules = list(extract_rules("Republic Act Nos. 386 and 7160"))
assert [(rule.cat.value, rule.num) for rule in rules] == [
("ra", "386"),
("ra", "7160"),
]
Use an explicit, read-only catalog snapshot when a database relationship needs canonical corpus identity:
from statute_utils import StatuteCatalog, extract_rule_matches
catalog = StatuteCatalog.open("data/main.db")
match = next(extract_rule_matches("1987 Constitution", catalog=catalog))
assert match.statute_id == "const-1987-1987-02-02-1"
Catalog construction reads SQLite once. Candidate lookup performs no later database reads, and an existing snapshot does not silently change when its artifact path is atomically replaced.
Build the SQLite artifact
The canonical command rebuilds package-owned tables and views in a sibling staging database, validates that database, and publishes it with an atomic file replacement:
builder rebuild-trees \
--db-name data/main.db \
--statutes-folder ../corpus-statutes \
--codifications-folder ../corpus-codifications
Use the root progress option before the command when CI needs stable records:
builder --progress plain rebuild-trees \
--db-name data/main.db \
--statutes-folder ../corpus-statutes \
--codifications-folder ../corpus-codifications
Warning: the builder does not require source directories to exist or require the glob to select at least one file. For CLI rebuilds, verify the reported
sourcescount before accepting an artifact; embedded callers should also validate the returned receipt. A zero-source rebuild can publish an empty package-owned surface.
Higher-level artifact producers that already own the connection, transaction,
validation, and publication boundary can use
statute_utils.rebuild.build_trees_into().
Documentation
- Documentation overview
- Getting started
- Extract and resolve citations
- Build and publish artifacts
- Python API and errors
- Upgrade to 2.0
For repository work, just check runs formatting and lint checks, Pyright and
package type verification, documentation source/build/site checks, strict
Marimo checks, the coverage-gated test suite, and a source-independent package
build.
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 statute_utils-2.0.tar.gz.
File metadata
- Download URL: statute_utils-2.0.tar.gz
- Upload date:
- Size: 48.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25a39b5821d468eea520e3468d8c000e01b68901ce9e094b5635cb1d3ca0366e
|
|
| MD5 |
edd6f57753dd5cedb4e1bcadc456c44b
|
|
| BLAKE2b-256 |
e9e3df96f48d9ed464366bfc31eedaeed59333cf69a6d3a37bfe67cfcc857e93
|
File details
Details for the file statute_utils-2.0-py3-none-any.whl.
File metadata
- Download URL: statute_utils-2.0-py3-none-any.whl
- Upload date:
- Size: 62.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
42b75a96139b17ca7aaedae3ae13a1c32db461149d93b3a756748371d94f2583
|
|
| MD5 |
7e56be3d7f0153d01344d5eec1952e1a
|
|
| BLAKE2b-256 |
ecb1ab3282e28ef053658ea5c1dbb9459c1993a61b2e3817d6c7e80fcdb9ed4b
|