Skip to main content

FiscalRail Python SDK

Typed Python client for issuing immutable invoices through FiscalRail.

Documentation · Changelog

python -m pip install fiscalrail

Pass a Test or Live secret explicitly when creating the client.

Issue an invoice

import os
from decimal import Decimal

from fiscalrail import FiscalRail
from fiscalrail.tax_regimes.es import irpf, vat

client = FiscalRail(os.environ["FISCALRAIL_API_KEY"])

invoice = client.invoices.issue(
    customer="cus_...",
    lines=[
        {
            "description": "Consulting services",
            "unit_price": Decimal("2500.00"),
            "taxes": [vat.general, irpf.professionals],
        }
    ],
)

pdf = client.invoice_pdfs.render_content(invoice.id, locale="en")
pdf.write_to_file(f"{invoice.code}.pdf")

The API key is required. Your application may read it from an environment variable or secret manager, but the SDK never reads process configuration on its own. The key selects the Test or Live account; the SDK has no separate environment switch.

The client owns a pooled requests.Session by default. Applications that need custom proxy, TLS, adapter or observability configuration can inject one:

import os

import requests

from fiscalrail import FiscalRail

session = requests.Session()
client = FiscalRail(os.environ["FISCALRAIL_API_KEY"], session=session)

Injected sessions remain owned by the caller and are not closed by the SDK.

Invoice issuance automatically uses an idempotency key. Durable workflows can provide and persist their own:

invoice = client.invoices.issue(
    idempotency_key="a49b50f6-1571-4e06-a243-e258bda98e40",
    customer="cus_...",
    lines=[
        {
            "description": "Consulting services",
            "unit_price": "2500.00",
            "taxes": [vat.general],
        }
    ],
)

Typed request values

Calls are type checked directly. Exported TypedDict definitions also make larger payloads reusable without introducing runtime parameter wrappers:

from fiscalrail.params import InvoiceIssueParams

params = InvoiceIssueParams(
    customer="cus_...",
    lines=[
        {
            "description": "Consulting services",
            "unit_price": Decimal("2500.00"),
            "taxes": [vat.general, irpf.professionals],
        }
    ],
)

invoice = client.invoices.issue(**params)

Responses are dependency-free frozen dataclasses. Dates, timestamps and monetary amounts are parsed into date, datetime and Decimal values. Unknown response fields are retained in response.extra_fields for forward compatibility and remain available through attribute access.

The response dataclasses, request TypedDicts, enums and operation registry are generated from FiscalRail's OpenAPI contract. The public client and resource methods remain hand-written so they can expose domain verbs, pooling, idempotency and retry behavior instead of generator-shaped HTTP calls.

Resources

  • client.accounts
  • client.api_keys
  • client.customers
  • client.event_destinations
  • client.events
  • client.invoice_series
  • client.invoices
  • client.invoice_pdfs
  • client.tax_ids
  • client.tax_regimes

Invoices use the domain verbs issue and amend; they are never updated. Account resources expose list, retrieve, and update operations. Customer and series resources expose ordinary create, retrieve, update, list and delete operations.

Verify webhooks

Verify the exact request body before parsing or processing it:

from fiscalrail.webhooks import construct_event

event = construct_event(raw_body, signature_header, signing_secret)

construct_event checks the HMAC in constant time, applies a five-minute timestamp tolerance, and raises WebhookSignatureError when verification fails.

Development

uv sync --all-groups
uv run python scripts/generate_contract.py
uv run python scripts/generate_contract.py --check
uv run pytest
uv run ty check
uv run ruff check .
uv build

Release maintainers should follow the release guide.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fiscalrail-0.2.0.tar.gz (82.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fiscalrail-0.2.0-py3-none-any.whl (27.6 kB view details)

Uploaded Python 3

File details

Details for the file fiscalrail-0.2.0.tar.gz.

File metadata

  • Download URL: fiscalrail-0.2.0.tar.gz
  • Upload date:
  • Size: 82.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for fiscalrail-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a59b91c1aeec6da1d7612157f82d4b257def9aa56bd1949ff30f84160e14682c
MD5 789c42d650dbf122d18ce391b0ab7b6b
BLAKE2b-256 f4d66d777789dca5e09bcf5b318f4cf8da517a1a5f3a2d93984badf0608a33ad

See more details on using hashes here.

Provenance

The following attestation bundles were made for fiscalrail-0.2.0.tar.gz:

Publisher: release.yml on fiscalrail/fiscalrail-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fiscalrail-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: fiscalrail-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 27.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for fiscalrail-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b6b853ab3e5a6425f842861cde66ab7224fb2d5b8bda9b7527e1c9c02acdd889
MD5 cf4515d50a8c18b363679f347f4dc7b6
BLAKE2b-256 65ae4d60842fadf133d2167cb439498c479f51e61ffb758be684e92d05df75f9

See more details on using hashes here.

Provenance

The following attestation bundles were made for fiscalrail-0.2.0-py3-none-any.whl:

Publisher: release.yml on fiscalrail/fiscalrail-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.3.0

2 files

This release

0.2.0 This release

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page