Status and UPO
KSeF processing is asynchronous. Keep session references and invoice reference numbers so you can inspect status and download UPO documents after the sending process exits.
Online session status
Section titled “Online session status”with auth.online_session(form_code=FormSchema.FA3) as session: result = session.send_invoice(invoice_xml=xml_bytes) invoice_status = session.wait_for_invoice_ready( invoice_reference_number=result.reference_number, timeout=120.0, ) upo_xml = session.get_invoice_upo_by_reference( invoice_reference_number=result.reference_number, )Batch status
Section titled “Batch status”state = auth.batch.submit_prepared_batch(prepared_batch=prepared)final_status = auth.batch.wait_for_completion(session=state, timeout=300.0)
accepted = auth.batch.list_invoices(session=state)failed = auth.batch.list_failed_invoices(session=state)If KSeF returns an UPO reference for the batch, use it to download the document:
upo_xml = auth.batch.get_upo( session=state, upo_reference_number="upo-reference-from-status",)Historical session browsing
Section titled “Historical session browsing”Use auth.invoice_sessions when you need to find sessions after process
restart.
page = auth.invoice_sessions.query( session_type="online", statuses=["processing", "completed"],)for page in auth.invoice_sessions.all(session_type="batch"): for item in page.sessions: print(item.reference_number, item.status)Recommended flow
Section titled “Recommended flow”-
Persist session and invoice references returned by KSeF.
-
Poll the session or invoice status until it reaches a terminal state.
-
Persist accepted and failed invoice details.
-
Download and store the relevant UPO document.