Python client for the Finansfatura e-invoice (e-Fatura / e-Arşiv) API
Project description
finansfatura
Python client for the Finansfatura e-invoice API (e-Fatura / e-Arşiv). Issue, list, download and cancel invoices with an API key — no WooCommerce required, this is the general external REST API.
Install
pip install finansfatura
Quickstart
import os
from finansfatura import FinansfaturaClient, build_earsiv_payload
ff = FinansfaturaClient(api_key=os.environ["FINANSFATURA_API_KEY"]) # ff_live_...
payload = build_earsiv_payload(
recipient={"vkn_tckn": "11111111111", "title": "Ahmet Yılmaz",
"email": "ahmet@example.com"},
lines=[
{"title": "Kablosuz Kulaklık", "product_code": "SKU-1042",
"qty": 1, "unit_price": 100.0, "vat_rate": 0.20},
],
)
result = ff.issue_invoice(payload, idempotency_key="order-1042")
print(result["invoice_id"], result["status"]) # -> ... QUEUED
build_earsiv_payload computes totals from the lines (Decimal, no float drift)
and applies the API's exact field casing for you: the outer layer is snake_case
(document_type, canonical) but everything inside canonical is PascalCase
(Recipient, Lines, Totals, VKNorTCKN). A snake_case key inside canonical
is silently ignored by the server, so let the builder handle it.
Idempotency
idempotency_key is required and can be any unique string (use your order
id). Retrying with the same key never double-issues — safe on timeout/retry.
Reading & lifecycle
ff.get_invoice(invoice_id) # poll while status is QUEUED
ff.list_invoices(page=1)
pdf_bytes = ff.download(invoice_id, "pdf") # or "html" / "xml"
ff.cancel(invoice_id) # before GİB acceptance
Errors
Failed calls raise a typed exception carrying .status and .body:
| Exception | HTTP | Meaning |
|---|---|---|
AuthError |
401 | key missing/invalid/revoked/expired |
InsufficientCredits |
402 | not enough credits (kontör) |
ScopeError |
403 | key lacks the required scope |
OnboardingRequired |
412 | e-invoice onboarding not completed |
ProviderError |
5xx | transient upstream — retry same idempotency key |
FinansfaturaError |
other | base class |
from finansfatura import FinansfaturaError, OnboardingRequired
try:
ff.issue_invoice(payload, idempotency_key=f"order-{order.id}")
except OnboardingRequired as e:
... # e.body -> {"error_code": ..., "message": ...}
except FinansfaturaError as e:
log.error("issue failed [%s]: %s", e.status, e.body)
e-Fatura (registered recipients)
e-Arşiv targets final consumers (TCKN is fine). For a GİB-registered recipient use e-Fatura, which needs the recipient's mailbox alias:
from finansfatura import build_efatura_payload
payload = build_efatura_payload(
recipient={"vkn_tckn": "1234567890", "title": "Kurum A.Ş."},
lines=[...],
recipient_alias="urn:mail:defaultpk@example.com",
)
Notes
- Seller identity (
Issuer) is filled server-side from your company profile — don't send it. Make sure the profile VKN is set, or issuing returns 503. - Keep the API key in an env var; never commit it.
Development
pip install -e ".[dev]"
python -m pytest # or: python -m unittest discover tests
License
MIT
Project details
Release history Release notifications | RSS feed
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 finansfatura-0.1.0.tar.gz.
File metadata
- Download URL: finansfatura-0.1.0.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c50f5a3df6358609d4f410f6e69e5be7d188db2d3e984fefefffe6e7ebbbcb05
|
|
| MD5 |
9caae6e5ebce49de216ed19ac26f0bf3
|
|
| BLAKE2b-256 |
72f270f53f3b9b155d56afffe50233428d83d318f65e07694b102215e11ab65b
|
Provenance
The following attestation bundles were made for finansfatura-0.1.0.tar.gz:
Publisher:
publish.yml on finansfatura/ff-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
finansfatura-0.1.0.tar.gz -
Subject digest:
c50f5a3df6358609d4f410f6e69e5be7d188db2d3e984fefefffe6e7ebbbcb05 - Sigstore transparency entry: 2098252453
- Sigstore integration time:
-
Permalink:
finansfatura/ff-python@430fd6e396bb47f86f91c4e8ac823adb3b41e66c -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/finansfatura
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@430fd6e396bb47f86f91c4e8ac823adb3b41e66c -
Trigger Event:
push
-
Statement type:
File details
Details for the file finansfatura-0.1.0-py3-none-any.whl.
File metadata
- Download URL: finansfatura-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
faf2ecaf6472d422bc3232251c440c53d3d374cc48aeb7975f36d25bbb0e1bd7
|
|
| MD5 |
570aed174963a410ffaa3f489e182280
|
|
| BLAKE2b-256 |
12ec17f2ad635c22b7adb6670dac2bada84c3e094dfeccaf286bb7860cae45f1
|
Provenance
The following attestation bundles were made for finansfatura-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on finansfatura/ff-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
finansfatura-0.1.0-py3-none-any.whl -
Subject digest:
faf2ecaf6472d422bc3232251c440c53d3d374cc48aeb7975f36d25bbb0e1bd7 - Sigstore transparency entry: 2098252779
- Sigstore integration time:
-
Permalink:
finansfatura/ff-python@430fd6e396bb47f86f91c4e8ac823adb3b41e66c -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/finansfatura
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@430fd6e396bb47f86f91c4e8ac823adb3b41e66c -
Trigger Event:
push
-
Statement type: