Skip to main content

KSeF utils

ksef-utils Release ksef-utils Test PyPI version PyPI - Python Version Documentation Status

This project contains Python utilities and example requests that can be helpful when integrating with Polish central invoicing system called Krajowy System e-Faktur (KSeF).

Installation

Creating python virtual environment

See virtualenvwrapper documentation.

$ mkvirtualenv ksef
$ workon ksef
(ksef) $

Installing package from source

(ksef) $ git clone https://github.com/pprzetacznik/ksef-utils.git
(ksef) $ cd ksef-utils
(ksef) $ pip install -e .

Installing package from PyPI

(ksef) $ pip install ksef-utils

Run tests

Set up secrets

Log in to https://ksef-test.mf.gov.pl/web/ and generate your individual KSEF_TOKEN.

#!/bin/bash

export KSEF_TOKEN="..."
export KSEF_ENV="test"
export KSEF_NIP="..."
export KSEF_SIGN_CERT_PATH="cert.pem"
export KSEF_SIGN_KEY_PATH="privkey.pem"
export KSEF_SIGN_CA_PATH="cert.pem"

Generate test cert

KSEF_NIP=${KSEF_NIP:-2222222222}
KSEF_SUBJECT="/CN=John Doe/SN=Doe/GN=John/O=My Corp/C=PL/L=Lesser Voivodeship/serialNumber=NIP-${KSEF_NIP}/description=John Doe NIP-${KSEF_NIP}"
openssl req -x509 \
  -nodes \
  -subj "${KSEF_SUBJECT}" \
  -days 365 \
  -newkey rsa \
  -keyout $KSEF_SIGN_KEY_PATH \
  -out $KSEF_SIGN_CERT_PATH

Run pytest framework

(ksef) $ pip install -r requirements.txt
(ksef) $ pytest -svvv

Markers

Run all e2e/functional/current tests

(ksef) $ pytest -svvv tests/test_ksef.py -m "e2e and not ignore"
(ksef) $ pytest -svvv tests/test_ksef.py -m "functional and not ignore"
(ksef) $ pytest -svvv tests/test_ksef.py -m "current and not ignore"
(ksef) $ ./run_tests.sh
(ksef) $ TESTS_MARKERS="init_signed and functional and not ignore" ./run_tests.sh

Example

See tests/test_e2e.py for detailed examples of usage.

from ksef_utils.server import KSEFServer, KSEFService
from ksef_utils.config import TestConfig, DemoConfig, ProdConfig

config = TestConfig()
server = KSEFServer(config)
service = KSEFService(service)

invoice_data = {
    # ...
    # see tests/conftest.py for example json invoice
}

session_token = service.init_signed()
response_send_invoice = service.send_invoice(**invoice_data)

Using cli utilities

(ksef) $ python -m ksef_utils keygen --identifier 1111111111 --identifier_type NIP --working_directory .
(ksef) $ pip install .
(ksef) $ which ksef-utils
(...)/.envs/bin/ksef-utils
(ksef) $ ksef-utils keygen --identifier 1111111111 --identifier_type PESEL --working_directory .

OpenAPI

/openapi/gtw/svc/api/KSeF-common.yaml
/openapi/gtw/svc/api/KSeF-batch.yaml
/openapi/gtw/svc/api/KSeF-online.yaml

Publish new release

$ git tag v1.0
$ git push origin v1.0

Building documentation

(ksef) $ sphinx-build -M html docs docs_build

KSEF references

Contributing

Metadata

Release files for ksef-utils 1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ksef-utils 1.4
File Size Uploaded Provenance
ksef-utils-1.4.tar.gz 29.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ksef-utils 1.4
File Interpreter ABI Platform
ksef_utils-1.4-py3-none-any.whl Python 3 none any Details

Total release size: 43.1 kB

Release files / ksef-utils-1.4.tar.gz

Download URL ksef-utils-1.4.tar.gz
Size 29.5 kB
Tags Source
SHA-256 checksum
How to use checksums
adb18a4588aedfa47e30e4ed02c275838bf6e12316b66ef4fc80ef843fb8514d
BLAKE2b-256 checksum
How to use checksums
f8d8025ae474ced2148d157ab767335e1d65d88c6cce10d54143c377cd9d8acd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.10

Release files / ksef_utils-1.4-py3-none-any.whl

Download URL ksef_utils-1.4-py3-none-any.whl
Size 13.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
68eebfb9ad2b729be6f000a9143939a48abf21d9a70771c963c518861e907a86
BLAKE2b-256 checksum
How to use checksums
6c1b41ddbd03ec74a21c30695c1afb7031b6be6365e3e47e9cf2fc304f2ab302
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.11.10

Security for ksef-utils 1.4

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page