Metadata-Version: 2.3
Name: statute-utils
Version: 1.0.0
Summary: Toolkit for Philippine rules.
Requires-Dist: prelawsql>=1.0.0
Requires-Dist: beautifulsoup4>=4.15
Requires-Dist: click>=8.4
Requires-Dist: jinja2>=3.1.6
Requires-Dist: lxml>=6.1
Requires-Dist: markdown>=3.10
Requires-Dist: markdownify>=1.2.3
Requires-Dist: markupsafe>=3.0
Requires-Dist: python-dateutil>=2.9.0.post0
Requires-Dist: pyyaml>=6.0.3
Requires-Dist: rich>=15.0
Requires-Dist: sqlite-utils>=4.1
Requires-Python: >=3.14
Description-Content-Type: text/markdown

# statute-utils

![GitHub CI](https://github.com/justmars/statute-utils/actions/workflows/ci.yml/badge.svg)

`statute-utils` recognizes Philippine statutory citations, resolves them to
canonical corpus records, builds searchable SQLite artifacts from legal YAML
trees, and renders those trees as reusable HTML.

Python 3.14 or newer is required.

```sh
uv add statute-utils
```

## Extract a citation

Use `extract_rules()` when a category and serial number are enough. Use
`extract_rule_matches()` with a statute catalog when a database relationship
needs an unambiguous corpus ID.

```py
from statute_utils import StatuteCatalog, extract_rule_matches, extract_rules

rules = list(extract_rules("Republic Act Nos. 386 and 7160"))

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"
```

Catalogs are immutable in-memory snapshots. Candidate lookup performs no later
SQLite reads, and each snapshot exposes a logical fingerprint that identifies
the statute metadata used for resolution.

## Build the SQLite artifact

The canonical build stages and validates all package-owned tables and views
before atomically replacing the target. A failed build leaves the previous
database untouched. Higher-level artifact builders can call
`statute_utils.rebuild.build_trees_into()` when they already own the staging
connection and publication boundary.

```sh
builder rebuild-trees \
  --db-name data/main.db \
  --statutes-folder ../corpus-statutes \
  --codifications-folder ../corpus-codifications
```

The configured Just wrapper accepts the same options:

```sh
just build-trees --db-name data/main.db
```

## Documentation

- [Overview](https://lawsql.com/)
- [Release notes](https://lawsql.com/releases/)
- [Extract citations](https://lawsql.com/extract/)
- [Use catalog snapshots](https://lawsql.com/catalog/)
- [Fetch statutes](https://lawsql.com/fetch/)
- [Build SQLite artifacts](https://lawsql.com/build/)
- [Render legal trees](https://lawsql.com/template/)
- [Python API](https://lawsql.com/api/)

For repository work, run `just check` to execute the tests, strict documentation
build, and package build.
