Raw endpoint interface for advanced KSeF integrations.
Classes
AsyncRawAuthenticatedClient
Import: from ksef2.raw import AsyncRawAuthenticatedClient
class AsyncRawAuthenticatedClientAsyncRawAuthenticatedClient(
*,
transport: AsyncMiddleware,
authed_transport: AsyncMiddleware,
environment: Environment,
)Raw authenticated endpoint facade for advanced async integrations.
Methods
AsyncRawAuthenticatedClient.auth (property)
auth: AsyncAuthEndpointsReturn raw authenticated authentication-session endpoints.
Returns
AsyncAuthEndpoints— Raw authenticated authentication-session endpoints.
AsyncRawAuthenticatedClient.certificates (property)
certificates: AsyncCertificatesEndpointsReturn raw certificate lifecycle endpoints.
Returns
AsyncCertificatesEndpoints— Raw certificate lifecycle endpoints.
AsyncRawAuthenticatedClient.encryption (property)
encryption: AsyncEncryptionEndpointsReturn raw public encryption-certificate endpoints.
Returns
AsyncEncryptionEndpoints— Raw public encryption-certificate endpoints.
AsyncRawAuthenticatedClient.invoices (property)
invoices: AsyncInvoicesEndpointsReturn raw invoice and invoice-session endpoints.
Returns
AsyncInvoicesEndpoints— Raw invoice and invoice-session endpoints.
AsyncRawAuthenticatedClient.limits (property)
limits: AsyncLimitEndpointsReturn raw limit endpoints.
Returns
AsyncLimitEndpoints— Raw limit endpoints.
AsyncRawAuthenticatedClient.collective_identifiers (property)
collective_identifiers: AsyncCollectiveIdentifiersEndpointsReturn raw collective invoice identifier endpoints.
Returns
AsyncCollectiveIdentifiersEndpoints— Raw collective invoice identifier endpoints.
AsyncRawAuthenticatedClient.peppol (property)
peppol: AsyncPeppolEndpointsReturn raw Peppol provider endpoints.
Returns
AsyncPeppolEndpoints— Raw Peppol provider endpoints.
AsyncRawAuthenticatedClient.permissions (property)
permissions: AsyncRawPermissionsEndpointsReturn raw permission endpoint groups.
Returns
AsyncRawPermissionsEndpoints— Raw permission endpoint groups.
AsyncRawAuthenticatedClient.session (property)
session: AsyncSessionEndpointsReturn raw online and batch session endpoints.
Returns
AsyncSessionEndpoints— Raw online and batch session endpoints.
AsyncRawAuthenticatedClient.testdata (property)
testdata: AsyncTestDataEndpointsReturn raw TEST-only data seeding endpoints.
Returns
AsyncTestDataEndpoints— Raw TEST-only data seeding endpoints.
AsyncRawAuthenticatedClient.tokens (property)
tokens: AsyncTokenEndpointsReturn raw token lifecycle endpoints.
Returns
AsyncTokenEndpoints— Raw token lifecycle endpoints.
AsyncRawClient
Import: from ksef2.raw import AsyncRawClient
class AsyncRawClientAsyncRawClient(transport: AsyncMiddleware, environment: Environment)Raw unauthenticated endpoint facade for advanced async integrations.
Methods
AsyncRawClient.auth (property)
auth: AsyncAuthEndpointsReturn raw authentication endpoints.
Returns
AsyncAuthEndpoints— Raw authentication endpoints.
AsyncRawClient.encryption (property)
encryption: AsyncEncryptionEndpointsReturn raw public encryption-certificate endpoints.
Returns
AsyncEncryptionEndpoints— Raw public encryption-certificate endpoints.
AsyncRawClient.peppol (property)
peppol: AsyncPeppolEndpointsReturn raw Peppol provider endpoints.
Returns
AsyncPeppolEndpoints— Raw Peppol provider endpoints.
AsyncRawClient.testdata (property)
testdata: AsyncTestDataEndpointsReturn raw TEST-only data seeding endpoints.
Returns
AsyncTestDataEndpoints— Raw TEST-only data seeding endpoints.
AsyncRawPermissionsEndpoints
Import: from ksef2.raw import AsyncRawPermissionsEndpoints
class AsyncRawPermissionsEndpointsAsyncRawPermissionsEndpoints(transport: AsyncMiddleware)Raw permission endpoint groups bound to one async transport.
Methods
AsyncRawPermissionsEndpoints.grant (property)
grant: AsyncPermissionsGrantEndpointsReturn permission grant endpoints.
Returns
AsyncPermissionsGrantEndpoints— Permission grant endpoints.
AsyncRawPermissionsEndpoints.revoke (property)
revoke: AsyncRevokePermissionsEndpointsReturn permission revocation endpoints.
Returns
AsyncRevokePermissionsEndpoints— Permission revocation endpoints.
AsyncRawPermissionsEndpoints.query (property)
query: AsyncQueryPermissionsEndpointsReturn permission query endpoints.
Returns
AsyncQueryPermissionsEndpoints— Permission query endpoints.
AsyncRawPermissionsEndpoints.status (property)
status: AsyncGetPermissionsEndpointsReturn permission operation status and role endpoints.
Returns
AsyncGetPermissionsEndpoints— Permission operation status and role endpoints.
RawAuthenticatedClient
Import: from ksef2.raw import RawAuthenticatedClient
class RawAuthenticatedClientRawAuthenticatedClient(
*,
transport: Middleware,
authed_transport: Middleware,
environment: Environment,
)Raw authenticated endpoint facade for advanced integrations.
Methods
RawAuthenticatedClient.auth (property)
auth: AuthEndpointsReturn raw authenticated authentication-session endpoints.
Returns
AuthEndpoints— Raw authenticated authentication-session endpoints.
RawAuthenticatedClient.certificates (property)
certificates: CertificatesEndpointsReturn raw certificate lifecycle endpoints.
Returns
CertificatesEndpoints— Raw certificate lifecycle endpoints.
RawAuthenticatedClient.encryption (property)
encryption: EncryptionEndpointsReturn raw public encryption-certificate endpoints.
Returns
EncryptionEndpoints— Raw public encryption-certificate endpoints.
RawAuthenticatedClient.invoices (property)
invoices: InvoicesEndpointsReturn raw invoice and invoice-session endpoints.
Returns
InvoicesEndpoints— Raw invoice and invoice-session endpoints.
RawAuthenticatedClient.limits (property)
limits: LimitEndpointsReturn raw limit endpoints.
Returns
LimitEndpoints— Raw limit endpoints.
RawAuthenticatedClient.collective_identifiers (property)
collective_identifiers: CollectiveIdentifiersEndpointsReturn raw collective invoice identifier endpoints.
Returns
CollectiveIdentifiersEndpoints— Raw collective invoice identifier endpoints.
RawAuthenticatedClient.peppol (property)
peppol: PeppolEndpointsReturn raw Peppol provider endpoints.
Returns
PeppolEndpoints— Raw Peppol provider endpoints.
RawAuthenticatedClient.permissions (property)
permissions: RawPermissionsEndpointsReturn raw permission endpoint groups.
Returns
RawPermissionsEndpoints— Raw permission endpoint groups.
RawAuthenticatedClient.session (property)
session: SessionEndpointsReturn raw online and batch session endpoints.
Returns
SessionEndpoints— Raw online and batch session endpoints.
RawAuthenticatedClient.testdata (property)
testdata: TestDataEndpointsReturn raw TEST-only data seeding endpoints.
Returns
TestDataEndpoints— Raw TEST-only data seeding endpoints.
RawAuthenticatedClient.tokens (property)
tokens: TokenEndpointsReturn raw token lifecycle endpoints.
Returns
TokenEndpoints— Raw token lifecycle endpoints.
RawClient
Import: from ksef2.raw import RawClient
class RawClientRawClient(transport: Middleware, environment: Environment)Raw unauthenticated endpoint facade for advanced integrations.
Methods
RawClient.auth (property)
auth: AuthEndpointsReturn raw authentication endpoints.
Returns
AuthEndpoints— Raw authentication endpoints.
RawClient.encryption (property)
encryption: EncryptionEndpointsReturn raw public encryption-certificate endpoints.
Returns
EncryptionEndpoints— Raw public encryption-certificate endpoints.
RawClient.peppol (property)
peppol: PeppolEndpointsReturn raw Peppol provider endpoints.
Returns
PeppolEndpoints— Raw Peppol provider endpoints.
RawClient.testdata (property)
testdata: TestDataEndpointsReturn raw TEST-only data seeding endpoints.
Returns
TestDataEndpoints— Raw TEST-only data seeding endpoints.
RawPermissionsEndpoints
Import: from ksef2.raw import RawPermissionsEndpoints
class RawPermissionsEndpointsRawPermissionsEndpoints(transport: Middleware)Raw permission endpoint groups bound to one transport.
Methods
RawPermissionsEndpoints.grant (property)
grant: PermissionsGrantEndpointsReturn permission grant endpoints.
Returns
PermissionsGrantEndpoints— Permission grant endpoints.
RawPermissionsEndpoints.revoke (property)
revoke: RevokePermissionsEndpointsReturn permission revocation endpoints.
Returns
RevokePermissionsEndpoints— Permission revocation endpoints.
RawPermissionsEndpoints.query (property)
query: QueryPermissionsEndpointsReturn permission query endpoints.
Returns
QueryPermissionsEndpoints— Permission query endpoints.
RawPermissionsEndpoints.status (property)
status: GetPermissionsEndpointsReturn permission operation status and role endpoints.
Returns
GetPermissionsEndpoints— Permission operation status and role endpoints.
Functions
encrypt_invoice
Import: from ksef2.raw import encrypt_invoice
def encrypt_invoice(xml_bytes: bytes, key: bytes, iv: bytes) -> bytesAES-256-CBC encrypt xml_bytes with PKCS#7 padding.
Parameters
xml_bytes(bytes) — Plain invoice XML bytes.key(bytes) — 32-byte AES-256 key.iv(bytes) — 16-byte initialization vector.
Returns
bytes— The raw ciphertext bytes. The caller is responsible for Base64 encoding.
Raises
KSeFEncryptionError— If encryption fails, for example because of an invalid key length.
encrypt_symmetric_key
Import: from ksef2.raw import encrypt_symmetric_key
def encrypt_symmetric_key(key: bytes, cert_b64: str) -> bytesRSA-OAEP encrypt an AES key with a KSeF public-key certificate.
Parameters
key(bytes) — AES key to encrypt.cert_b64(str) — Base64-encoded DER certificate containing the RSA public key.
Returns
bytes— The raw ciphertext bytes. The caller is responsible for Base64 encoding.
Raises
KSeFEncryptionError— If the certificate cannot be loaded or encryption fails.
encrypt_token
Import: from ksef2.raw import encrypt_token
def encrypt_token(token: str, timestamp: str, cert_b64: str) -> strRSA-OAEP encrypt token|timestamp and return Base64.
Parameters
token(str) — KSeF token.timestamp(str) — Challenge timestamp in Unix milliseconds, as a string.cert_b64(str) — Base64-encoded DER certificate containing the RSA public key.
Returns
str— The Base64-encoded ciphertext.
Raises
KSeFEncryptionError— If the certificate cannot be loaded or encryption fails.
generate_session_key
Import: from ksef2.raw import generate_session_key
def generate_session_key() -> tuple[bytes, bytes]Generate a random AES-256 key (32 bytes) and IV (16 bytes).
Returns
tuple[bytes, bytes]— A tuple of the AES key and the initialization vector.
prepare_batch_package
Import: from ksef2.raw import prepare_batch_package
def prepare_batch_package(
*,
invoices: Iterable[BatchInvoice],
aes_key: bytes,
iv: bytes,
encrypted_key: bytes,
public_key_id: str | None = None,
form_code: FormSchema = FormSchema.FA3,
offline_mode: bool = False,
max_part_size: int = MAX_BATCH_PART_SIZE,
) -> PreparedBatchBuild, split, and encrypt a batch package from invoice payloads.
Parameters
invoices(Iterable[BatchInvoice]) — Invoices to include; each becomes one ZIP entry.aes_key(bytes) — AES-256 key used to encrypt the parts.iv(bytes) — AES initialization vector.encrypted_key(bytes) —aes_keyencrypted with the KSeF public key.public_key_id(str | None) — Identifier of the KSeF public key used forencrypted_key;Nonefor the default.form_code(FormSchema) — Invoice schema of the batch.offline_mode(bool) — Whether the invoices were issued in offline mode.max_part_size(int) — Maximum size in bytes of one encrypted part.
Returns
PreparedBatch— The prepared batch: package metadata, encrypted parts and encryption material.
Raises
KSeFEncryptionError— If part encryption fails.KSeFValidationError— If the invoice list or part size is invalid.
sha256_b64
Import: from ksef2.raw import sha256_b64
def sha256_b64(data: bytes) -> strReturn the SHA-256 digest of data as a Base64-encoded string.
Parameters
data(bytes) — Bytes to hash.
Returns
str— The Base64-encoded digest.
Submodules
auth
Import: import ksef2.raw.auth
batch
Import: import ksef2.raw.batch
Supplementary models for batch session operations.
These models shadow the spec models with str instead of Base64Str fields to allow easier construction in mappers.
certificates
Import: import ksef2.raw.certificates
Supplementary models for certificate operations.
These models shadow generated schema models that use Base64Str fields so the SDK can pass already-base64-encoded request data without double decoding.
encryption
Import: import ksef2.raw.encryption
invoices
Import: import ksef2.raw.invoices
peppol
Import: import ksef2.raw.peppol
permissions
Import: import ksef2.raw.permissions
session
Import: import ksef2.raw.session
spec
Import: import ksef2.raw.spec
supp
Import: import ksef2.raw.supp
testdata
Import: import ksef2.raw.testdata
