DIAN REST API uses Pydantic Settings (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.
pydantic-settings) to load and validate every configuration value from environment variables at application startup. The Settings class in src/infrastructure/config/settings.py is instantiated once when the module is imported — meaning all validations run before the first request is ever served. If any required variable is missing, has an incorrect type, or if the PFX certificate cannot be loaded with the provided password, the application raises an exception and refuses to start. There is no way to defer or skip this validation.
Environment Variables
Absolute path on the server’s filesystem to the DIAN digital certificate file in PFX (PKCS#12) format. Pydantic validates that this path exists and points to a file before the
@model_validator runs. Use an absolute path — relative paths are not recommended and may behave differently depending on the working directory.Password used to decrypt the PFX certificate file. Pydantic stores this value as a
SecretStr — its raw value is never included in logs, tracebacks, or serialized representations of the Settings object. The plain-text value is only exposed internally via .get_secret_value() when constructing the SOAP adapter.The Test Set ID assigned by DIAN during the software habilitación (registration) process. This UUID-formatted identifier is submitted as part of the SOAP envelope to associate the invoice with your registered test set. Provided by DIAN’s Facturación Electrónica portal.
The Software ID (UUID) that identifies your billing software as registered with DIAN. Every electronic document submitted to DIAN must be associated with a registered
SoftwareID. This value is provided when you complete the DIAN software registration.The Software PIN that authenticates your billing software against DIAN’s web services. Used alongside
DIAN_SOFTWARE_ID to construct the SOAP security header for each request.Runtime environment flag that controls which DIAN WSDL endpoint receives invoice submissions. Any value other than
"production" routes requests to the habilitación (testing) service. Set to "production" only when you are ready to submit legally binding fiscal documents to DIAN’s live service.Accepted values: local, staging, production (or any custom string — only "production" triggers the production WSDL).Full URL of the DIAN SOAP WSDL for the habilitación (testing) environment. This endpoint is used when
ENVIRONMENT is set to any value other than "production". The default points to DIAN’s official testing service.Full URL of the DIAN SOAP WSDL for the production environment. This endpoint is only used when
ENVIRONMENT=production. The default points to DIAN’s official live service.Certificate Validation
WhenSettings is instantiated, a @model_validator(mode="after") method (validate_pfx_certificate) immediately attempts to open the file at DIAN_CERT_PATH and decrypt it using DIAN_CERT_PASSWORD. Internally it calls:
ValueError is raised with a descriptive message and the application process exits immediately:
WSDL Environment Routing
Thepedido_local_controller.py controller selects the correct WSDL URL each time a request is processed, using a simple conditional:
ENVIRONMENT value | WSDL used |
|---|---|
local (default) | https://vpfe-hab.dian.gov.co/WcfDianCustomerServices.mac/WcfDianCustomerServices.svc?wsdl |
staging | https://vpfe-hab.dian.gov.co/WcfDianCustomerServices.mac/WcfDianCustomerServices.svc?wsdl |
production | https://vpfe.dian.gov.co/WcfDianCustomerServices.mac/WcfDianCustomerServices.svc?wsdl |
ENVIRONMENT variable in your deployment configuration needs to change.
Configuration file
A complete.env file for local development:
The
Settings class is configured with extra="ignore" in its model_config. This means any environment variables present in your shell or .env file that are not declared as fields on Settings are silently ignored — they will not cause a validation error. This makes it safe to run the application in environments that have many unrelated environment variables set (for example, a shared CI runner or a container with platform-injected variables).