FiscalRail Python SDK
Typed Python client for issuing immutable invoices through FiscalRail.
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.accountsclient.api_keysclient.customersclient.event_destinationsclient.eventsclient.invoice_seriesclient.invoicesclient.invoice_pdfsclient.tax_idsclient.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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a59b91c1aeec6da1d7612157f82d4b257def9aa56bd1949ff30f84160e14682c
|
|
| MD5 |
789c42d650dbf122d18ce391b0ab7b6b
|
|
| BLAKE2b-256 |
f4d66d777789dca5e09bcf5b318f4cf8da517a1a5f3a2d93984badf0608a33ad
|
Provenance
The following attestation bundles were made for fiscalrail-0.2.0.tar.gz:
Publisher:
release.yml on fiscalrail/fiscalrail-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fiscalrail-0.2.0.tar.gz -
Subject digest:
a59b91c1aeec6da1d7612157f82d4b257def9aa56bd1949ff30f84160e14682c - Sigstore transparency entry: 2520578244
- Sigstore integration time:
-
Permalink:
fiscalrail/fiscalrail-python@a17e2572c3d54c69766d91e87674aea5ba4915ed -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/fiscalrail
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a17e2572c3d54c69766d91e87674aea5ba4915ed -
Trigger Event:
release
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b6b853ab3e5a6425f842861cde66ab7224fb2d5b8bda9b7527e1c9c02acdd889
|
|
| MD5 |
cf4515d50a8c18b363679f347f4dc7b6
|
|
| BLAKE2b-256 |
65ae4d60842fadf133d2167cb439498c479f51e61ffb758be684e92d05df75f9
|
Provenance
The following attestation bundles were made for fiscalrail-0.2.0-py3-none-any.whl:
Publisher:
release.yml on fiscalrail/fiscalrail-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fiscalrail-0.2.0-py3-none-any.whl -
Subject digest:
b6b853ab3e5a6425f842861cde66ab7224fb2d5b8bda9b7527e1c9c02acdd889 - Sigstore transparency entry: 2520578339
- Sigstore integration time:
-
Permalink:
fiscalrail/fiscalrail-python@a17e2572c3d54c69766d91e87674aea5ba4915ed -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/fiscalrail
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@a17e2572c3d54c69766d91e87674aea5ba4915ed -
Trigger Event:
release
-
Statement type: