carimbar
Emissão direta de NF-e e NFS-e Nacional para devs e agentes de IA, sem provedor intermediário.
O nome vem do verbo: carimbar é o gesto que torna um documento oficial.
O núcleo é escrito em Rust e conversa direto com a SEFAZ e com o ADN (Ambiente de Dados Nacional). Você pode usá-lo como CLI, como servidor MCP local (para agentes de IA) ou como biblioteca Python.
Sumário
- Por que carimbar
- Funcionalidades
- Instalação
- Uso rápido
- Segurança e produção
- Estado do projeto
- Roadmap
- Documentação
- Contribuindo
- Licenças
Por que carimbar
Desde 01/11/2026, ME e EPP optantes pelo Simples Nacional são obrigadas a emitir NFS-e pelo Emissor Nacional (Resolução CGSN 191/2026). Isso empurra muita gente para integrações novas, e a maioria das opções disponíveis passa por um provedor intermediário.
O carimbar existe para quem quer emitir direto, com:
- Sem intermediário: a emissão vai direto para a SEFAZ e para o ADN.
- Feito para automação: CLI com códigos de saída estáveis, binding Python e servidor MCP para agentes.
- Seguro por padrão: produção bloqueada até promoção explícita, certificados criptografados em repouso e journal contra emissão duplicada.
- Valores fiscais sem
float:Dinheiroentra e sai como texto.
Funcionalidades
NFS-e Nacional
- DPS, emissão, consulta e cancelamento.
- Distribuição ADN por NSU.
- Parâmetros municipais.
NF-e modelo 55
- Leiaute 4.00 com campos de IBS e CBS (NT 2025.002-RTC, PL_010).
- Autorização, consulta, eventos, inutilização e contingência SVC.
- NFC-e fica para uma fase futura.
Infraestrutura
- Cofre multiempresa de certificados A1, com envelope encryption, rotação de chaves e auditoria encadeada.
- Fachada
Emissorcom journal local, idempotência, reconciliação e bloqueio explícito de produção. - DANFSe e DANFE em PDF gerados a partir do XML autorizado.
- Transporte HTTP/1.1 sobre mTLS com SOAP 1.2 e JSON, sem raízes de confiança embutidas.
Interfaces
- CLI
carimbar. - Servidor MCP stdio em duas fases.
- Binding Python síncrono (PyO3/maturin).
Instalação
carimbar e carimbar-cli estão no crates.io. O pacote Python carimbar sai no PyPI a partir da 0.0.3.
cargo add carimbar
cargo install carimbar-cli
pip install carimbar
Para compilar a partir do repositório:
git clone https://github.com/seatrunk/carimbar.git
cd carimbar
# CLI e MCP com o perfil SHA-1 exigido pela NF-e (os dois binários de carimbar-cli)
cargo build --release -p carimbar-cli --bins --features nfe-sha1
# Binding Python (wheel abi3, com OpenSSL vendored para NF-e/DANFE)
cd crates/carimbar-py
maturin build --release --out dist
pip install dist/*.whl
Requisitos
| Item | Versão |
|---|---|
| Rust | 1.89+ (o toolchain do repositório fixa 1.99.1) |
| Python (wheel) | 3.9+ |
| maturin | >=1.9,<2 |
O build Rust padrão não usa OpenSSL. A feature nfe-sha1 é opt-in, e o wheel Python já a habilita com OpenSSL vendored.
Plataformas suportadas (wheels do PyPI)
A partir da 0.0.3 o PyPI recebe wheels abi3 para Python ≥ 3.9, na matriz do job wheels de .github/workflows/release.yml:
- Linux x86_64 glibc:
manylinux_2_17/ manylinux2014. - Linux aarch64 glibc
manylinux_2_28. - Linux x86_64 musl
musllinux_1_2. - macOS x86_64 (Intel).
- macOS arm64 (Apple Silicon).
- Windows x64.
Não há wheel musllinux aarch64 nem Windows arm64. Nessas plataformas não há wheel e a instalação cai no sdist.
O wheel linux-aarch64 é manylinux_2_28 (glibc ≥ 2.28) e não instala no Amazon Linux 2 em Graviton (glibc 2.26) nem no Ubuntu 18.04 (glibc 2.27). Motivo: o ring 0.17 não compila com o gcc 4.8.5 da imagem manylinux2014.
Alternativas: instalar pela fonte (sdist, pip install --no-binary carimbar carimbar ou o fallback automático do pip; exige toolchain Rust ≥ 1.89, compilador C, make e Perl) ou usar Amazon Linux 2023.
Migração de crates (0.0.1 → 0.0.2)
Os crates carimbar-types, carimbar-cert, carimbar-endpoints e
carimbar-danfe 0.0.1 foram substituídos por carimbar com features: o que era
carimbar_types::X agora é carimbar::types::X (com carimbar ligado por
default), e assim por diante para cert, endpoints, xml, dsig,
transport, vault, danfe, nfse e nfe. Os binários carimbar e
carimbar-mcp agora saem de um único crate, carimbar-cli.
Uso rápido
Python
from carimbar import Cofre, Emissor
# Use uma KEK real, com 64 caracteres hexadecimais.
kek = "07" * 32
cofre = Cofre("carimbar-cofre.db", kek)
with open("a1.p12", "rb") as arquivo:
cofre.importar(
"00000001000136", # CNPJ
"a1", # id do certificado
arquivo.read(),
"senha-do-pfx",
)
emissor = Emissor(
"carimbar-cofre.db",
"carimbar-journal.db",
"00000001000136",
kek,
raizes="raizes-der",
)
with open("dps.xml", encoding="utf-8") as arquivo:
dps_xml = arquivo.read()
resultado = emissor.emitir(dps_xml)
with open("danfse.pdf", "wb") as arquivo:
arquivo.write(emissor.gerar_danfse(resultado["operacao"]))
- Operações bloqueantes liberam o GIL.
- As exceções distinguem validação, rejeição fiscal, transporte, produção, conflito e cofre.
- Use dados sintéticos nos testes e nunca versione PFX, senha, KEK ou XML de empresa real.
CLI
export CARIMBAR_KEK=... # 64 caracteres hexadecimais
export CARIMBAR_SENHA_PFX=... # senha do A1 (nunca em argumento)
export CARIMBAR_RAIZES=... # diretório com raízes de confiança em DER
# Importa o certificado A1 para o cofre
carimbar --empresa 00000001000136 \
empresa importar --id a1 --pfx a1.p12
# Emite a NFS-e e gera o PDF
carimbar --empresa 00000001000136 \
emitir --dps dps.xml --xml-saida nfse.xml --pdf-saida danfse.pdf
Com a feature nfe-sha1, a CLI também aceita emitir-nfe, consultar-nfe e danfe-nfe. A saída humana é o padrão; use --json para JSON.
Códigos de saída
| Código | Significado |
|---|---|
2 |
Erro de uso |
3 |
Rejeição fiscal |
4 |
Falha de transporte ou resultado desconhecido |
5 |
Produção bloqueada |
6 |
Conflito de idempotência |
MCP
Exemplo de configuração para um cliente MCP:
{
"mcpServers": {
"carimbar": {
"command": "carimbar-mcp",
"env": {
"CARIMBAR_KEK": "...",
"CARIMBAR_COFRE": "carimbar-cofre.db",
"CARIMBAR_JOURNAL": "carimbar-journal.db",
"CARIMBAR_RAIZES": "raizes-der",
"CARIMBAR_PRODUCAO": "0"
}
}
}
}
O servidor expõe ferramentas preparar_* e confirmar_* em duas fases:
preparar_*valida e persiste a operação sem enviar, e devolve um token de uso único com validade de 300 segundos (ajustável emCARIMBAR_MCP_TTL_SEGUNDOS).confirmar_*consome o token e envia a operação.
Importação de certificado, promoção de produção e segredos ficam exclusivamente na CLI, fora do alcance do agente.
Segurança e produção
- Produção só é permitida com
CARIMBAR_PRODUCAO=1(depois detrim()). Ausência, vazio,0e qualquer outro valor (true,sim,2,off, lixo) bloqueiam produção. - Promover uma empresa exige chamada explícita com o CNPJ e o certificado. Não existe promoção automática nem valor padrão.
- O cofre cifra os segredos com uma DEK por empresa; a KEK fica fora do arquivo.
- O journal guarda XML, protocolo e estado da operação para evitar emissão duplicada.
- Testes de PR usam dados sintéticos e não acessam SEFAZ, Sefin ou ADN.
- Publicar e homologar são ações manuais, separadas da implementação.
scripts/check-no-certs.shbloqueia certificados e arquivos.envversionados.
Estado do projeto
| Etapa | Situação |
|---|---|
| MVP implementado | Concluído, com testes locais |
| Homologação real | Pendente (manual e protegida) |
| Publicação no crates.io | carimbar e carimbar-cli publicados (0.0.2; 0.0.3 pelo release da tag v0.0.3) |
| Publicação no PyPI | primeira versão é a 0.0.3; a 0.0.2 não foi publicada |
| Uso em produção | Não recomendado |
Veja release e homologação para os procedimentos.
Roadmap
- NFC-e: fase futura.
- Fase 2: servidor self-hosted (HTTP + MCP remoto, fila, contingência e webhooks), construído sobre a mesma lib e licenciado sob AGPL-3.0.
O acompanhamento central está na issue #4.
Documentação
- Plano de implementação do MVP
- Contratos fiscais, arquitetura e limites
- Release e publicação
- Homologação manual protegida
Contribuindo
Contribuições são bem-vindas. Leia o CONTRIBUTING.md antes de abrir um PR e lembre-se: nunca inclua certificados, senhas ou XMLs reais em issues, PRs ou testes.
Licenças
- A lib e o MCP usam a licença Apache-2.0 (veja LICENSE).
- O futuro servidor self-hosted usará AGPL-3.0, num diretório próprio com LICENSE própria.
Metadata
Release files for carimbar 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| carimbar-0.0.3.tar.gz | 165.9 kB | With provenance | Details for carimbar-0.0.3.tar.gz |
Built distributions (wheels)
| File | Actions Reset | |||
|---|---|---|---|---|
| carimbar-0.0.3-cp39-abi3-win_amd64.whl | CPython 3.9 | abi3 | Windows x86-64 | Details for carimbar-0.0.3-cp39-abi3-win_amd64.whl |
| carimbar-0.0.3-cp39-abi3-musllinux_1_2_x86_64.whl | CPython 3.9 | abi3 | Linux musl 1.2+ x86-64 | Details for carimbar-0.0.3-cp39-abi3-musllinux_1_2_x86_64.whl |
| carimbar-0.0.3-cp39-abi3-manylinux_2_28_aarch64.whl | CPython 3.9 | abi3 | Linux glibc 2.28+ ARM64 | Details for carimbar-0.0.3-cp39-abi3-manylinux_2_28_aarch64.whl |
| carimbar-0.0.3-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl | CPython 3.9 | abi3 | Linux glibc 2.17+ x86-64 | Details for carimbar-0.0.3-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
| carimbar-0.0.3-cp39-abi3-macosx_11_0_arm64.whl | CPython 3.9 | abi3 | macOS 11.0+ ARM64 | Details for carimbar-0.0.3-cp39-abi3-macosx_11_0_arm64.whl |
| carimbar-0.0.3-cp39-abi3-macosx_10_12_x86_64.whl | CPython 3.9 | abi3 | macOS 10.12+ x86-64 | Details for carimbar-0.0.3-cp39-abi3-macosx_10_12_x86_64.whl |
Total release size: 34.1 MB
Release files / carimbar-0.0.3.tar.gz
| Download URL | carimbar-0.0.3.tar.gz |
|---|---|
| Size | 165.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
878cacf03c68919dbbf2e78495ece2ab79ed8b499d790cbdc75adf9469d6bce0
|
|
BLAKE2b-256 checksum How to use checksums |
d9f411d923af4f44ff19a010a05822890a18ea9ac4a64e462ad13a9103580a42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 10, 2026.
Transparency logRelease files / carimbar-0.0.3-cp39-abi3-win_amd64.whl
| Download URL | carimbar-0.0.3-cp39-abi3-win_amd64.whl |
|---|---|
| Size | 5.6 MB |
| Tags | CPython 3.9 Windows x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
c76ae02f0e4c4cb5f8bdcd3d23dbea896682c542e824ff3e3dc3fa73a52331e7
|
|
BLAKE2b-256 checksum How to use checksums |
c979289d215d8a0fce83021c3dbd7bf6914267e912ab6cee1ee77fa820ad0614
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 10, 2026.
Transparency logRelease files / carimbar-0.0.3-cp39-abi3-musllinux_1_2_x86_64.whl
| Download URL | carimbar-0.0.3-cp39-abi3-musllinux_1_2_x86_64.whl |
|---|---|
| Size | 6.0 MB |
| Tags | CPython 3.9 Linux musl 1.2+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
878655f92696bc5308f509f0c8885253cb86d694b46c0a460c02750fadcdead4
|
|
BLAKE2b-256 checksum How to use checksums |
545a94ccd62f6f3f04f253cced1fe9ba17eb991d05599f15e035b801052e6c74
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 10, 2026.
Transparency logRelease files / carimbar-0.0.3-cp39-abi3-manylinux_2_28_aarch64.whl
| Download URL | carimbar-0.0.3-cp39-abi3-manylinux_2_28_aarch64.whl |
|---|---|
| Size | 5.8 MB |
| Tags | CPython 3.9 Linux glibc 2.28+ ARM64 abi3 |
|
SHA-256 checksum How to use checksums |
b0b927609452f16b99aa5537a2628f77f1fb5d05f3306a244f465356cc54dd43
|
|
BLAKE2b-256 checksum How to use checksums |
1cff5b3e3f9680c1e24cfbbe33e1260b1d673ca1c3def1ff8037dffd36361976
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 10, 2026.
Transparency logRelease files / carimbar-0.0.3-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
| Download URL | carimbar-0.0.3-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl |
|---|---|
| Size | 5.7 MB |
| Tags | CPython 3.9 Linux glibc 2.17+ x86-64 abi3 |
|
SHA-256 checksum How to use checksums |
c4c95d4d53545bf8a1475c766f7c455f57791a4ca928e90b8df942991fa91484
|
|
BLAKE2b-256 checksum How to use checksums |
a45769efde143b22ee7052190d0a32db6a35fdb0c15ddcb282c20deac2333820
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 10, 2026.
Transparency logRelease files / carimbar-0.0.3-cp39-abi3-macosx_11_0_arm64.whl
| Download URL | carimbar-0.0.3-cp39-abi3-macosx_11_0_arm64.whl |
|---|---|
| Size | 5.5 MB |
| Tags | CPython 3.9 abi3 macOS 11.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
79906a1bdc0988d7a6cc20411151cd96254fbe876e503fe27ef19c83faa93a16
|
|
BLAKE2b-256 checksum How to use checksums |
44a2ef6336ba454b9c297da10de117e4c2a9975fea3afb680e4fadb855f3912b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 10, 2026.
Transparency logRelease files / carimbar-0.0.3-cp39-abi3-macosx_10_12_x86_64.whl
| Download URL | carimbar-0.0.3-cp39-abi3-macosx_10_12_x86_64.whl |
|---|---|
| Size | 5.3 MB |
| Tags | CPython 3.9 abi3 macOS 10.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
59720823dc8b1c4fa8224e4070474aec1a4352485ac66b021486a6de81f5f0bf
|
|
BLAKE2b-256 checksum How to use checksums |
26c09af0bd85864b38a4208a6a712717d3abd587930b48c477d3166b72ffa43f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 10, 2026.
Transparency logSecurity for carimbar 0.0.3
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 7 files in this release have been uploaded with provenance metadata.
Attestation for carimbar-0.0.3.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 Nov 10, 2026.
Transparency logA 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.