Create Saudi e-invoices in your application¶
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.
Use the Rust library, add it to your application in Python, JavaScript/TypeScript, C#, Kotlin/Java (including Android), or C/C++, or run the command-line tool from your terminal.
Run the sandbox walkthrough Choose your language View on GitHub
fatoority is an independent project and is not affiliated with ZATCA.
Start with one complete example in Python, C#, or TypeScript covering creation through reporting, with a diagram of the ZATCA journey.
What you can build¶
| Task | How fatoority helps |
|---|---|
| Create invoices | Build invoice data with calculated totals and UBL XML output. Choose standard or simplified tax invoices, credit/debit notes, or prepayments. |
| Handle pricing and VAT | Apply line or document discounts and charges, use price-base quantities, and group VAT by category and rate with exact decimal arithmetic. |
| Include business references | Carry purchase orders, contracts, delivery dates, payment instructions/accounts, and party/item identifiers into XML. |
| Read existing XML | Inspect supported fields and totals. Signed import checks cryptographic integrity and QR consistency while retaining the original XML. |
| Validate locally | Check UBL schemas and the pinned SDK's 257 business-rule assertions. Inspect rule findings, warnings, and incomplete stages before submission. |
| Sign invoices | Sign with a matching certificate and private key. Compute invoice hashes and prepare API payloads. |
| Generate QR payloads | Generate base64 invoice QR data or read the payload embedded in signed XML. |
| Onboard and submit | Generate a CSR, obtain or renew credentials, run compliance checks, and integrate reporting or clearance. |
Local invoice processing needs no official SDK installation or network access. The Rust core has no Java dependency. The JavaScript package includes WebAssembly for Node.js and browsers; Kotlin/Java also has an Android artifact. Use prepared API requests when your application needs its own HTTP transport.
Local validation helps catch problems before submission. It does not establish ZATCA gateway acceptance or certificate issuer trust. See the validation guide for coverage and how to interpret results.
Try it: validate an invoice¶
Start with a local XML schema check. You do not need an account, certificate, or API credentials for this example.
1. Install the CLI¶
With Rust and Cargo installed, run:
cargo install fatoora-cli
You can also download a binary for your platform from
GitHub Releases. Extract the archive
and put the fatoora executable on your PATH.
2. Download the sample invoice¶
Save sample-invoice.xml in your working folder. It contains demonstration data for this schema check.
3. Run the check¶
From the folder containing the file:
fatoora validate --invoice sample-invoice.xml
Expected output:
OK
OK means the XML passes the bundled UBL schema check. To run local ZATCA rules
and inspect individual findings, follow the invoice validation guide.
For more terminal commands, see the CLI guide.
Choose your language¶
Install the package for your application, then follow its examples. The project
and most packages are named fatoority; existing API names such as Python's
fatoora import and Rust's fatoora_core remain unchanged.
cargo add fatoora-core
Import fatoora_core in your code.
Create your first invoice or browse the
Rust API reference.
pip install fatoority
Import fatoora in your code.
Follow the Python setup and examples.
npm install fatoority
Use the WebAssembly package in Node.js or a browser. Follow the JavaScript/TypeScript setup and examples, including browser asset setup and API transport requirements.
dotnet add package Fatoority
Use the Fatoora namespace with .NET 8 or later.
Follow the C# setup and examples, including
supported native platforms.
Install from Maven Central with Gradle or Maven.
Gradle (build.gradle.kts):
repositories { mavenCentral() }
dependencies {
implementation("com.fatoority:fatoority:0.7.0")
}
Maven (add inside <dependencies> in pom.xml):
<dependency>
<groupId>com.fatoority</groupId>
<artifactId>fatoority</artifactId>
<version>0.7.0</version>
</dependency>
Import com.fatoora in your code.
Follow the Kotlin/Java examples for
supported platforms and Android setup. For Android, use
com.fatoority:fatoority-android:0.7.0 instead of the desktop artifact.
Download the fatoora-ffi-* archive with the native library and C/C++ headers from
GitHub Releases.
Follow the C/C++ setup and examples for compilation and linking instructions.
Continue your integration¶
If you are adding invoicing to an application, start with creating an invoice. The business-case recipes cover pricing and document types. Then sign and validate the XML before sending it.
For device onboarding, generate a CSR, then use the ZATCA API client to request credentials and submit invoices. The guides explain the inputs needed at each step.
About the project¶
The core is written in Rust and shared by the CLI and language bindings. The project code is available under the MIT or Apache-2.0 license. Third-party materials retain their upstream terms; see the third-party notices.
See the SDK compatibility notes for the scope of comparison with the official SDK, and benchmarks for measured performance and methodology.
Need help with an integration? Open an issue. To help improve the library or these docs, read the contributing guide.