Skip to content

Dados de CNPJ da base da receita direto para seu banco

Notifications You must be signed in to change notification settings

caiopizzol/cnpj-data-pipeline

Repository files navigation

CNPJ Data Pipeline (v2)

Release Python Ruff codecov

Baixa e processa dados de empresas brasileiras da Receita Federal para PostgreSQL.

Important

Novo em v1.3.2A Receita Federal migrou os arquivos CNPJ para um novo repositório Nextcloud. Esta versão já suporta a nova URL e realiza downloads via WebDAV automaticamente. Nenhuma configuração adicional necessária.

Requisitos

  • uv - brew install uv
  • just - brew install just
  • Docker

Início Rápido

cp .env.example .env
just up      # Iniciar PostgreSQL
just run     # Executar pipeline

Comandos

just install # Instalar dependências
just up      # Iniciar PostgreSQL
just down    # Parar PostgreSQL
just db      # Entrar no banco (psql)
just run     # Executar pipeline
just reset   # Limpar e reiniciar banco
just lint    # Verificar código
just format  # Formatar código
just test    # Rodar testes
just check   # Rodar todos (lint, format, test)

Uso

just run                          # Processar mês mais recente
just run --list                   # Listar meses disponíveis
just run --month 2024-11          # Processar mês específico
just run --month 2024-11 --force  # Forçar reprocessamento

Configuração

DATABASE_URL=postgres://postgres:postgres@localhost:5435/cnpj
BATCH_SIZE=500000
TEMP_DIR=./temp
DOWNLOAD_WORKERS=4
RETRY_ATTEMPTS=3
RETRY_DELAY=5
CONNECT_TIMEOUT=30
READ_TIMEOUT=300
KEEP_DOWNLOADED_FILES=false

Schema

Documentação completa: docs/data-schema.md

EMPRESAS (1) ─── (N) ESTABELECIMENTOS
         ├─── (N) SOCIOS
         └─── (1) DADOS_SIMPLES

Fonte de Dados