Skip to main content

A Python library to generate XML digital signatures (XAdES-BES) compliant with Ecuador's SRI electronic invoicing requirements.

Project description

SRI-Xades-Signer

Python library to sign XML with the XAdES-BES standard, in compliance with the requirements of the SRI (Ecuador) for electronic invoicing. It allows signing invoices, credit notes, withholding vouchers, and other tax documents. Updated to SRI specification v2.31.

Requirements

  • Python >= 3.10
  • Dependencies: cryptography>=45.0.6, lxml>=5.4.0

Installation

  • From PyPI:

    pip install sri-xades-signer
    
  • From the repository:

    pip install git+https://github.com/Juanja1306/SRI-Xades-Signer.git
    
  • Local:

    pip install -e .
    

Quick usage

  • One-time signing with sign_xml using a .p12 file:

    from sri_xades_signer import sign_xml
    
    xml_text = open("comprobante.xml", "r", encoding="utf-8").read()
    xml_signed = sign_xml(
        pkcs12_file="path/to/certificate.p12",
        password="p12_password",
        xml=xml_text,
        read_file=True,  # indicates pkcs12_file is a file path
    )
    open("comprobante_signed.xml", "w", encoding="utf-8").write(xml_signed)
    
  • Reusable with XadesSigner to sign multiple XMLs:

    from sri_xades_signer import XadesSigner
    
    signer = XadesSigner(
        pkcs12_file="path/to/certificate.p12",
        password="p12_password",
        read_file=True,
    )
    xml_signed = signer.sign(xml_text)
    
  • Sign and save in one step:

    from sri_xades_signer import sign_and_save
    
    sign_and_save(
        pkcs12_file="path/to/certificate.p12",
        password="p12_password",
        xml_file="comprobante.xml",
        output_xml="comprobante_signed.xml",
    )
    

Main API

  • sign_xml(pkcs12_file, password, xml, read_file=False) -> str
  • XadesSigner(pkcs12_file, password, read_file=False).sign(xml) -> str
  • sign_and_save(pkcs12_file, password, xml_file, output_xml) -> bool
  • Exception: SignatureError

Important notes

  • The root element of the document must have the attribute Id="comprobante", since the signature reference points to #comprobante.
  • Signature algorithm: RSA-SHA1 with exclusive canonicalization (exc-c14n), according to SRI requirements.

Links

License

Licensed under the GNU Affero General Public License v3.0 (AGPL-3.0).
See LICENSE

Provenance & Attribution

This project, SRI-Xades-Signer, is a derivative work of jsonfm/xades-bes-sri
https://github.com/jsonfm/xades-bes-sri (AGPL-3.0).
The upstream project itself credits xades-bes-sri-ec by @alfredo138923.

Modifications by Juan Malo (2025-09-02)

  • Package name and module structure: sri_xades_signer (pyproject-based).
  • Public API additions:
    • XadesSigner class for re-usable signing.
    • sign_and_save(...) convenience function.
    • SignatureError for consistent error handling.
  • Input ergonomics: support for PKCS#12 via file path using read_file=True.
  • Documentation: updated examples and guidance for SRI spec v2.31.
  • Dependency and packaging updates.

Network Use Notice (AGPL-3.0 §13)

If this software (modified or not) is run as a network-accessible service, users of that service must be offered the complete corresponding source code of the exact version running, at no charge. A simple way is to expose a “Source” link pointing to this repository.

Credits & Copyright

  • Original work: jsonfm/xades-bes-sri — © jsonfm and contributors
  • Derivative work: SRI-Xades-Signer — © 2025 Juan Malo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sri_xades_signer-1.0.0.tar.gz (46.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sri_xades_signer-1.0.0-py3-none-any.whl (34.1 kB view details)

Uploaded Python 3

File details

Details for the file sri_xades_signer-1.0.0.tar.gz.

File metadata

  • Download URL: sri_xades_signer-1.0.0.tar.gz
  • Upload date:
  • Size: 46.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.6

File hashes

Hashes for sri_xades_signer-1.0.0.tar.gz
Algorithm Hash digest
SHA256 094d200eb0ea1bef0a15bcc148af99c132627f26c99c6b27f8730dba95d14a78
MD5 b1862825eac9b23b23cb29a0d1c497cf
BLAKE2b-256 df98b163e00deda1116a529b3bfea5c83650d82309968b4efdeb25dca3790ce8

See more details on using hashes here.

File details

Details for the file sri_xades_signer-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sri_xades_signer-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e9a6fb08e7edda507dbef85d1677a59e2223073172fb396ea6b3dcaa54fd3b32
MD5 f2f0e92117ac3018d97cefe0af449e45
BLAKE2b-256 0f300651390bfabd4e4504c8143949891e1fc7fd824bb27fd597a0c4b2e458d7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page