Metadata-Version: 2.5
Name: fiscalfixtures-br
Version: 0.1.1
Summary: Brazilian Fiscal Documents Testing Toolkit — fictional XML fixtures, NF-e generator, and secure XML validator.
Project-URL: Homepage, https://github.com/moisesz10/FISCALFIXTURES-BR
Project-URL: Documentation, https://github.com/moisesz10/FISCALFIXTURES-BR/tree/main/docs
Project-URL: Repository, https://github.com/moisesz10/FISCALFIXTURES-BR
Project-URL: Issues, https://github.com/moisesz10/FISCALFIXTURES-BR/issues
Project-URL: Changelog, https://github.com/moisesz10/FISCALFIXTURES-BR/blob/main/CHANGELOG.md
Author: FiscalFixtures BR Contributors
License: MIT
License-File: LICENSE
Keywords: brazil,cte,fiscal,fixtures,nfce,nfe,sefaz,testing,xml
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: Text Processing :: Markup :: XML
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: lxml>=5.0.0
Requires-Dist: pydantic>=2.7.0
Requires-Dist: typer>=0.12.0
Provides-Extra: dev
Requires-Dist: coverage[toml]>=7.6.0; extra == 'dev'
Requires-Dist: lxml-stubs>=0.5.1; extra == 'dev'
Requires-Dist: mypy>=1.11.0; extra == 'dev'
Requires-Dist: pre-commit>=3.8.0; extra == 'dev'
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
Requires-Dist: pytest>=8.3.0; extra == 'dev'
Requires-Dist: ruff>=0.6.0; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mkdocs-material>=9.5.0; extra == 'docs'
Requires-Dist: mkdocs>=1.6.0; extra == 'docs'
Description-Content-Type: text/markdown

# FiscalFixtures BR

**Brazilian Fiscal Documents Testing Toolkit**

[![Tests](https://github.com/moisesz10/FISCALFIXTURES-BR/actions/workflows/tests.yml/badge.svg)](https://github.com/moisesz10/FISCALFIXTURES-BR/actions/workflows/tests.yml)
[![Lint & Typecheck](https://github.com/moisesz10/FISCALFIXTURES-BR/actions/workflows/lint.yml/badge.svg)](https://github.com/moisesz10/FISCALFIXTURES-BR/actions/workflows/lint.yml)
[![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)

> **Leia em Português:** [README.pt-BR.md](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

```bash
pip install fiscalfixtures-br
```

Or install from source for local development:

For local development with `uv`:

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

---

## Quick Start

### 1. Load a Curated Fixture

```python
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

```python
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

```python
from fiscalfixtures.generators import NFeGenerator

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

---

## CLI Usage

```bash
# 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

```text
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

```bash
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](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](CONTRIBUTING.md) and our [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) before submitting a pull request.

## License

Licensed under the [MIT License](LICENSE).
