ksefe
Official async Python SDK for the Ksefe API — a JSON-first REST gateway over Poland's KSeF e-invoicing system. Generated from the API's OpenAPI 3.1 description with Kiota.
Install
pip install ksefe
Published on PyPI from 0.1.0.
Requires Python 3.10+.
Quickstart (async)
import asyncio
from ksefe import ApiKeyAuthenticationProvider, HttpxRequestAdapter, KeyLocation, KsefeClient, unwrap
from ksefe.models import (
CreateContext,
CreateContext_environment,
EntityCreate,
EntityCreate_kind,
EntityCreate_taxIdKind,
)
async def main() -> None:
api_key = "..."
ksefe = KsefeClient(
HttpxRequestAdapter(
ApiKeyAuthenticationProvider(KeyLocation.Header, f"Bearer {api_key}", "Authorization")
)
)
entity = await ksefe.entities.post(
EntityCreate(
kind=EntityCreate_kind.Company,
name="Example sp. z o.o.",
country_code="PL",
tax_id="5265877635",
tax_id_kind=EntityCreate_taxIdKind.Nip,
)
)
context = await ksefe.ksef.contexts.post(
CreateContext(
entity_id=entity.id, name="Example", environment=CreateContext_environment.Test
)
)
submission = unwrap(await ksefe.ksef.submissions.by_id(submission_id).get())
upo = await ksefe.ksef.submissions.by_id(submission_id).upo.get()
invoices = await ksefe.ksef.invoices.get()
vat = await ksefe.vat.by_tax_id("5265877635").get()
asyncio.run(main())
Models and enums import from ksefe.models, and models take keyword arguments.
Enum fields take the enum member (EntityCreate_kind.Company); a plain string
raises TypeError naming the field, before anything is sent.
KSeF TEST needs no certificate: the API generates a self-signed one. For demo
and prod, pass your KSeF certificate as base64 PKCS#12 (or a PEM pair):
from ksefe.models import CertificateUpload
await ksefe.ksef.contexts.post(CreateContext(
entity_id=entity.id,
name="Production",
environment=CreateContext_environment.Prod,
certificate=CertificateUpload(pkcs12=p12_base64, password=password),
))
API shape
A Kiota fluent client — async.
Resources mirror the URL structure: client.entities, client.ksef.contexts,
client.ksef.submissions, client.ksef.invoices, client.integrations,
client.bank.connections, client.bank.transactions, client.vat. Path
parameters are by_id(…) / by_ksef_number(…) / by_tax_id(…), and the HTTP verb is the
terminal awaited call (await …get(), await …post(body)). Every model and enum
is importable from ksefe.models.
Pagination
Listings are cursor-paginated: each page returns next_cursor, which you pass
back as cursor. The paginate async iterator walks every page for you. Give it
the listing's request builder and its filters:
from ksefe import paginate
async for invoice in paginate(ksefe.ksef.invoices, context_id=[context.id]):
print(invoice.ksef_number)
Filters use the Python names of the listing's query parameters and are sent
unchanged on every page; an unknown one raises TypeError before any request.
Pass page_size=… to change the page size (default 50, maximum 100).
Auth & errors
The client is the one Kiota
generates: a request adapter with an authentication provider, here an API key sent
as Authorization: Bearer <api_key> on every request. Error responses
(RFC 9457 application/problem+json) are raised as Problem exceptions carrying
status, title and detail. Detect them with is_ksefe_error:
from ksefe import is_ksefe_error
try:
await ksefe.ksef.contexts.post(body)
except Exception as err:
if is_ksefe_error(err):
print(err.status, err.detail)
else:
raise
A full runnable flow (entity → context → submit → poll → UPO, plus pagination)
is in examples/quickstart.py.
Configuration
The client targets https://ksefe.pl/api/v1. To use another deployment, set the
base URL on the adapter before constructing the client; pass an httpx.AsyncClient
for proxies or custom transports:
import httpx
adapter = HttpxRequestAdapter(
ApiKeyAuthenticationProvider(KeyLocation.Header, f"Bearer {api_key}", "Authorization"),
http_client=httpx.AsyncClient(proxy="http://proxy.example:8080"),
)
adapter.base_url = "https://staging.example/api/v1"
ksefe = KsefeClient(adapter)
The client serializes request bodies strictly: an enum field holding a plain
string raises TypeError instead of being dropped. Kiota keeps one serializer
registry per process, so if you also use another Kiota-generated client, construct
it before this one.
License
MIT. Generated code is regenerated from the OpenAPI spec — do not edit
ksefe/_generated/** or ksefe/models.py by hand.
Metadata
Release files for ksefe 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| ksefe-0.2.0.tar.gz | 129.4 kB | With provenance | Details for ksefe-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| ksefe-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for ksefe-0.2.0-py3-none-any.whl |
Total release size: 531.9 kB
Release files / ksefe-0.2.0.tar.gz
| Download URL | ksefe-0.2.0.tar.gz |
|---|---|
| Size | 129.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fa3a9f666190acfbeb63f87759b3aae3615fe6a1051a9f0518d5d01a1ae2bcac
|
|
BLAKE2b-256 checksum How to use checksums |
a78a96cd8466bfb6b07c01375c3325a0cf571c372ef5d05be7ba77c32e75bf72
|
| 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 Nov 24, 2026.
Transparency logRelease files / ksefe-0.2.0-py3-none-any.whl
| Download URL | ksefe-0.2.0-py3-none-any.whl |
|---|---|
| Size | 402.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c583d0fbcf911188c1f37e03b0cdfd1ae066bfd1bd2b06364a5abb944289eca2
|
|
BLAKE2b-256 checksum How to use checksums |
ef0ea9e1af33d2fde6c8a1bd00439500aa2743c02a3575672abcc84f712658a1
|
| 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 Nov 24, 2026.
Transparency logSecurity for ksefe 0.2.0
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.
Attestation for ksefe-0.2.0.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 Nov 24, 2026.
Transparency logA 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.