Use local profiles, environment-backed authentication, JSON output, and resumable workflow files to automate KSeF invoicing from shells, CI jobs, and operational scripts.
ksef2-cli exposes the ksef2
Python SDK as a command-line tool. It is designed for developers and operators
who want to authenticate with KSeF, query invoice metadata, send invoices,
download invoice XML, export packages, inspect sessions, and manage
administrative resources without writing Python code.
The CLI avoids hidden state by default. Commands can read credentials from global options or environment variables, while local profiles store reusable non-secret defaults such as environment, NIP, auth method, certificate paths, and secret environment variable names.
This project is not published, endorsed, or supported by Poland's Ministry of Finance. Official KSeF documentation remains the source of truth for API behavior.
uv tool install ksef2-clior:
pipx install ksef2-cliThe package exposes two equivalent executables:
ksef2 --help
ksef2-cli --helpRequires Python 3.12 or newer.
For repeated local work, create a profile once and let commands inherit its environment, NIP, and authentication settings:
ksef2 profile create test-company \
--env test \
--nip 5261040828 \
--test-cert
ksef2 --profile test-company --json auth loginFor CI and one-off scripts, pass global options before the command group:
ksef2 --nip "$KSEF2_NIP" --token "$KSEF2_TOKEN" --json \
invoices metadata \
--role seller \
--date-from 2026-01-01T00:00:00Z \
--allSupported direct authentication methods:
--tokenorKSEF2_TOKEN--test-certfor the TEST environment--certand--keyfor PEM XAdES credentials--p12for PKCS#12/PFX XAdES credentials
Send one XML invoice, wait for processing, save a UPO, and keep a receipt for later status checks:
ksef2 --profile test-company \
invoices send invoice.xml \
--wait \
--upo-dir upos \
--receipt invoice-receipt.jsonDownload the UPO later from the saved receipt:
ksef2 --profile test-company \
invoices upo \
--receipt invoice-receipt.json \
--out invoice-upo.xmlSubmit many XML files as one batch:
ksef2 --nip "$KSEF2_NIP" --token "$KSEF2_TOKEN" \
invoices send invoice-1.xml invoice-2.xml \
--mode batch \
--wait \
--upo-dir uposUse --json before the command group when output is consumed by scripts.
- Online docs: https://docs.stacking.me/ksef2/cli/intro/
- Installation: https://docs.stacking.me/ksef2/cli/getting-started/installation/
- Quickstart: https://docs.stacking.me/ksef2/cli/getting-started/quickstart/
- Command reference: https://docs.stacking.me/ksef2/cli/reference/commands/
- Source docs:
docs - SDK repository:
stacking-hq/ksef2
uv sync --all-groups
uv run ksef2 --help
uv run python -m coverage run -m pytest -q
uv run python scripts/validate_docs_frontmatter.py docs/The CLI command domains live under src/ksef2_cli/commands/. Source
documentation lives under docs/.
Issues and pull requests are welcome. Before opening a PR, run the focused test or docs check that covers your change, and update source docs when command behavior changes.