Skip to main content

nota2md

Builds the Markdown of a single DOF note, identified by its codNota, for Mexico's official gazette (DOF, Diario Oficial de la Federación).

Where dof2md converts a whole edition PDF and dofjson is a thin client for SIDOF's JSON service, nota2md ties them together to produce the Markdown for one note, from any of three sources:

Source How When
HTML Converts the note's cadenaContenido HTML directly (a DOF-tailored BeautifulSoup converter). The note has digital text. Preferred: clean, already scoped to the one note, no OCR.
Image Downloads the note's scanned page image(s) via dofjson, OCRs them with dof2md/mineru, then slices out the one note. Image-only notes — or any note, when you want the certified scanned original.
PDF Downloads the note's own PDF (the edition PDF sliced to the note's pages, via dofjson.download_nota_pdf), OCRs it with dof2md/mineru, then slices out the one note. When you'd rather OCR a PDF than page images.

Both OCR paths (image and PDF) mirror the HTML path's output style (#/## headings, **bold**, *italic*, GitHub tables — dof2md rewrites mineru's HTML tables to Markdown), so a note's Markdown looks much the same whichever source it came from.

Notes SIDOF does not have

SIDOF is missing whole days of the gazette (see dofjson), and the notes published on them have no SIDOF record at all — no cadenaContenido, and no codDiario or page numbers for the OCR paths to start from. When SIDOF answers {"Nota": []} for a codNota, nota2md looks the note up on the DOF's own website instead, which serves the same HTML:

nota2md 4997808 --outdir output   # DOF 03-03-1999, a day SIDOF lost

The HTML path is the only one that can build these notes; asking for --source image or --source pdf on one raises rather than fetching the wrong pages.

Cutting a note out of its page

A scanned page (or a sliced PDF) usually holds more than one note: it can begin with the tail of the previous note and end with the start of the next. nota2md uses the per-day note index — which lists every note's title in order — to locate two boundaries in the OCR'd text (where this note's title appears, and where the next note's title appears) and keeps only what lies between. Matching is fuzzy (accent-folded, marker-stripped, difflib alignment) to tolerate OCR differences, and it also drops the next note's organism header that the DOF prints above its title.

Usage

# HTML when available, otherwise OCR of the scanned page(s)
nota2md 5793655 --outdir output

# force the scanned-image + OCR path, sourcing the next note's title from a
# saved notas index (avoids an extra request; works offline)
dofjson 2026-07-15 --outdir output          # writes 15072026-notas.json
nota2md 5793655 --source image --notas output/15072026-notas.json --outdir output

# force the PDF + OCR path (edition PDF sliced to the note's pages)
nota2md 5793655 --source pdf --notas output/15072026-notas.json --outdir output

Programmatically:

from pathlib import Path
from nota2md.builder import build_nota_markdown

build_nota_markdown(5793655, Path("output"))                 # -> output/nota-5793655.md

The HTML path needs only beautifulsoup4; the image and PDF paths additionally need dof2md (and mineru), imported lazily so the HTML path works without them.

Installation

pip install nota2md          # HTML path only
pip install nota2md[ocr]     # also pulls in dof2md, for the image/PDF OCR paths

dofjson is a hard dependency and installs automatically. For development in this monorepo, install the siblings editable instead so local edits are picked up:

pip install -e "packages/dofjson"
pip install -e "packages/dof2md"          # only needed for the image/PDF OCR paths
pip install -e "packages/nota2md[test]"

Development

pytest packages/nota2md

Download files

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

Source Distribution

nota2md-0.2.1.tar.gz (18.0 kB view details)

Uploaded Source

Built Distribution

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

nota2md-0.2.1-py3-none-any.whl (13.1 kB view details)

Uploaded Python 3

File details

Details for the file nota2md-0.2.1.tar.gz.

File metadata

  • Download URL: nota2md-0.2.1.tar.gz
  • Upload date:
  • Size: 18.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for nota2md-0.2.1.tar.gz
Algorithm Hash digest
SHA256 60c9a9eda7d08a63b4d625863d25756ccabdb0c25210b91d4b79caa04a7603e0
MD5 c3fd4f169753a0e09afec693382bdda6
BLAKE2b-256 91a7e0944718f941cbe59abd0d5d045dffefa788cebb42a54169ed8e5364afbe

See more details on using hashes here.

File details

Details for the file nota2md-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: nota2md-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 13.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.12.13

File hashes

Hashes for nota2md-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 2770567208d9863460c7cb661b5cbea33a0c7ef95f9b6311ca0003702a16230e
MD5 69f9adadd8a8cb3003f347b8dac9f19c
BLAKE2b-256 63269c13b247ee6f4b0aa628be3dd009ec262f665c21e964e3c2de2e2e8429f5

See more details on using hashes here.

Release history Release notifications | RSS feed

0.4.1

2 files

0.4.0

2 files

0.3.0

2 files

This release

0.2.1 This release

2 files

0.2.0

2 files

0.1.0

2 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