Skip to main content

FiscalFixtures BR

Brazilian Fiscal Documents Testing Toolkit

Tests Lint & Typecheck Python 3.11+ License: MIT

Leia em Português: README.pt-BR.md

FiscalFixtures BR is an open-source Python toolkit providing fictional Brazilian electronic fiscal XML documents, reusable test fixtures, deterministic NF-e generation utilities, secure XML validation, and automated testing scenarios.

Important Notice — Test Data Only: All XML fixtures and generated documents use 100% fictional data and homologation (tpAmb=2) markers. They are not officially authorized by SEFAZ and must never be used for production fiscal issuance.


Why FiscalFixtures BR?

Developers building ERPs, accounting software, e-commerce checkouts, and fiscal integrations in Brazil spend significant time crafting XML payloads and reproducing edge cases (malformed XML, missing tags, invalid numeric types, Simples Nacional vs. Normal regime, freight/discounts).

FiscalFixtures BR solves this by offering:

  • Curated Fictional XML Fixtures: Ready-to-use valid and intentionally invalid NF-e 4.00 XMLs.
  • Numeric & Alphanumeric CNPJ Support: Validates and generates both traditional numeric CNPJs and July 2026 alphanumeric CNPJs ([A-Z0-9]{12}[0-9]{2}, Receita Federal ASCII-48 mod-11, e.g. 00.000.000/E08G-12).
  • Deterministic NF-e Generator: Generate customizable NF-e 4.00 XMLs with seed support for reproducible tests.
  • Secure Multi-Stage XML Validator: Distinguishes well-formedness, NF-e structural rules, and optional local XSD validation with XXE/DTD protection enabled by default.
  • Reusable Testing Scenarios: Standardized scenarios (valid_xml, malformed_xml, missing_required_field, invalid_numeric_value, missing_namespace, xxe_payload, etc.).
  • Clean CLI (fiscalfixtures): Inspect fixtures, generate test XMLs, and validate files from the terminal.

Supported Document Types

Document Status Notes
NF-e (Modelo 55, Layout 4.00) Supported (v0.1.0) Fixtures, generator, structural validator
NFC-e (Modelo 65) Planned (v0.5.0) Directory structure prepared
CT-e (Modelo 57) Planned (Future) Directory structure prepared
MDF-e (Modelo 58) Planned (Future) Roadmap item

Installation

pip install fiscalfixtures-br

Or install from source for local development:

For local development with uv:

git clone https://github.com/moisesz10/FISCALFIXTURES-BR.git
cd FISCALFIXTURES-BR
uv sync --all-extras

Quick Start

1. Load a Curated Fixture

from fiscalfixtures.fixtures import load_fixture, get_fixture_metadata

xml = load_fixture("nfe/basic")
meta = get_fixture_metadata("nfe/basic")
print(meta.document_type, meta.layout_version)

2. Validate an XML Document

from fiscalfixtures.validators import validate_xml

result = validate_xml("examples/nfe/basic.xml")
print(result.is_valid)  # True
print(result.validation_stage)  # "completed"
print(result.errors)  # []

3. Generate a Fictional NF-e XML

from fiscalfixtures.generators import NFeGenerator

generator = NFeGenerator(seed=42)
xml = generator.generate(scenario="multiple_products", products=3)

CLI Usage

# List available fixtures
fiscalfixtures list

# Show fixture metadata
fiscalfixtures info nfe/basic

# Generate a deterministic fictional NF-e XML
fiscalfixtures generate nfe --scenario basic --seed 42 --output sample.xml

# Validate an XML file (optionally with a local verified XSD)
fiscalfixtures validate sample.xml
fiscalfixtures validate sample.xml --xsd path/to/nfe_v4.00.xsd

# List reusable testing scenarios
fiscalfixtures scenarios

# Check supported schema versions and local XSD availability
fiscalfixtures schemas

# Show installed version
fiscalfixtures version

Project Structure

FiscalFixtures-BR/
├── src/fiscalfixtures/
│   ├── cli/            # Typer CLI commands
│   ├── data/fixtures/  # Packaged fictional XML fixtures & manifest
│   ├── fixtures/       # Secure fixture loader
│   ├── generators/     # Deterministic NF-e 4.00 generator
│   ├── models/         # Pydantic v2 domain models
│   ├── scenarios/      # Reusable testing scenarios catalog
│   └── validators/     # Multi-stage secure XML & XSD validators
├── examples/           # Browsable valid XML examples
├── invalid-examples/   # Browsable invalid XML examples
├── schemas/            # Instructions for local official XSD usage
├── docs/               # MkDocs documentation
├── tests/              # Unit and integration tests
└── .github/            # CI workflows and issue/PR templates

Running Tests & Quality Checks

uv run pytest --cov=fiscalfixtures --cov-report=term-missing
uv run ruff check src tests
uv run mypy src tests

Security

FiscalFixtures BR is designed with strict security defaults:

  • XXE & DTD Protection: External entities, DTD loading, and network access are disabled in lxml. <!DOCTYPE and <!ENTITY declarations are explicitly rejected.
  • Path Traversal Prevention: Fixture IDs are validated against a strict allowlist regex and resolved paths are verified to stay within the packaged fixtures directory.
  • No Real Fiscal Data: Never commit real NF-e XMLs, real CNPJs/CPFs of customers, or digital certificates (.pfx/.p12).

See SECURITY.md for responsible vulnerability reporting.


Roadmap

  • v0.1.0 — Foundation: Core Python package, NF-e 4.00 fixtures, loader, deterministic generator, secure XML validator, CLI, tests, and docs.
  • v0.2.0 — Developer Toolkit: Expanded NF-e scenarios, richer tax/item customization, enhanced validation diagnostics.
  • v0.3.0 — Validation: Verified official XSD integration guides and extended structural checks.
  • v0.4.0 — Community: Expanded contributor-submitted fixtures and scenarios.
  • v0.5.0 — Expansion: NFC-e (Modelo 65) support.
  • Future: CT-e, MDF-e, optional FastAPI integration.

Contributing

Contributions are warmly welcome! Please read CONTRIBUTING.md and our CODE_OF_CONDUCT.md before submitting a pull request.

License

Licensed under the MIT License.

Metadata

Release files for fiscalfixtures-br 0.1.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 fiscalfixtures-br 0.1.1
File Size Uploaded Provenance Actions
fiscalfixtures_br-0.1.1.tar.gz 60.3 kB With provenance Details for fiscalfixtures_br-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fiscalfixtures-br 0.1.1
File Interpreter ABI Platform Actions
fiscalfixtures_br-0.1.1-py3-none-any.whl Python 3 none any Details for fiscalfixtures_br-0.1.1-py3-none-any.whl

Total release size: 110.5 kB

Release files / fiscalfixtures_br-0.1.1.tar.gz

Download URL fiscalfixtures_br-0.1.1.tar.gz
Size 60.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a342d0e14ca9e8090e2bece6446d8b46b78343e8343a3cd9f3287f20ad0f0ff6
BLAKE2b-256 checksum
How to use checksums
58737a26167ca5c7c4da9cca02c5dd258157114cddbb4845d92ca4984a699150
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 Dec 5, 2026.

Transparency log

Release files / fiscalfixtures_br-0.1.1-py3-none-any.whl

Download URL fiscalfixtures_br-0.1.1-py3-none-any.whl
Size 50.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa70be04646c3f67868157cd0184195ebef5013aa50a1dc9ab2ef1653b00a168
BLAKE2b-256 checksum
How to use checksums
285deed97705f0e3878d36eae00544ae976546cde89cf684898868515d8131b5
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 Dec 5, 2026.

Transparency log

Security for fiscalfixtures-br 0.1.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fiscalfixtures_br-0.1.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 Dec 5, 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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

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