fatoora-rs
An unofficial open-source toolkit for everything you'd need for ZATCA (Zakat, Tax and Customs Authority of Saudi Arabia) Phase 1 and 2 compliant e-invoicing
...with bindings and support for many programming languages (so far only C/C++ and Python).
...and also built in Rust btw
fatoora-rsis in active early development. While the core functionality is usable, the public API is still evolving and may change as the project matures. We strive to maintain good test coverage and stability, but users should be aware that some rough edges may remain. Feedback and contributions are especially welcome at this stage.
Disclaimer:
fatoora-rs is 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
- Rust API: docs.rs
- Project docs: see
docs/(MkDocs site)
Features
Everything done by the official ZATCA SDK
- CSR Generation
- Invoice Signing (All invoice types)
- Validation (UBL only for now)
- QR Generation
- API Requests
But we do it faster and better e.g. ~190x faster invoice hashing than ZATCA's SDK (see bench/)
Dependencies
XML parsing/manipulation is done internally with libxml2, so you might need to install it if you haven't already. See here for relevant instructions.
C headers are generated in fatoora-ffi/include/, with grouped headers under fatoora/ (e.g., fatoora/config.h). Do not edit these generated headers manually; update the Rust sources and re-run the build to regenerate them.
Installation
The Rust library can be added with cargo add fatoora-core.
The cli tool can also be installed with cargo:
cargo install fatoora-rs-cli
Python bindings:
pip install fatoora-rs
Python modules mirror the Rust core layout (e.g., fatoora.config, fatoora.csr, fatoora.invoice, fatoora.sign).
Usage/Examples
Rust
use EnvironmentType;
use ;
let props_text = read_to_string?;
let props = from_properties_str?;
let key = generate;
let csr = props.build?;
let csr_pem = csr.to_pem?;
let key_pem = key.to_pem?;
Python
=
=
=
=
=
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 Config;
use validate_xml_invoice_from_str;
let config = new;
let xml = read_to_string?;
validate_xml_invoice_from_str?;
CLI
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_base64?;
CLI
Rust
use parse_signed_invoice_xml;
let xml = read_to_string?;
let signed = parse_signed_invoice_xml?;
let payload = json!;
CLI
Contributing
Contributions are always welcome! See CONTRIBUTING.md for more details.
Roadmap
- Increase test coverage to 100% (Inshallah)
- Add the full validation suite (not only UBL schema)
- Expand bindings to other languages (subject to demand)
- PDF invoice generation