Skip to main content

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.

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.

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

Metadata

Release files for sri-xades-signer 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sri-xades-signer 1.0.0
File Size Uploaded Provenance Actions
sri_xades_signer-1.0.0.tar.gz 46.8 kB Without provenance Details for sri_xades_signer-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sri-xades-signer 1.0.0
File Interpreter ABI Platform Actions
sri_xades_signer-1.0.0-py3-none-any.whl Python 3 none any Details for sri_xades_signer-1.0.0-py3-none-any.whl

Total release size: 81.0 kB

Release files / sri_xades_signer-1.0.0.tar.gz

Download URL sri_xades_signer-1.0.0.tar.gz
Size 46.8 kB
Tags Source
SHA-256 checksum
How to use checksums
094d200eb0ea1bef0a15bcc148af99c132627f26c99c6b27f8730dba95d14a78
BLAKE2b-256 checksum
How to use checksums
df98b163e00deda1116a529b3bfea5c83650d82309968b4efdeb25dca3790ce8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.6

Release files / sri_xades_signer-1.0.0-py3-none-any.whl

Download URL sri_xades_signer-1.0.0-py3-none-any.whl
Size 34.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e9a6fb08e7edda507dbef85d1677a59e2223073172fb396ea6b3dcaa54fd3b32
BLAKE2b-256 checksum
How to use checksums
0f300651390bfabd4e4504c8143949891e1fc7fd824bb27fd597a0c4b2e458d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.6

Security for sri-xades-signer 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page