Metadata-Version: 2.4
Name: scjn
Version: 0.5.0
Summary: Client for the SCJN's SCOW JSON API and reader for the scjn-leyes release: a Mexican federal law's reform-dated snapshots.
License: Apache-2.0
Project-URL: Homepage, https://github.com/INGEOTEC/LegalIA/tree/main/packages/scjn
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Requires-Python: >=3.10
Description-Content-Type: text/markdown
Requires-Dist: requests>=2.31
Requires-Dist: platformdirs>=4.0
Provides-Extra: test
Requires-Dist: pytest>=7.0; extra == "test"

# scjn

Client for the SCJN's SCOW JSON API (`https://legislacion.scjn.gob.mx`) and
reader for the `scjn-leyes` GitHub release: a Mexican federal law's
reform-dated snapshots, each tagged with a `fuente: scjn` provenance header.
The SCJN is **not** an official source of legal text — the *Diario Oficial de
la Federación* (DOF), read through [`dofjson`](../dofjson), remains that;
this package's crawl is a convenience corpus SCJN's own consolidated view
makes possible, never a replacement for it.

This package was extracted out of a downstream package's own modules (issue
#206). Fase 1 (issue #207) moved the transport (`scjn.api`), the catalogue's
own algebra (`scjn.catalog`), per-instrument crawl state (`scjn.state`), and
the provenance header's reader (`scjn.header`) — no behaviour change, no
release-format change. Fase 3 (issue #209) moved the `scjn-leyes` release's
own readers here too (`scjn.release`: `download_scjn_leyes_corpus`,
`download_scjn_leyes_index`, `download_scjn_leyes_catalog`,
`iter_current_federal_laws`, `markdown_de_snapshot`,
`download_scjn_leyes_assets`, `local_slugs`), now in the package's own public
`scjn.__all__`, disk-first and with their own cache directory
(`scjn.cache`, `$SCJN_CACHE_DIR` — a separate lifecycle from the downstream
package's cache, migrated once automatically from wherever it used to live).
`codNota` linking — matching a snapshot to the DOF `codNota` that produced it
— stays one layer up: a `codNota` is a DOF concept, and this package's
dependency direction is one way (see `tests/test_boundary.py`).

Since issue #215 every law also carries the SCJN's own `materia` (subject
classification), `vigencia` (whether it is still in force — seven values, not
a boolean) and `resumen` (a one-paragraph abstract). They are per law, not
per reform, so they live in each law's own `estado.json` and in the release
index, and `download_scjn_leyes_catalog`/`iter_current_federal_laws` return
them with no extra request — which makes `scjn-leyes` a *classified* corpus.
`scripts/fetch_federal_law_metadata.py` is what fills them in, one SCJN
search per law, matched by `idOrdenamiento` so a wrong document can never be
described as the right one (issue #115, Hallazgo C).

    scjn download [--slug SLUG] [--cache-dir DIR] [--refrescar]

puts the release on disk; every reader in `scjn.release` then reads off it
with no network request at all, raising `scjn.release.AssetNotCached` for
whatever is not there yet.

## Changelog

- **0.5.0** — the fourth id-keyed collection, `scjn-tratados` (issue #277):
  every international treaty the SCJN serves (~1,456 instruments, members
  by the SCJN's *ámbito* `TRATADOS INTERNACIONALES`, any category).
  `download_scjn_tratados_index` / `_corpus` / `_assets`,
  `local_tratados_ids` and `iter_current_tratados` are the same thin
  wrappers over the generic core the reglamentos/lineamientos ones are
  (same `AssetNotCached`/`SinTextoEnSCJN` raise order), `scjn.cache.TRATADOS`
  joins `COLECCIONES_POR_ID`, `scjn download --coleccion tratados` fetches
  it, and `scjn.release.construye_indice_global_tratados` is its index
  builder. The release is a numbered series of tags (`scjn-tratados`,
  `scjn-tratados-2`, ...). `scjn.discovery` gains an `ambito` keyword
  (`discover`/`discover_by_category`, default `"FEDERAL"`, existing calls
  unchanged), a by-ámbito mode (`categoria=""`: no reform-category rescue
  and no coverage audit) and `report_outside_ambito`.

- **0.4.0** — `articulos_a_markdown` recovers table rows from a
  blank-line-separated block of an article's `contenido` that carries a tab
  (issue #253): the SCJN's plain text uses a run of tabs as its only column
  separator, and a wrapped multi-line cell used to come back as one
  Markdown paragraph per source line instead of one per row. A block with
  no tab is unaffected, byte for byte. Measured on the cached `scjn-leyes`
  release: 35 of 315 laws, 567 of 3,707 snapshots — a snapshot already on
  disk only picks up the fix via `scripts/fetch_scjn_legislacion.py
  --reintenta <slug>`, never automatically.

- **0.3.0** — `iter_current_reglamentos` / `iter_current_lineamientos`
  (issue #227, Fase 2): `iter_current_federal_laws`' id-keyed siblings, the
  *current* text of every instrument of either collection, one tarball open
  at a time. No `codNota` and no `abrev` (neither collection is DOF-linked),
  the newest snapshot chosen from the file names since an id-keyed tarball
  ships no `indice.json`, and an instrument the index lists with no
  consolidated text at all is skipped rather than raising `SinTextoEnSCJN`.

- **0.2.0** — the package's first release: the SCOW transport (`scjn.api`),
  the catalogue algebra, the crawl state, the provenance header and the
  disk-first readers of the `scjn-leyes`/`scjn-reglamentos`/
  `scjn-lineamientos` releases (issues #206-#212, #220, #222).

## Development

```bash
pip install -e "packages/scjn[test]"
pytest packages/scjn
```

## License

Apache License 2.0. See [LICENSE](../../LICENSE).
