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.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

statute_utils-2.0.tar.gz (48.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

statute_utils-2.0-py3-none-any.whl (62.0 kB view details)

Uploaded Python 3

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

Hashes for statute_utils-2.0.tar.gz
Algorithm Hash digest
SHA256 25a39b5821d468eea520e3468d8c000e01b68901ce9e094b5635cb1d3ca0366e
MD5 edd6f57753dd5cedb4e1bcadc456c44b
BLAKE2b-256 e9e3df96f48d9ed464366bfc31eedaeed59333cf69a6d3a37bfe67cfcc857e93

See more details on using hashes here.

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

Hashes for statute_utils-2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 42b75a96139b17ca7aaedae3ae13a1c32db461149d93b3a756748371d94f2583
MD5 7e56be3d7f0153d01344d5eec1952e1a
BLAKE2b-256 ecb1ab3282e28ef053658ea5c1dbb9459c1993a61b2e3817d6c7e80fcdb9ed4b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page