fatoority is an open-source SDK and CLI for Saudi e-invoicing. Build standard and
simplified invoices from application data, including credit notes, debit notes,
and prepayment invoices. Calculate totals and VAT, generate UBL XML, then sign
and validate invoices locally before submitting them through the ZATCA APIs.
With bindings and support for many programming languages:
-
π¦ Rust
-
π Python
-
π―βπΈβ JavaScript / TypeScript
-
π£ C# / .NET
-
β Kotlin / Java / Android
-
π C/C++ (through the C FFI see releases)
-
π Also, a Command Line Interface (CLI) Tool
Disclaimer:
fatoorityis not affiliated, associated, authorized, endorsed by, or in any way officially connected with ZATCA (Zakat, Tax and Customs Authority), or any of its subsidiaries or its affiliates. The official ZATCA website can be found at https://zatca.gov.sa.
ποΈ Documentation
Follow the complete sandbox walkthrough in Python, C#, or TypeScript: create an invoice, sign it, validate it, report it, and handle the response. The guide includes a ZATCA journey diagram and production changes.
For local XML output, start with invoice creation, browse the guides, or read the Rust API reference.
β‘ Features
| Build into your application | What fatoority provides |
|---|---|
| π§Ύ Invoice creation | Typed builders for standard and simplified tax invoices, credit/debit notes, and prepayments; UBL XML output. |
| π° Pricing and VAT | Exact decimal calculations, mixed VAT categories and rates, exemptions, line and document discounts/charges, price-base quantities, and payable totals. |
| πΌ Business document data | Purchase orders, contracts, delivery dates, payment accounts/instructions, repeated references, and party/item identifiers. |
| </> XML import | Read supported invoice fields into structured data. Signed import checks signature, digest, and QR consistency and retains the original XML. |
| β Local validation | UBL schemas and all 257 business-rule assertions in the pinned SDK 238-R3.4.8 profile, with structured findings and explicit stage coverage. |
| βοΈ Invoice Signing | Sign XML with a matching certificate and key, and compute invoice hashes. |
| π£― QR Generation | Generate base64 QR payloads or read them from signed XML. |
| π© CSR Generation | Generate signing keys and certificate requests for device onboarding. |
| π¨ API Requests | Obtain and renew credentials, check compliance, report simplified invoices, and request standard-invoice clearance. |
Local invoice processing needs no official SDK installation or network access. The Rust core has no Java dependency. Use the JavaScript WebAssembly package in Node.js or a browser, and the Android artifact in mobile applications. API calls require network access; prepared requests let you use your own HTTP transport.
π The recorded .NET benchmarks measured hashing at 8.5β14.1Γ, signing at 11.3β15.6Γ, and validation at about 44Γ the speed of the official .NET SDK on the tested fixtures. The separate CLI hashing benchmark measured about 187Γ, including process startup. See benchmarks for hardware, versions, timings, and reproduction instructions.
βοΈ The test suite includes property tests, fuzzing, and recorded comparisons with the official SDK. See SDK compatibility for the tested scope. Local validation does not establish certificate issuer trust or ZATCA gateway acceptance.
π₯ Installation
Install a published release from Maven Central.
Gradle (build.gradle.kts):
repositories { mavenCentral() }
dependencies {
implementation("com.fatoority:fatoority:0.7.0")
}
Maven (pom.xml):
com.fatoority
fatoority
0.7.0
For Android, use com.fatoority:fatoority-android:0.7.0 instead of the desktop
artifact. Java/Kotlin imports remain com.fatoora.
Download the fatoora-ffi-* archive for your platform from
releases and extract it. The shared
library is at the archive root. The C API header is include/fatoora.h,
with its adapter in src/fatoora.c and generated headers in include/generated; C++ headers
are in include/diplomat-cpp and expose types in namespace fatoora.
For example, on Linux, compile your application from the extracted directory:
Include fatoora.h in C or fatoora/Config.hpp in C++. Keep the shared library
beside these executables. On Windows, link the supplied import library and keep
the DLLs from the archive beside your executable.
To build the library from a source checkout:
The C API
provides one fatoora.h, plain strings, shared errors, and named-field options.
Compile bindings/c/fatoora.c once with your application, add bindings/c to
your include path, and link fatoora_ffi. Release archives also include the C
examples under examples/c.
The library is written to target/release/. The generated headers are checked in
under bindings/c/generated and bindings/cpp; raw ABI callers use those include paths and
-Ltarget/release when compiling against a source build. Cargo does not regenerate
headers. After changing bridge declarations, follow the
Diplomat generation workflow.
The cli tool can also be installed with cargo:
cargo install fatoora-cli
Alternatively, you can grab the precompiled binary for your platform on the repo's releases (fatoora-cli-*). Extract the archive and run fatoora.
π‘ Examples
Build a simplified invoice with two SAR 50 items and 15% VAT. The library
calculates SAR 15 VAT and a SAR 115 payable total, then writes invoice.xml.
This example uses demonstration identity and invoice-history data; replace them
for your integration. Running it replaces invoice.xml in the working folder.
Install with pip install fatoority, save as creation.py, and run python creation.py.
=
=
=
See invoice creation for the Rust example and next steps. Building checks model fields and arithmetic; run local validation separately before submission.
Rust
use Environment;
use ;
let props = from_file?;
let key = generate;
let csr = props.build?;
let csr_pem = csr.to_pem?;
let key_pem = key.to_pem?;
Python
=
=
=
=
=
JavaScript
import from 'fatoority';
const key = ;
const csr = .;
const csrPem = csr.;
CLI
Rust
use InvoiceSigner;
let cert_pem = read_to_string?;
let key_pem = read_to_string?;
let signer = from_pem?;
let xml = read_to_string?;
let signed_xml = signer.sign_xml?;
CLI
Rust
use ;
let xml = read_to_string?;
let options = ZatcaValidationOptions ;
let report = new.validate_zatca?;
if !report.is_valid
CLI
The local profile implements all 257 business-rule assertions from SDK
238-R3.4.8, plus applicable signature, QR and predecessor checks. It preserves
warnings and partial reports. Standard invoices skip signature/QR checks under
this SDK profile. Local validation does not establish issuer trust or remote
acceptance. Validator::validate_xml and the default CLI profile
continue to check XSD only.
Rust
use parse_signed_invoice_xml;
let xml = read_to_string?;
let signed = parse_signed_invoice_xml?;
let qr = signed.qr_code;
CLI
Rust
use parse_finalized_invoice_xml;
let xml = read_to_string?;
let invoice = parse_finalized_invoice_xml?;
let hash = invoice.hash?;
CLI
Rust
use parse_signed_invoice_xml;
let xml = read_to_string?;
let signed = parse_signed_invoice_xml?;
let payload = json!;
CLI
For discounts, mixed VAT, credit notes, and prepayments, see the invoice recipes.
π€ Contributing
Contributions are always welcome! See CONTRIBUTING.md for more details.
πͺ§ Roadmap
- Increase test coverage to 100% (Inshallah)
- Expand bindings to other languages (subject to demand)
- PDF invoice generation
Author π€
This project began as a personal undertaking, and continues to be developed and maintained by me @mqqz.
While this means development happens alongside other commitments, I do my best to keep the project maintained and responsive to issues. Contributions, feedback, and suggestions are always welcome.
If you or your team are working on fintech or ZATCA integrations and need help building reliable scalable infrastructure, feel free to get in touch.
π Relevant Links
License
This project's code is licensed under either the MIT License or the Apache License, Version 2.0, at your option.
Third-party schemas, fixtures, templates, and dependencies retain their applicable upstream licenses and notices. The project license does not relicense those materials.
See third-party notices for attribution, applicable terms, and outstanding permission questions.