This guide walks you through everything needed to run DIAN REST API locally and send your first electronic invoice to DIAN’s habilitación (testing) environment. By the end you will have a running FastAPI server, a validated PFX certificate loaded on startup, and a confirmed SOAP round-trip to DIAN’s testing service.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/farojas85/fast-rest-api/llms.txt
Use this file to discover all available pages before exploring further.
Prerequisites
Before you begin, make sure you have the following:
- Python 3.14 or later — required by
pyproject.toml. uvpackage manager — used exclusively for dependency management and virtual environments. Install it with:
- A valid DIAN
.pfxdigital certificate — issued during the DIAN software registration process. This file is required for XML signing and SOAP authentication. Keep the file path and password handy. - DIAN habilitación credentials — provided by DIAN when you register your billing software:
TestSetId— identifies your test set during habilitación.SoftwareID— the UUID of your registered billing software.SoftwarePIN— the PIN associated with your software registration.
Clone and install
Clone the repository and install all dependencies in one command. To also install the development dependencies (pytest, ruff):
uv sync reads pyproject.toml, creates an isolated virtual environment, and installs every dependency — no manual pip install needed.Configure environment
Copy the provided example file to create your local Open
.env:.env and fill in your real values. The file contains the following variables:| Variable | Description |
|---|---|
DIAN_CERT_PATH | Absolute path to your .pfx certificate file on disk. |
DIAN_CERT_PASSWORD | Password for the .pfx certificate. Stored as a SecretStr — never logged. |
DIAN_TEST_SET_ID | Test Set ID provided by DIAN during the habilitación process. |
DIAN_SOFTWARE_ID | UUID of your billing software registered with DIAN. |
DIAN_SOFTWARE_PIN | PIN for your registered DIAN software. |
ENVIRONMENT | Runtime environment. Any value other than production routes requests to the habilitación WSDL. |
DIAN_WSDL_URL_HABILITACION | WSDL endpoint for DIAN’s testing service. |
DIAN_WSDL_URL_PRODUCCION | WSDL endpoint for DIAN’s live production service. |
Start the server
Start the FastAPI development server with hot-reload enabled:On startup, Pydantic Settings loads every variable from Expected response:
.env and immediately attempts to open and decrypt your PFX certificate. If the file is missing, unreadable, or the password is wrong, the process exits with an error before accepting any requests — this fast-fail behavior prevents the server from running in a broken state.Once the server is up, verify it is healthy:Send your first invoice
Submit a local consumption order (consumo local) to the invoicing endpoint. The example below uses the same payload values as the project’s test suite:On success, the API returns HTTP Use the
201 Created with a DIAN tracking response:track_id value to query DIAN’s portal and confirm the document was received and accepted.