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:
-
๐ฆ Rust
-
๐ Python
-
๐ C/C++ (through the C FFI see
)
-
๐ Also, a Command Line Interface (CLI) Tool
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
Checkout the homepage, also the Rust API at docs.rs may prove useful.
โก 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.
๐ฅ Installation
cargo add fatoora-core
pip install fatoora-rs
Download the precompiled shared library and headers for your platform on the repo's releases (fatoora-ffi-*).
Alternatively, if you'd like to build from source. Clone the repo and run:
cargo build -p fatoora-ffi --release
The compiled library will be in target/release/ for your platform (e.g. libfatoora_ffi.so, libfatoora_ffi.dylib, or fatoora_ffi.dll) and the headers will be (re)generated and written to fatoora-ffi/include/
The cli tool can also be installed with cargo:
cargo install fatoora-rs-cli
Alternatively, you can grab the precompiled binary for your platform on the repo's releases (fatoora-rs-cli-*).
๐ก 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
And much more... see the guides in the homepage for more info.
๐ค 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