Skip to main content

Alanube Python API

A lightweight Python client for connecting to the Alanube e-invoicing API across multiple countries.

PyPI version License: MIT Tests

📚 Table of Contents

Instalation

To install the Alanube library, you can use pip:

pip install alanube

Usage

# Import the Alanube class specific to the country,
# in this case from `alanube.do` for the Dominican Republic
from alanube.do import Alanube

# Connect to the API
Alanube.connect("[TOKEN]")

payload = {...}

data = Alanube.send_document(encf_type=31, payload)

Now you can easily and efficiently use the Alanube API with this Python library!

To retrieve an already-issued document PDF, Generic is selected by default. Use pdf_type="pos" to request the POS representation:

generic_document = Alanube.get_document(31, "DOCUMENT_ID")
pos_document = Alanube.get_document(31, "DOCUMENT_ID", pdf_type="pos")

Dominican Republic API Methods

Method Description
create_company Create a new company.
update_company Update company information.
get_company Retrieve company info.
send_fiscal_invoice Issue Fiscal Credit Invoice (31).
get_fiscal_invoice Get status of a Fiscal Credit Invoice.
get_fiscal_invoices List Fiscal Credit Invoices.
send_invoice Issue Consumption Invoice (32).
get_invoice Get status of a Consumption Invoice.
get_invoices List Consumption Invoices.
send_debit_note Issue Debit Note (33).
get_debit_note Get status of a Debit Note.
get_debit_notes List Debit Notes.
send_credit_note Issue Credit Note (34).
get_credit_note Get status of a Credit Note.
get_credit_notes List Credit Notes.
send_purchase Issue Purchase Document (41).
get_purchase Get status of a Purchase Document.
get_purchases List Purchase Documents.
send_minor_expense Issue Minor Expense Document (43).
get_minor_expense Get status of a Minor Expense Document.
get_minor_expenses List Minor Expense Documents.
send_special_regime Issue Special Regime Document (44).
get_special_regime Get status of a Special Regime Document.
get_special_regimes List Special Regime Documents.
send_gubernamental Issue Government Document (45).
get_gubernamental Get status of a Government Document.
get_gubernamentals List Government Documents.
send_export_support Issue Export Support Document (46).
get_export_support Get status of an Export Support Document.
get_export_supports List Export Support Documents.
send_payment_abroad_support Issue Payment Abroad Support Document (47).
get_payment_abroad_support Get status of a Payment Abroad Support Document.
get_payment_abroad_supports List Payment Abroad Support Documents.
send_cancellation Issue a cancellation document.
get_cancellation Get status of a cancellation.
get_cancellations List cancellations.
get_received_document Retrieve a received document.
get_received_documents List received documents.
check_directory Check active companies in directory.
check_dgii_status Check DGII service status and maintenance.
get_report_companies_documents_total Get total documents issued by a company.
get_report_users_documents_total Get total documents issued by the authenticated user.
get_report_company_emitted_documents Get total documents emitted by a company.
get_report_company_emitted_documents_monthly Monthly totals of emitted documents (12 months).
get_report_company_emitted_documents_15_days Daily totals of emitted documents (last 15 days).
get_report_company_accepted_documents Total documents accepted by DGII for a company.
get_report_company_accepted_documents_monthly Monthly totals of accepted documents (12 months).
get_report_company_accepted_documents_15_days Daily totals of accepted documents (last 15 days).

Error Handling

Since v1.3.0, API errors are parsed into structured APIErrorItem objects:

from alanube.do.exceptions import APIErrorItem, ValidationError

try:
    company = AlanubeAPI.create_company({...})
except ValidationError as e:
    for error in e.error_items:
        print(f"[{error.code}] {error.message} (field: {error.field})")

Supported error formats:

  • Unified format: {"code": 400, "errors": [{"code": "...", "message": "...", "field": "..."}]}
  • Legacy formats: {"message": [...]}, {"errors": [...]}, etc.

Legacy formats continue to work without changes.

Contents

  • do: Fully implemented for the Dominican Republic (DGII).
  • pa, cr, pe, bo: Planned support. Follow the structure of the do module.

For the missing countries, you can use the do directory as a reference to build the required implementations, adapting the logic to meet the specific local requirements of each country.

Roadmap

  • 🇩🇴 Dominican Republic
  • 🇵🇦 Panama
  • 🇨🇷 Costa Rica
  • 🇵🇪 Peru
  • 🇧🇴 Bolivia

Used by

This library is trusted and used in production by:

Unolet Logo
Unolet

ERP and electronic invoicing platform for SMEs.

If your company uses this library and would like to be listed here, feel free to open a pull request or create an issue.

Developers

If you're contributing to the development of this library, here are the steps to set up your environment and run the tests:

Setting Up the Environment

  1. Clone the repository:

    git clone https://github.com/wilmerm/alanube-python.git
    cd alanube-python
    
  2. Create a virtual environment (optional but recommended):

    python -m venv venv
    source venv/bin/activate  # On Windows: venv\Scripts\activate
    
  3. Install the required dependencies:

    pip install -r requirements.txt
    pip install -r requirements-dev.txt
    
  4. Install the library in editable mode:

    pip install -e .
    
  5. Code Style. We follow PEP 8 for coding standards. Please ensure your code is formatted accordingly before submitting a pull request.

    flake8 alanube
    

Running the Tests

  1. Navigate to the project root directory.

  2. Execute the tests with unittest:

    python -m unittest discover -s alanube/tests -p "*.py"
    
    • -s: Specifies the directory to look for tests (tests folder).
    • -p: Defines the pattern for test file names (e.g., *.py).

Building and Publishing the Library

To compile and upload the library to PyPI, follow these steps:

  1. Ensure you have the necessary dependencies:

    pip install build twine
    
  2. Build the package:

    python -m build
    
  3. (Optional) Verify the package:

    twine check dist/*
    
  4. Upload the package to PyPI:

    python -m twine upload dist/*
    

Credits

Wilmer Martinez
Wilmer Martinez

Author & Maintainer
Oriku Precious
Oriku Precious

Documentation Contributor

If you contributed to this project and would like to be listed here, feel free to open a pull request adding yourself to the credits section.

Licence

This project is licensed under the MIT License.

Proyect Status

✅ This project is in production and actively maintained.

Contributing

We welcome pull requests and suggestions. Please open an issue or submit a PR.

Support 💗

If you find this useful, consider supporting.

Your generosity helps us to continue improving and maintaining this project. We appreciate every contribution, however small. Thanks for being part of our community!

Metadata

Release files for alanube 1.4.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 alanube 1.4.0
File Size Uploaded Provenance Actions
alanube-1.4.0.tar.gz 27.3 kB Without provenance Details for alanube-1.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for alanube 1.4.0
File Interpreter ABI Platform Actions
alanube-1.4.0-py3-none-any.whl Python 3 none any Details for alanube-1.4.0-py3-none-any.whl

Total release size: 53.3 kB

Release files / alanube-1.4.0.tar.gz

Download URL alanube-1.4.0.tar.gz
Size 27.3 kB
Tags Source
SHA-256 checksum
How to use checksums
d516752461a35bed249ff2940ce106f57b0c82497f48f06329cbe70908e70196
BLAKE2b-256 checksum
How to use checksums
164eb0ba20ee04ade4d99e29f80118857a2c5e3f69d4388ff3316e7f36a11dfb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / alanube-1.4.0-py3-none-any.whl

Download URL alanube-1.4.0-py3-none-any.whl
Size 26.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
468fc30b54901fdf26fd7e0db7118f795510dfba21a238b7c4e2aa83eadc68eb
BLAKE2b-256 checksum
How to use checksums
1945954414ff28e64f57e64c27461233becfd7e16b79fc45ccc76db9a78706cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for alanube 1.4.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.

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