Skip to content
BEG-lagPublic

About

Mexican federal law as code: 36 federal laws as Markdown in git, with 375 historical versions recovered from archived copies. Every reform is a commit dated on its DOF publication.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

leyes-mx: Mexican federal law as code. Every reform, a commit.

English · Español

CI Daily update Code: MIT Data: public domain Python 3.12+

Animation built from this repo: git log --reverse of leyes/cpeum.md lists the Constitution's 44 versions from 2006 to 2026, then git show 8f63595 shows the DOF 03-03-2026 reform of article 123, section A, fraction IV: the forty-hour work week.

Real history from this repo, no mockups. MP4 version.

leyes-mx

Mexican federal law, as code. Every federal law is a clean Markdown file in git, and every reform published in the Diario Oficial de la Federación (DOF) is a commit dated on the day it was published. So git log tells you how a law changed, git diff shows exactly what a reform did, and git blame tells you which reform wrote each paragraph.

36 laws · 13,370 articles · 816 reform decrees catalogued · 375 versions in git across 27 laws with history back to 1993 · data as of DOF 07-10-2026

  • For lawyers: see exactly what a reform changed, link to a single article, and read a law as it stood on any date since its first archived version.
  • For developers: a clean, versioned corpus of Mexican federal law, with headings, front matter and reform metadata, ready for search, RAG or analysis.

Important

Unofficial. Only the Diario Oficial de la Federación is authoritative. Not legal advice.

See it

The Constitution, reform by reform (44 versions in git):

$ git log --date=short --format='%ad  %h  %s' -- leyes/cpeum.md
2026-10-07  6cd26a9  CPEUM: reforma DOF 07-10-2026
2026-06-02  3e9003b  CPEUM: reformas DOF 10-04-2026 a 02-06-2026
2026-03-03  8f63595  CPEUM: reforma DOF 03-03-2026
2025-10-15  edd95aa  CPEUM: reformas DOF 09-10-2025 a 15-10-2025
2025-04-15  93d32c6  CPEUM: reforma DOF 15-04-2025
2025-04-01  b18e57f  CPEUM: reformas DOF 17-03-2025 a 01-04-2025
2025-01-17  b237612  CPEUM: reformas DOF 20-12-2024 a 17-01-2025
2024-12-02  b5be146  CPEUM: 3 decretos de reforma, DOF 02-12-2024
...

What the reform of March 3, 2026 did to article 123, section A, fraction IV (git show 8f63595):

-IV. Por cada seis días de trabajo deberá disfrutar el operario de un día de descanso, cuando menos.
+IV. La jornada laboral será de cuarenta horas semanales en los términos que establezca la Ley.
+
+Por cada seis días de trabajo las personas trabajadoras deberán disfrutar por lo menos de un día de descanso con goce de salario íntegro.
+
+*Fracción reformada DOF 03-03-2026*

And which reform wrote that line:

$ git blame --date=short -L '/^IV. La jornada laboral/,+1' leyes/cpeum.md
8f635957 (Diario Oficial (leyes-mx) 2026-03-03) IV. La jornada laboral será de cuarenta horas semanales en los términos que establezca la Ley.

Quickstart

git clone https://github.com/BEG-lag/leyes-mx && cd leyes-mx

Browse. Each law is one file in leyes/. Every article is a heading, so it has a stable link, for example leyes/cpeum.md#artículo-27. Next to each law, leyes/<slug>.reformas.md lists every reform decree with its DOF date and a link to the decree.

Read the history of a law. One commit per version, dated with the DOF publication of the reform it reflects:

git log --date=short --format='%ad  %s' -- leyes/lft.md

Diff two versions. By date, at word level, with the bundled CLI or with plain git:

uv run leyes diff lft 2019-01-01 2026-06-30 --word      # what changed in between
uv run leyes diff cpeum 2024-01-01 --stat               # summary up to today
git diff "$(git rev-list -1 --before=2019-01-01 HEAD -- leyes/lft.md)" HEAD -- leyes/lft.md

Read the law as it stood on a date.

git show "$(git rev-list -1 --before=2012-01-01 HEAD -- leyes/cpeum.md)":leyes/cpeum.md | less

Find which reform wrote a paragraph.

git blame --date=short leyes/cpeum.md | grep -m1 'jornada'

Run the pipeline. Python 3.12+ and uv:

uv sync
uv run leyes build lft lse          # download from LeyesBiblio and convert (3 s between requests)
uv run leyes validate --strict      # front matter and article numbering of every law
uv run leyes update --full --commit # what the scheduled workflow runs
uv run leyes history import cpeum   # rebuild a law's history from archived versions
uv run leyes site                   # regenerate CHANGES.md, docs/ and the tables below
uv run pytest

How it works

flowchart LR
    I["LeyesBiblio index.htm<br/>(Cámara de Diputados)"] -->|"last-reform dates"| U{"changed?"}
    U -->|yes| D["consolidated .doc<br/>(Word 97 binary)"]
    W["Internet Archive<br/>captures of the same .doc files"] -->|"older versions"| D
    D --> P["doc.py<br/>piece table, fields, tables"]
    P --> S["parse.py<br/>Libro, Título, Capítulo, Sección,<br/>Artículo, transitorios, notes"]
    S --> M["leyes/slug.md<br/>Markdown + YAML front matter"]
    R["ref/slug.htm<br/>reform decrees"] --> T["leyes/slug.reformas.md<br/>data/reformas/slug.json"]
    M --> G[("git<br/>one commit per reform<br/>bot author, DOF date")]
    T --> G
    G --> O["git log · git diff · git blame<br/>CHANGES.md · docs/"]
Loading
  1. Sources. The Cámara de Diputados publishes the consolidated text of every federal law in force at LeyesBiblio, as PDF and as Word .doc, plus one page per law listing every reform decree. The pipeline uses the .doc: paragraphs and tables come out exactly as typed, without the line-wrapping and page-header noise of PDF extraction.
  2. Parsing Word 97 directly. doc.py reads the binary format itself (OLE container, File Information Block, piece table, paragraph properties), drops field codes, and keeps tables as rows of cells. No LibreOffice, no network service: the 1.9 MB .doc of the Constitution is read and structured in under 0.2 s on a laptop.
  3. Structure. parse.py recognizes the divisions each law actually uses and assigns heading levels accordingly; turns every article (1o., 3o. Bis, 15-A, 353-Ñ, 228 a, 199 Sextus...) into a heading; keeps the Cámara's editorial notes (Párrafo reformado DOF ...) in italics; and keeps the transitorios of the original text and of every reform decree.
  4. Validation. Repealed articles stay in the text (Se deroga.), so the body must number 1..N with no gaps and no repeats. leyes validate --strict checks that for every law, in CI.
  5. Commits. Law text is only ever committed by the bot (below), dated with the DOF publication date. A scheduled workflow checks the sources every day and commits new reforms the same way.

Laws included

Constitución

Law Abbr. Published (DOF) Last reform (DOF) Articles Reform decrees Versions in git
Constitución Política de los Estados Unidos Mexicanos CPEUM 05-02-1917 07-10-2026 136 285 44

Energía (reforma de 2025)

Law Abbr. Published (DOF) Last reform (DOF) Articles Reform decrees Versions in git
Ley del Sector Eléctrico LSE 18-03-2025 none 188 0 1
Ley del Sector Hidrocarburos LSH 18-03-2025 none 166 0 1
Ley de la Empresa Pública del Estado, Comisión Federal de Electricidad LEPECFE 18-03-2025 none 131 0 1
Ley de la Empresa Pública del Estado, Petróleos Mexicanos LEPEPM 18-03-2025 none 126 0 1
Ley de la Comisión Nacional de Energía LCNE 18-03-2025 26-12-2025 28 0 1
Ley de Planeación y Transición Energética LPTE 18-03-2025 none 100 0 1
Ley de Biocombustibles LBio 18-03-2025 none 46 0 1
Ley de Geotermia LGeo 18-03-2025 none 66 0 1
Ley de Ingresos sobre Hidrocarburos LIH 11-08-2014 28-12-2025 64 1 10
Ley de la Agencia Nacional de Seguridad Industrial y de Protección al Medio Ambiente del Sector Hidrocarburos LANSI 11-08-2014 11-05-2022 38 0 3

Minería, agua, tierra y ambiente

Law Abbr. Published (DOF) Last reform (DOF) Articles Reform decrees Versions in git
Ley de Minería LMin 26-06-1992 08-05-2023 79 2 4
Ley de Aguas Nacionales LAN 01-12-1992 11-12-2025 215 5 11
Ley General de Aguas LGAg 11-12-2025 none 45 0 1
Ley General del Equilibrio Ecológico y la Protección al Ambiente LGEEPA 28-01-1988 19-01-2026 270 33 21
Ley Agraria LAgra 26-02-1992 14-11-2025 201 5 10

Empresa, comercio y competencia

Law Abbr. Published (DOF) Last reform (DOF) Articles Reform decrees Versions in git
Código de Comercio CCom 07-10-1889 18-02-2026 1,641 49 20
Ley General de Sociedades Mercantiles LGSM 04-08-1934 26-12-2025 277 12 10
Ley General de Títulos y Operaciones de Crédito LGTOC 27-08-1932 26-03-2024 463 21 8
Ley de Inversión Extranjera LIE 27-12-1993 27-05-2024 42 8 10
Ley Federal de Competencia Económica LFCE 23-05-2014 14-11-2025 153 1 4
Ley Federal de Protección al Consumidor LFPC 24-12-1992 23-12-2025 190 24 27

Propiedad intelectual y datos personales

Law Abbr. Published (DOF) Last reform (DOF) Articles Reform decrees Versions in git
Ley Federal del Derecho de Autor LFDA 24-12-1996 14-05-2026 259 6 10
Ley Federal de Protección a la Propiedad Industrial LFPPI 01-07-2020 03-04-2026 421 2 2
Ley Federal de Protección de Datos Personales en Posesión de los Particulares LFPDPPP 20-03-2025 14-11-2025 64 0 2

Trabajo, civil, amparo y procedimiento

Law Abbr. Published (DOF) Last reform (DOF) Articles Reform decrees Versions in git
Ley Federal del Trabajo LFT 01-04-1970 14-05-2026 1,266 54 14
Código Civil Federal CCF 26-05-1928 14-11-2025 3,103 57 14
Ley de Amparo, Reglamentaria de los artículos 103 y 107 de la Constitución Política de los Estados Unidos Mexicanos LAmp 02-04-2013 16-10-2025 272 2 11
Código Nacional de Procedimientos Civiles y Familiares CNPCF 07-06-2023 15-01-2026 1,191 2 4

Administración pública, fiscal y penal

Law Abbr. Published (DOF) Last reform (DOF) Articles Reform decrees Versions in git
Ley Orgánica de la Administración Pública Federal LOAPF 29-12-1976 07-05-2026 72 47 30
Ley Federal de Procedimiento Administrativo LFPA 04-08-1994 14-11-2025 119 2 5
Ley General de Responsabilidades Administrativas LGRA 18-07-2016 15-12-2025 235 4 9
Código Fiscal de la Federación CFF 31-12-1981 09-04-2026 421 56 27
Ley del Impuesto sobre la Renta LISR 11-12-2013 01-04-2024 236 2 7
Código Penal Federal CPF 14-08-1931 13-03-2026 556 128 36
Código Nacional de Procedimientos Penales CNPP 05-03-2014 28-11-2025 490 8 13

The list lives in catalog.yml; adding a law is one line.

Where the history comes from

LeyesBiblio only serves the current text of each law. But the Internet Archive has been capturing those same .doc files since 2006, under the three naming schemes the Cámara has used (doc/125.doc, then doc/125_120615.doc, now doc/LFT.doc). leyes history recovers the old file names from archived copies of the index, lists every capture through the public CDX API, downloads each distinct file once, reads its Última reforma publicada DOF dd-mm-yyyy header and keeps one version per reform date. Each commit groups the reforms published between two archived copies of the source and is dated with the latest of them. Dates are those of the DOF publication the text reflects, not of the capture: the oldest captures are from 2006, and some of them hold texts last reformed years earlier (the Ley Agraria captured in 2006 had not changed since 1993, so its history starts there).

Result: 375 versions in git. 27 of 36 laws have more than one version; the oldest dates from 1993. Per-law detail in data/historia/.

Law Versions Since
CPEUM · Constitución Política de los Estados Unidos Mexicanos 44 2006-04-07
CPF · Código Penal Federal 36 2006-06-30
LOAPF · Ley Orgánica de la Administración Pública Federal 30 2006-06-02
CFF · Código Fiscal de la Federación 27 2006-05-12
LFPC · Ley Federal de Protección al Consumidor 27 2006-06-06
LGEEPA · Ley General del Equilibrio Ecológico y la Protección al Ambiente 21 2006-05-23
CCom · Código de Comercio 20 2006-06-06
CCF · Código Civil Federal 14 2004-12-31
LFT · Ley Federal del Trabajo 14 2006-01-17
CNPP · Código Nacional de Procedimientos Penales 13 2014-03-05
LAmp · Ley de Amparo, Reglamentaria de los artículos 103 y 107 de la Constitución Política de los Estados Unidos Mexicanos 11 2013-04-02
LAN · Ley de Aguas Nacionales 11 2004-04-29
LAgra · Ley Agraria 10 1993-07-09
LFDA · Ley Federal del Derecho de Autor 10 2003-07-23
LGSM · Ley General de Sociedades Mercantiles 10 2006-07-28
LIE · Ley de Inversión Extranjera 10 2006-07-18
LIH · Ley de Ingresos sobre Hidrocarburos 10 2014-08-11
LGRA · Ley General de Responsabilidades Administrativas 9 2016-07-18
LGTOC · Ley General de Títulos y Operaciones de Crédito 8 2006-07-18
LISR · Ley del Impuesto sobre la Renta 7 2013-12-11
LFPA · Ley Federal de Procedimiento Administrativo 5 2000-05-30
CNPCF · Código Nacional de Procedimientos Civiles y Familiares 4 2023-06-07
LFCE · Ley Federal de Competencia Económica 4 2014-05-23
LMin · Ley de Minería 4 2006-06-26
LANSI · Ley de la Agencia Nacional de Seguridad Industrial y de Protección al Medio Ambiente del Sector Hidrocarburos 3 2014-08-11
LFPDPPP · Ley Federal de Protección de Datos Personales en Posesión de los Particulares 2 2025-03-20
LFPPI · Ley Federal de Protección a la Propiedad Industrial 2 2020-07-01

Who commits what. Every commit that records a version of a law is authored and committed by Diario Oficial (leyes-mx) <dof@leyes-mx.invalid>, with GIT_AUTHOR_DATE and GIT_COMMITTER_DATE set to noon (Mexico City) of the DOF publication date. The messages cite the decree title, its DOF date and a link to it, plus the consolidated source and the archived copy. The merge that brought the history in and the generated data refreshes are also the bot's, with their real dates. The tooling and documentation commits are the author's, with their real dates. That keeps the legal timeline in git log and git blame without attributing backdated activity to a person.

How the two histories meet. The tooling lives on main from its first commit. The reconstructed law history was built as a separate root (one commit per version, oldest first, across all laws) and merged into main once. So git log -- leyes/cpeum.md walks back through the Constitution's reforms, git log --first-parent shows how the project itself was built, and future imports of more laws can be merged the same way without rewriting anything.

Limitations

  • Unofficial and derived. The texts are the Cámara de Diputados' consolidated versions, not the DOF itself. Consolidation can contain errors; the DOF prevails.
  • Partial history. Old versions exist only where the Internet Archive captured the file. When several reforms fall between two captures, one commit carries all of them and its message says so. Laws enacted in 2025 start at their publication.
  • Index and file can disagree. The date shown is the one printed in the document header. The Cámara sometimes updates its index before the file: as of this snapshot the index lists a reform of the Ley del Impuesto sobre la Renta of 13-11-2026 that the downloadable file does not include yet. The Monday full check (hash comparison) picks such changes up when they land.
  • Source quirks in old versions. 14 of the 375 versions in git show article-numbering anomalies that come from the archived files: 13 old Códigos de Comercio type article 291 as 29l, and the 2014 copy of the Ley Federal de Competencia Económica bundles articles of another law from the same decree. Every current text passes leyes validate --strict.
  • Formatting. Bold and italics from Word are not preserved (editorial notes are rendered in italics on purpose); images, scanned annexes and formulas are not included; tables are kept as Markdown tables.
  • Scope. Federal laws and codes only: no regulations, NOMs, state law or case law. The SCJN legislation portal was evaluated and not used: it sits behind bot protection and session-based forms, and this project does not scrape around that.
  • Transitorios are kept as text with bold labels rather than headings, so the outline of each file stays readable.
  • Size. The largest codes are 0.7 to 1.3 MB of Markdown. GitHub renders files of that size, but if the rich view ever times out, use Raw, the docs page or a local clone.

Repository layout

leyes/                  one Markdown file per law + its reform timeline
data/reformas/          reform decrees per law (JSON, from LeyesBiblio)
data/historia/          which archived file became which version (JSON)
src/leyes_mx/           doc.py, parse.py, sources.py, wayback.py, history.py, cli.py ...
tests/                  pytest suite (parser, sources, git history)
docs/                   static index page (GitHub Pages ready)
CHANGES.md              recent reforms across all tracked laws
catalog.yml             the curated list of laws

Politeness

The pipeline identifies itself with a generic leyes-mx/0.1 User-Agent that points to this repository, waits 3 seconds between requests to the same host (the Cámara de Diputados and the Internet Archive alike), uses timeouts, and retries with exponential backoff. The daily job downloads one index page; files are downloaded only for laws whose date changed (plus a full hash check on Mondays).

Disclaimer

Unofficial. Only the Diario Oficial de la Federación is authoritative. Not legal advice. This project is not affiliated with the Cámara de Diputados, the DOF or the Internet Archive.

License

Code: MIT. Law texts: excluded from copyright protection by article 14, fraction VIII, of the Ley Federal del Derecho de Autor; anything this project adds to the data is dedicated to the public domain (CC0). See DATA-LICENSE.md, which quotes the article. That is the author's reading of the law, not legal advice.

Author

Benjamín Esponda García, corporate lawyer in Mexico City (energy, hydrocarbons and mining, about eight years in practice) who builds legal tools with AI. This repository is the kind of thing a lawyer wants and a developer can maintain: the law as data, with its history intact.

pivotek.mx · AI portfolio · @BEG-lag

About

Mexican federal law as code: 36 federal laws as Markdown in git, with 375 historical versions recovered from archived copies. Every reform is a commit dated on its DOF publication.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages