Skip to main content

statute-utils

GitHub CI

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 sources count 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

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.

Release files for statute-utils 2.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 statute-utils 2.0
File Size Uploaded
statute_utils-2.0.tar.gz 48.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for statute-utils 2.0
File Interpreter ABI Platform
statute_utils-2.0-py3-none-any.whl Python 3 none any Details

Total release size: 110.2 kB

Release files / statute_utils-2.0.tar.gz

Download URL statute_utils-2.0.tar.gz
Size 48.3 kB
Tags Source
SHA-256 checksum
How to use checksums
25a39b5821d468eea520e3468d8c000e01b68901ce9e094b5635cb1d3ca0366e
BLAKE2b-256 checksum
How to use checksums
e9e3df96f48d9ed464366bfc31eedaeed59333cf69a6d3a37bfe67cfcc857e93
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release files / statute_utils-2.0-py3-none-any.whl

Download URL statute_utils-2.0-py3-none-any.whl
Size 62.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
42b75a96139b17ca7aaedae3ae13a1c32db461149d93b3a756748371d94f2583
BLAKE2b-256 checksum
How to use checksums
ecb1ab3282e28ef053658ea5c1dbb9459c1993a61b2e3817d6c7e80fcdb9ed4b
Upload date
Uploaded using Trusted Publishing?
What is 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}

Release history Release notifications | RSS feed

This release

2.0 This release

2 release files

1.0.0

2 release files

0.10.1

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.8.6

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