DIAN API¶
Log in¶
Initialize the client:
from prometeo import Client
from prometeo.dian import DocumentType
client = Client('<YOUR_API_KEY>', environment='testing')
Supply the NIT to log in as a company
session = client.dian.login(
nit='098765',
document_type=DocumentType.CEDULA_CIUDADANIA,
document='12345',
password='test_password',
)
Or omit it to log in as a person:
session = client.dian.login(
document_type=DocumentType.CEDULA_CIUDADANIA,
document='12345',
password='test_password',
)
Check the reference for a list of possible values for DocumentType
Restoring a session¶
In some cases it may be useful to serialize the session to be used later or to transfer to another process, like in a task queue job. For this use get_session_key()
and get_session()
:
session_key = session.get_session_key()
# save session_key somewhere...
restored_session = client.dian.get_session(session_key)
Download the forms¶
To download the original forms in pdf format, use the pdf
property of the object returned by the methods:
info = session.get_company_info()
pdf_content = info.pdf.get_content()
# write the contents to a file:
with open("company-info.pdf", "wb") as f:
f.write(pdf_content)
Getting the data¶
Company info (form 001):
session.get_company_info()
Balances:
session.get_balances()
Rent declaration:
session.get_rent_declaration(2019)
VAT declaration:
from prometeo.dian import Periodicity, QuartlerlyPeriod
session.get_vat_declaration(2019, Periodicity.QUARTERLY, QuartlerlyPeriod.JANUARY_APRIL)
Numeration:
from datetime import datetime
from prometeo.dian import NumerationType
session.get_numeration(
NumerationType.Authorization,
datetime(2019, 1, 1),
datetime(2019, 5, 1)
)
Retentions:
from prometeo.dian import MonthlyPeriod
session.get_retentions(2019, MonthlyPeriod.NOVEMBER)