Skip to main content

normasbr

MIT licensed Python 3.12 Ruff CI PyPi Latest Release Downloads readthedocs Python

⚠️ ATENÇÃO ⚠️: Biblioteca ainda em estágio muito experimental, e sem garantias de retrocompatibilidade entre as versões.

normasbr é uma biblioteca Python que extrai, segmenta e estrutura normativas brasileiras (leis, decretos, medidas provisórias etc.) a partir de HTML, PDF, DOCX ou TXT, convertendo textos brutos em documentos estruturados (YML), com hierarquia completa de dispositivos (norma > agrupadores > artigos > incisos > alíneas > itens).

O processamento é determinístico, usando heurísticas e expressões regulares baseadas em documentos normativos diversos.

Pipeline

ingerir -> segmentar -> estruturar
  1. Ingestão: normaliza HTML/PDF/DOCX/TXT para um HTML canônico;
  2. Segmentação: extrai blocos de texto e classifica cada segmento (artigo, parágrafo, inciso, ementa, preâmbulo, bloco de alteração etc.);
  3. Estruturação: monta a árvore hierárquica da normativa a partir dos segmentos;

Instalação

A última versão pode ser instalada com o uv:

uv add normasbr # Usando como biblioteca
uv tool install normasbr # Usando como utilitário de linha de comando

Ou diretamente do repositório:

uv pip install git+https://github.com/ipea/normasbr

Exemplo de uso

Biblioteca:

import normasbr

for bruta in normasbr.despachar_ingestao("data/DEL5452.htm"):
    segmentos = normasbr.Segmentador().segmentar(normasbr.extrair_blocos(bruta))
    normas = normasbr.estruturar(segmentos, leniente=True)

print(normasbr.formatar_normativas_yml(normas))

CLI:

normasbr ingerir data/DEL5452.htm
normasbr segmentar data/docs
normasbr estruturar data/docs -o normas.yml
normasbr diff_seg snapshot.jsonl novo.jsonl
normasbr classificar_macrodim normas.yml saida.parquet

Desenvolvimento

make setup   # cria o venv e instala as dependências
make check   # lint (ruff) + testes (pytest)
make format  # formata o código

Referências usadas na modelagem

Nota Ipea

normasbr é desenvolvido por uma equipe de pesquisadores do Instituto de Pesquisa Econômica Aplicada (Ipea).

Download files

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

Source Distribution

normasbr-0.0.2.tar.gz (30.3 kB view details)

Uploaded Source

Built Distribution

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

normasbr-0.0.2-py3-none-any.whl (38.5 kB view details)

Uploaded Python 3

File details

Details for the file normasbr-0.0.2.tar.gz.

File metadata

  • Download URL: normasbr-0.0.2.tar.gz
  • Upload date:
  • Size: 30.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.8 {"installer":{"name":"uv","version":"0.12.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for normasbr-0.0.2.tar.gz
Algorithm Hash digest
SHA256 4aa1969660af24d61e1142328e6a784bd11a6ab63a2e8d52d6565970675104b7
MD5 091874edc061d6a0c65fbe3b0e9af1de
BLAKE2b-256 2c0b5766940fd7275f8b85e1004bddb99f3acc3a2a3c889918583bb7cfa0c860

See more details on using hashes here.

Provenance

The following attestation bundles were made for normasbr-0.0.2.tar.gz:

Publisher: pypi-release.yml on ipea/normasbr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file normasbr-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: normasbr-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 38.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.8 {"installer":{"name":"uv","version":"0.12.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for normasbr-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 c54bbe9586bd54eecb3472154204bd68d3396e8fecf301ddbcdbefe3f936bc14
MD5 d608279ee892aafa4c2d26619013275f
BLAKE2b-256 b877d824321c9bdd079acbdd80ef369baa48060a4d5a52f8add0546eba376df4

See more details on using hashes here.

Provenance

The following attestation bundles were made for normasbr-0.0.2-py3-none-any.whl:

Publisher: pypi-release.yml on ipea/normasbr

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.0.2 This release

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