GitHub

Low-level API

Schema-native endpoint wrappers, raw model namespaces, and low-level utility exports.

On this page

The low-level API is the SDK surface for endpoint-level control without leaving the SDK transport stack. It is exposed through client.raw before authentication and auth.raw after authentication.

Use it when a KSeF integration needs custom signing, caller-owned encryption custody, exact OpenAPI-shaped payloads, or endpoint debugging. Most application workflows should still start with the high-level clients.

Contract

PropertyLow-level behavior
TransportReuses the same root-client middleware stack, retries, lifecycle checks, and exception mapping.
Authenticationclient.raw is unauthenticated; auth.raw uses the authenticated bearer transport where KSeF requires it.
ModelsRequest and response objects use schema-native KSeF/OpenAPI field names such as referenceNumber, publicKeyId, and authenticationToken.
ParsingSuccessful JSON responses are parsed into generated spec or supplemental supp Pydantic models.
Binary responsesInvoice XML and UPO downloads return bytes.
Async shapeAsync low-level clients expose the same branch and method names, with awaited network calls.

Model namespaces

Import supported low-level models from ksef2.raw, not from internal generated packages:

from ksef2.raw import spec, supp
python
NamespaceUse for
specGenerated OpenAPI request and response models.
suppSupplemental models used where generated OpenAPI shapes need SDK-side support.
ksef2.raw.mappersExplicit bridges from schema-native models back to public SDK models.

Utility exports

ExportUse for
encrypt_tokenEncrypt KSeF token authentication payloads.
generate_session_keyGenerate AES key and IV for invoice/session/export encryption.
encrypt_symmetric_keyEncrypt local AES material with a KSeF public certificate.
encrypt_invoiceEncrypt invoice XML bytes for low-level online submission.
sha256_b64Calculate base64 SHA-256 hashes for low-level payload metadata.
prepare_batch_packageBuild encrypted batch package metadata when caller owns low-level batch flow.

Levels of control

LevelSDK ownsCaller ownsTypical entry point
WorkflowEndpoint order, encryption, polling, and model mapping.Business inputs and persistence.auth.invoices, auth.batch, session clients.
Step-levelProtocol details for one SDK workflow step.Ordering and persistence between steps.session.send_invoice(), submission.wait().
Low-levelTransport, response parsing, exception mapping.Endpoint order, schema-native payloads, encryption custody, polling.client.raw, auth.raw.

The main ownership rule is session consistency: if low-level code opens a session, low-level code should usually close and inspect that session. If high-level code opens a session, use the returned high-level session client.

Low-level section