fv-cli

module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2026 License: MIT

README

fv

Command-line tool for issuing Polish VAT invoices (FA(3)) and sending them to KSeF 2.0.

fv builds an invoice from one amount and a buyer alias (fv issue --to acme --net "18500,43"), keeps it as a local draft, and sends it to KSeF only when you say so (fv send). Seller and buyer are configured by tax number; their name, address and VAT status come from the MF White List and EU VIES. It logs in to KSeF with your KSeF certificate (XAdES), encrypts the invoice for the session, and keeps the KSeF number and the UPO in a local archive. It is one static binary for Windows, macOS and Linux, written for people who invoice from a terminal and want a small, auditable tool instead of a web form.

Features

  • One command from amount to draft: seller, buyer, dates, VAT rate, bank account and numbering come from a small config.toml.
  • Buyers are looked up by NIP (MF White List) or EU VAT ID (VIES) and cached; the VAT status is checked and shown on every invoice.
  • Exact money arithmetic in grosze (no floating point); Polish and English decimal input, with documented shell quoting.
  • Foreign currency invoices with the NBP exchange rate.
  • Several lines per invoice, saved items you bill by key (--item dev=160), ad-hoc lines (--line), and the bank name and SWIFT written next to the account.
  • FA(3) XML generated and validated against the official schema.
  • KSeF login with a certificate (XAdES), session encryption, one-shot send with a 120 s verdict poll, UPO stored with the invoice.
  • Safe by default: nothing is sent without confirmation; PROD needs a typed PRODUCTION; an unknown outcome blocks a resend until fv status resolves it.
  • fv list and fv show cover sales and purchases from KSeF, not only what you issued with fv.
  • Local archive with sequential numbering under an OS lock, immutable sent XML with a stored SHA-256.
  • Secrets in the OS keyring (Windows Credential Manager, macOS Keychain, Secret Service), redacted from logs and output.
  • Documented exit codes for scripting; every command has --help with examples.

Status

Verified live against the KSeF DEMO environment on 2026-10-31: certificate (XAdES) login, and PLN and EUR invoices accepted with a UPO. The TEST and PROD environments have not been exercised yet.

This project is not affiliated with the Polish Ministry of Finance (Ministerstwo Finansów) or the KSeF programme. It is not tax or accounting advice. Check every invoice before you send it, and use fv at your own risk.

Getting started

This walks you from nothing to a first invoice accepted by KSeF, on the DEMO environment, which has no tax effect. Commands are shown for Windows (PowerShell), macOS and Linux where they differ. The names and numbers (NIP 5555555555, "Jan Kowalski", the buyer acme) are made up.

1. Install

The short way, with Go 1.26.10 or newer (an older Go from 1.21 on downloads that toolchain by itself):

go install github.com/lwasak/fv-cli/cmd/fv@latest

The binary (fv, or fv.exe on Windows) lands in GOBIN, or in $(go env GOPATH)/bin when that is not set (go env GOPATH shows the folder). That folder must be on your PATH; if fv is not found afterwards, add it:

# Windows (PowerShell), then open a new terminal
[Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", "User") + ";$(go env GOPATH)\bin", "User")
# macOS and Linux, in ~/.profile or your shell's rc file
export PATH="$PATH:$(go env GOPATH)/bin"

The binary is built on your machine, so macOS and Windows do not quarantine or block it.

Without Go, download the archive for your platform from the Releases page: windows_amd64 (.zip), darwin_arm64 (Apple silicon), darwin_amd64 (Intel), linux_amd64 or linux_arm64 (.tar.gz), plus checksums.txt. Check the archive against checksums.txt before you run anything from it.

Windows (PowerShell):

Get-FileHash .\fv_*_windows_amd64.zip -Algorithm SHA256     # compare with the line in checksums.txt
Expand-Archive .\fv_*_windows_amd64.zip -DestinationPath .\fv-unpacked
New-Item -ItemType Directory -Force "$env:LOCALAPPDATA\Programs\fv" | Out-Null
Copy-Item .\fv-unpacked\fv.exe "$env:LOCALAPPDATA\Programs\fv\fv.exe"
$bin = "$env:LOCALAPPDATA\Programs\fv"
[Environment]::SetEnvironmentVariable("Path", [Environment]::GetEnvironmentVariable("Path", "User") + ";$bin", "User")
Unblock-File "$bin\fv.exe"            # only if the archive came from a browser and Windows blocks it

Open a new terminal so the new PATH is picked up.

macOS and Linux:

sha256sum --check --ignore-missing checksums.txt             # macOS: shasum -a 256 --check --ignore-missing checksums.txt
tar -xzf fv_*_linux_amd64.tar.gz                             # use the darwin archive on a Mac
mkdir -p ~/.local/bin && install -m 0755 fv ~/.local/bin/fv  # or: sudo install -m 0755 fv /usr/local/bin/fv
xattr -d com.apple.quarantine ~/.local/bin/fv                # macOS only, if the archive came from a browser

Make sure ~/.local/bin is on your PATH. The binaries are not code-signed, which is why macOS and Windows may block a browser download; a file fetched with curl is not affected.

Check it:

fv version

More per-OS detail: docs/install.md.

2. Get a KSeF certificate

fv logs in to KSeF with a certificate, not a token. KSeF issues it in the taxpayer application, "Aplikacja Podatnika KSeF 2.0", in its certificates module. Each environment has its own application, and a certificate works only in the environment that issued it:

Environment Application Data
DEMO (start here) https://ap-demo.ksef.mf.gov.pl Your real login identity, fictitious invoice data, no tax effect.
TEST https://ap-test.ksef.mf.gov.pl Fictitious data shared with other users.
PROD https://ap.ksef.mf.gov.pl Legally binding.
  1. Log in to the DEMO application with Profil Zaufany, a qualified signature or an existing KSeF certificate.
  2. Request a certificate of type Authentication (not Offline: an Offline certificate cannot log in).
  3. Choose a strong password for the private key and keep it in a password manager. fv refuses an unencrypted key.
  4. Download the certificate (.crt or .pem) and the encrypted private key (.key), or a single .p12 file.

A personal certificate carries your PESEL, not a NIP. That is fine: fv logs in with your seller NIP as the context, and KSeF checks that you are authorised to act for that NIP. A certificate that does carry a NIP must match your seller NIP. Details: docs/setup.md.

3. Configure with fv init
fv --env demo init

fv init asks for your seller NIP, the environment and your bank account (IBAN, optional), writes a minimal config.toml, and offers to import the certificate. Answer y and give the paths; the passphrase is typed without echo and stored in the OS keyring (Windows Credential Manager, macOS Keychain, Linux Secret Service).

Seller NIP (10 digits): 5555555555
KSeF environment (test/demo/prod) [test]: demo
Seller bank account, IBAN (optional, empty to skip): PL61 1090 1014 0000 0712 1981 2874
config written: C:\Users\you\AppData\Roaming\fv\config.toml
Import a KSeF certificate for demo/5555555555? [y/N] y
Certificate file (.p12/.pfx, or .pem/.crt): C:\keys\ksef-demo.crt
Encrypted private key file (.pem/.key; empty if the certificate file holds it): C:\keys\ksef-demo.key
Key passphrase:
certificate imported for demo/5555555555

fv keeps its own encrypted copy, so delete the downloaded files afterwards. To skip the questions (for a script), pass the files and supply the passphrase in an environment variable, which is then not written to the keyring:

$env:FV_SECRET_KSEF_DEMO_5555555555 = Read-Host "KSeF key passphrase"
fv --env demo init --import-cert C:\keys\ksef-demo.crt --import-key C:\keys\ksef-demo.key

The variable is named FV_SECRET_KSEF_<ENV>_<NIP>. On macOS and Linux use export FV_SECRET_KSEF_DEMO_5555555555=... (or read -rs).

The account is written as defaults.bank_account (--bank-account gives it without the question), so you can issue an invoice right after init; pass --rate or set a VAT rate and any other defaults in the config file. Where the file lives, and a fuller example:

OS Config file Data (archive, certificate)
Windows %AppData%\fv\config.toml %LocalAppData%\fv
macOS ~/Library/Application Support/fv/config.toml ~/Library/Application Support/fv
Linux ~/.config/fv/config.toml ~/.local/share/fv
[ksef]
environment = "demo"

[seller]
nip = "5555555555"
place_of_issue = "Gdańsk"

[defaults]
vat_rate = "23"
bank_account = "PL61 1090 1014 0000 0712 1981 2874"

Check the file with fv config validate. All keys: docs/config-reference.md.

4. Test the login
fv ksef check

This does a real login to KSeF and prints what it found:

environment: demo
subject: CN=JAN KOWALSKI (uwierzytelnienie),SN=KOWALSKI,GN=JAN,SERIALNUMBER=PNOPL-…,C=PL
identifier: PESEL
nip: 5555555555 (context; none in certificate)
type: KSeF Authentication
validity: …
authenticated: OK

authenticated: OK means the certificate, the passphrase and your permissions for the NIP all work. Exit code 3 means they do not; see docs/troubleshooting.md.

5. Add a buyer
fv party add acme --nip 5252248481

fv looks the NIP up in the MF White List and adds [parties.acme] to your config. For a buyer the White List does not know, give the details yourself with --name and --address; for an EU buyer use --vat-id DE123456789 (looked up in VIES). fv party show acme shows what was found. See docs/parties.md.

6. Issue a draft
fv issue --to acme --net "1,00"

This creates a local draft and reserves the next invoice number. Nothing is sent. Quote the amount: PowerShell and other shells can mangle an unquoted comma (docs/amounts.md).

ENVIRONMENT: DEMO

Invoice:   FV/2026/10/001   [draft]
...
  No                 Description  Qty  Unit  Price   Net  Rate
   1  Usługi za październik 2026    1  usł.   1,00  1,00   23%

  Rate   Net   VAT  Gross
   23%  1,00  0,23   1,23
Total:     1,23 PLN
...
Nothing was sent to KSeF. To send: fv send FV/2026/10/001

Look at it with fv show FV/2026/10/001, or at the exact XML that would be sent with fv show FV/2026/10/001 --xml.

Bill the same things every month. Save what you sell as an item in config.toml (quote the price), then bill it by key, with a quantity if you like:

[items.dev]
name = "Programming services {month_name_en} {year}"
unit = "h"
unit_price = "120,00"
fv issue --to acme --item dev=160

Add more --item or --line "desc=Hosting; price=19,99" flags for more lines, or list the items in [parties.acme] (items = ["dev"]) and run fv issue --to acme with nothing else. See docs/workflow.md.

7. Send it to DEMO
fv send FV/2026/10/001

fv shows the invoice again and asks, naming the environment:

Send invoice FV/2026/10/001 to KSeF DEMO? [y/N] y
Sent FV/2026/10/001 to KSeF DEMO.
KSeF number: 5260250274-20261031-0100001AF62C-27
UPO:         stored (upo.xml)

The KSeF number is the invoice's permanent identifier and the UPO is KSeF's official confirmation of receipt; both are kept in the local archive. On TEST and DEMO, --yes skips the question (for scripts). If the answer was lost (exit code 5), fv status FV/2026/10/001 asks KSeF and settles it. See the next step for fv list.

8. List and show invoices
fv list
fv list --month 2026-10 --as buyer
fv show 5260250274-20261031-0100001AF62C-27

fv list shows the invoices of the selected environment for the last three months including the current one: your sales and your purchases, read from KSeF and merged with your archive, so an invoice you sent with fv appears once with its state and an invoice that exists only in KSeF has the state ksef. --from and --to (YYYY-MM-DD) or --month YYYY-MM choose the issue dates, --as seller or --as buyer limits it to sales or purchases, --offline asks nothing and shows the archive and the rows cached earlier, and --wide adds full names, NIPs and KSeF numbers. KSeF limits metadata queries to 20 per hour; see Troubleshooting.

fv show works for any invoice fv list shows: give its KSeF number, or its invoice number if only one invoice in KSeF has it. An invoice that is not stored yet is downloaded once and kept in a local cache; --xml prints it exactly as KSeF served it. An invoice number fv has not seen is looked up in KSeF over the last three months, or over --from/--to; --offline asks KSeF nothing.

9. Go to production
  1. Get a PROD certificate from https://ap.ksef.mf.gov.pl, the same way as in step 2.
  2. Import it: fv --env prod init. Answer N to the overwrite question and y to the import question.
  3. Test it:
fv --env prod ksef check
  1. Issue and send with --env prod. A PROD send is legally binding and needs you to type PRODUCTION; --yes never skips that.
  2. When you are ready to work in production by default, set environment = "prod" under [ksef] in the config. Numbering, archive and credentials are separate per environment, so DEMO drafts never go to PROD.
10. Where to go next

Security

  • The KSeF private key is stored encrypted as you imported it; it is decrypted in memory for one signature and not kept. The passphrase is never a flag or a config value: OS keyring, environment variable or a no-echo prompt.
  • Passphrases, tokens and PESEL are redacted from logs and output. All files are user-only (0600/0700, protected ACL on Windows) and written atomically.
  • TLS 1.2+ with the system trust store, no option to skip verification, fixed service addresses, no redirects. A send is posted once and never retried.
  • The local archive is not encrypted and holds buyer names and addresses: use full-disk encryption and protect backups.

Read docs/security.md for what fv protects and what you must protect.

Documentation

The user guide is in docs/: install, setup, parties, workflow, amounts, numbering and archive, exit codes, troubleshooting, security, the config reference and the design decisions. Every command also has --help.

Development

CI runs through Dagger (engine v0.21.11, Go SDK; module in ci/), so the same pipeline runs locally and on GitHub Actions. It needs a container engine.

dagger call check                         # gofmt, vet, tests (incl. XSD golden), cross-builds, govulncheck, gosec
dagger call build export --path=dist      # snapshot release archives in ./dist

Or with plain Go (1.26.10+; xmllint from libxml2 enables the XSD golden test):

gofmt -l .                                # must print nothing
go vet ./...
go test ./...
go build ./cmd/fv

The Go test in internal/live (build tag kseflive, see Troubleshooting) runs a manual live check against KSeF TEST or DEMO in an isolated temporary config; it needs your own certificate and refuses PROD.

Releasing

Releases are built by GoReleaser inside the Dagger pipeline when a version tag is pushed:

git tag v0.1.0 && git push origin v0.1.0

The release workflow publishes the archives, checksums.txt and a GitHub-generated changelog.

License

MIT © 2026 Łukasz Wasak.

Directories

Path Synopsis
cmd
fv command
Command fv issues Polish VAT invoices and sends them to KSeF.
Command fv issues Polish VAT invoices and sends them to KSeF.
internal
cli
Package cli holds the Cobra command tree of fv.
Package cli holds the Cobra command tree of fv.
config
Package config locates, loads and resolves fv's configuration.
Package config locates, loads and resolves fv's configuration.
credentials
Package credentials imports, stores, inspects and uses the KSeF login certificate.
Package credentials imports, stores, inspects and uses the KSeF login certificate.
credentials/credtest
Package credtest generates throwaway certificates and keys for tests.
Package credtest generates throwaway certificates and keys for tests.
exitcode
Package exitcode maps sentinel errors to fv process exit codes, so packages can tag their errors without importing the cli package.
Package exitcode maps sentinel errors to fv process exit codes, so packages can tag their errors without importing the cli package.
fa3
Package fa3 builds FA(3) invoice XML (KSeF schema 1-0E) deterministically from already computed amounts, and ships the vendored XSD used to validate it.
Package fa3 builds FA(3) invoice XML (KSeF schema 1-0E) deterministically from already computed amounts, and ships the vendored XSD used to validate it.
fsafe
Package fsafe is the one place fv creates files and directories.
Package fsafe is the one place fv creates files and directories.
httpx
Package httpx is the hardened HTTPS client for fv's non-KSeF services (White List, VIES, NBP).
Package httpx is the hardened HTTPS client for fv's non-KSeF services (White List, VIES, NBP).
invoice
Package invoice is the pure computation behind "fv issue": dates, the line description template and the amounts.
Package invoice is the pure computation behind "fv issue": dates, the line description template and the amounts.
ksef
Package ksef is fv's client for the KSeF 2.0 API: fixed per-environment base URLs, a hardened HTTPS transport, KSeF error decoding, safe request logging, the cache of the Ministry of Finance public-key certificates and the certificate login flow.
Package ksef is fv's client for the KSeF 2.0 API: fixed per-environment base URLs, a hardened HTTPS transport, KSeF error decoding, safe request logging, the cache of the Ministry of Finance public-key certificates and the certificate login flow.
ksef/ksefake
Package ksefake is a scripted TLS test server standing in for the KSeF API.
Package ksefake is a scripted TLS test server standing in for the KSeF API.
ksefcache
Package ksefcache is the local copy of what KSeF told fv about invoices: the metadata that fv list collects and the XML that fv show downloads.
Package ksefcache is the local copy of what KSeF told fv about invoices: the metadata that fv list collects and the XML that fv show downloads.
listing
Package listing decides what fv list shows: the date range and the merge of the local archive with the invoices KSeF reports.
Package listing decides what fv list shows: the date range and the merge of the local archive with the invoices KSeF reports.
logging
Package logging provides fv's structured log (fv.log) and the process-wide secret redactor that keeps registered secret values out of log files and printed errors.
Package logging provides fv's structured log (fv.log) and the process-wide secret redactor that keeps registered secret values out of log files and printed errors.
money
Package money holds locale-agnostic amount parsing and VAT arithmetic.
Package money holds locale-agnostic amount parsing and VAT arithmetic.
nbp
Package nbp is the client for the NBP table A (average rates) API.
Package nbp is the client for the NBP table A (average rates) API.
numbering
Package numbering renders invoice numbers from a pattern and derives the counter period.
Package numbering renders invoice numbers from a pattern and derives the counter period.
registry
Package registry resolves party data from the official registries by tax number only: the MF VAT White List for Polish NIPs and EU VIES for EU VAT numbers.
Package registry resolves party data from the official registries by tax number only: the MF VAT White List for Polish NIPs and EU VIES for EU VAT numbers.
secrets
Package secrets reads secrets (KSeF tokens and the like) from the OS keyring, with an environment-variable fallback.
Package secrets reads secrets (KSeF tokens and the like) from the OS keyring, with an environment-variable fallback.
store
Package store is fv's local archive: invoice numbering counters in state.json and one folder per invoice holding invoice.xml, meta.json and upo.xml.
Package store is fv's local archive: invoice numbering counters in state.json and one folder per invoice holding invoice.xml, meta.json and upo.xml.
useragent
Package useragent holds the User-Agent fv sends on every HTTP request.
Package useragent holds the User-Agent fv sends on every HTTP request.
validate
Package validate checks user-supplied identifiers and settings.
Package validate checks user-supplied identifiers and settings.
xades
Package xades builds the KSeF AuthTokenRequest and signs it as an enveloped XAdES-BES signature in pure Go.
Package xades builds the KSeF AuthTokenRequest and signs it as an enveloped XAdES-BES signature in pure Go.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL