Skip to main content

filings-rfb

Receita Federal emblem

Project Status: Active Python Version PyPI Version Docs Linting Type-checked: mypy Test Coverage License Open Issues Contributions Welcome

Overview

filings-rfb reads the Receita Federal do Brasil (RFB) CNPJ open data (the company registry) into typed pandas DataFrames. It covers every dataset the RFB publishes:

Dataset Reader Content
Empresas read_companies Legal entities (basic CNPJ, name, legal nature, share capital)
Estabelecimentos read_establishments Establishments, with the full 14-character CNPJ and its validity
Socios read_partners Partners and representatives (CPFs stay masked)
Simples read_simples Simples Nacional and MEI options
Cnaes, Motivos, Municipios, Naturezas, Paises, Qualificacoes read_lookup Code lookup tables

Data source and cadence. The data comes from the RFB's public share (arquivos.receitafederal.gov.br), which publishes one folder per reference month (YYYY-MM), refreshed monthly. A reader takes the month as its argument; a month the share does not publish raises an error rather than falling back to another one.

⚠️ Size. The archives are large and are never held in memory: each reader streams every ZIP to disk and yields typed chunks. Estabelecimentos is the heaviest (ten parts, up to 2.3 GB each compressed) and Simples.zip inflates to ~3.2 GB. Plan for disk space and a long first run; pass path_workdir= to keep the ZIPs so a rerun resumes instead of downloading again.

Documentation

The full documentation is published at https://guilhermegor.github.io/filings-rfb/:

To serve it locally: bash bin/poe_exec.sh docs_serve (runs the project venv's poe, no activation needed).

Getting Started

Python 3.10+ is the only prerequisite.

Install

pip install filings-rfb
pip install 'filings-rfb[parquet]'   # optional: Parquet export (pulls in pyarrow)

Or with Poetry:

poetry add filings-rfb

To work on the library itself, see CONTRIBUTING.md.

Usage

Every dataset reader (read_companies, read_establishments, read_partners, read_simples) takes a reference month (YYYY-MM) and yields chunks of int_chunk_rows rows (default 500,000), so memory stays flat. read_lookup is the exception: it takes str_table, path_zip, str_url, str_etag and returns a single DataFrame, since each lookup table is small. Every row carries provenance columns (url, updated_at, source_key, package_version, ingestion_run_id, content_hash, source_etag).

Empresas. capital_social is an exact Decimal, never a float.

from filings_rfb import read_companies

for df_chunk in read_companies("2026-10"):
    ...

Estabelecimentos. Adds the full cnpj_completo and its validity flag cnpj_valido (alphanumeric-aware).

from filings_rfb import read_establishments

for df_chunk in read_establishments("2026-10"):
    ...

Socios. Masked CPFs (***240659**) are kept verbatim, never unmasked; ***000000** as representative document becomes null.

from filings_rfb import read_partners

for df_chunk in read_partners("2026-10"):
    ...

Simples. Booleans and real dates, with the RFB's 00000000 read as null.

from filings_rfb import read_simples

for df_chunk in read_simples("2026-10"):
    ...

Lookups. read_lookup reads one downloaded lookup ZIP (one of CNPJ_LOOKUP_NAMES).

from pathlib import Path

from filings_rfb import read_lookup
from filings_rfb._internal.utils.stream_downloader import download_file_streaming
from filings_rfb.ingestion.cnpj._share import file_url, latest_reference_month

str_url = file_url(latest_reference_month(), "Cnaes.zip")
path_zip, str_etag = download_file_streaming(str_url, Path("data/raw/Cnaes.zip"))
df_cnaes = read_lookup("Cnaes", path_zip, str_url, str_etag)

Parquet. export_companies_parquet("2026-10", path) writes Empresas to one Parquet file for lazy querying (DuckDB, Polars scan_parquet); it needs the parquet extra.

⚠️ Do not read these files with Polars directly: it silently misparses the .zip and corrupts latin-1 text.

Project Structure

filings-rfb/
├── .github/              workflows, CODEOWNERS, PR template
├── assets/               logo
├── bin/                  gate scripts and helpers
├── docs/                 published documentation (mkdocs)
├── src/filings_rfb/
│   ├── __init__.py       the public API (__all__)
│   ├── ingestion/cnpj/   one reader per RFB dataset
│   └── _internal/        private: contracts, utils, ports
├── tests/
│   ├── unit/
│   └── integration/
├── pyproject.toml
└── poe_tasks.toml        task runner entry points

Development

git clone https://github.com/guilhermegor/filings-rfb.git
cd filings-rfb
bash bin/venv.sh                           # bootstrap: Poetry venv and all deps (poe included)
bash bin/precommit.sh                      # install the git hooks
bash bin/poe_exec.sh unit_tests            # unit suite
bash bin/poe_exec.sh integration_tests     # integration suite
bash bin/poe_exec.sh lint                  # ruff, codespell and the structure gates
bash bin/poe_exec.sh docs_serve            # serve the docs locally

Public API

The public surface is whatever the package __init__.py lists in __all__; everything under _internal/ is private.

  • read_companies(str_month, int_chunk_rows=500_000, path_workdir=None): Empresas chunks.
  • read_establishments(...): Estabelecimentos chunks, same signature.
  • read_partners(...): Socios chunks, same signature.
  • read_simples(...): Simples chunks, same signature.
  • export_companies_parquet(str_month, path_dest, int_chunk_rows=500_000, path_workdir=None): Empresas to one Parquet file (needs the parquet extra).
  • read_lookup(str_table, path_zip, str_url, str_etag): one of the six lookup tables (CNPJ_LOOKUP_NAMES) as a typed DataFrame.
  • CNPJ_LOOKUP_NAMES, __version__.

Publishing

Releases go out from the release workflows under .github/workflows/ through PyPI trusted publishing (OIDC); the git tag is the version.

Contributing

See CONTRIBUTING.md for the branch, commit and review rules.

License

This project is licensed under MIT; see LICENSE.

Authors


Generated from the lib-minimal template via BlueprintX. Unofficial, community library. Not affiliated with or endorsed by the Receita Federal do Brasil; the emblem is theirs.

Metadata

Release files for filings-rfb 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for filings-rfb 1.0.1
File Size Uploaded Provenance
filings_rfb-1.0.1.tar.gz 81.8 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for filings-rfb 1.0.1
File Interpreter ABI Platform
filings_rfb-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 191.6 kB

Release files / filings_rfb-1.0.1.tar.gz

Download URL filings_rfb-1.0.1.tar.gz
Size 81.8 kB
Tags Source
SHA-256 checksum
How to use checksums
24339e97f0aeefe24e166cd9679ed22f0ccea76bb5483ba15e4ef07703e94a8b
BLAKE2b-256 checksum
How to use checksums
e4ab11a0f796ade1e9b03e63d02e1cc715b94625cd1be8b679115cba6a68c2c7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Release files / filings_rfb-1.0.1-py3-none-any.whl

Download URL filings_rfb-1.0.1-py3-none-any.whl
Size 109.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
375be9f3b63eb46ca77e28a1a47b7370051fb7f7b092088273d92511e2580713
BLAKE2b-256 checksum
How to use checksums
21c243166eb5182096e1b681f03741f7bcd15912a5ca354c2237667cc98861c3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

Security for filings-rfb 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for filings_rfb-1.0.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 25, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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