This is an unofficial Python wrapper for FacturAPI
FacturAPI makes it easy for developers to generate valid Invoices in Mexico (known as Factura Electrónica or CFDI).
If you've ever used Stripe or Conekta, you'll find FacturAPI very straightforward to understand and integrate in your server app.
pip install facturapi-python
from facturapi import Facturapi
api = facturapi("FACTURAPI_SECRET_KEY")
new_customer = api.customers.create({
"legal_name": "Dunder Mifflin",
"tax_id": "ABC101010111",
"tax_system": "601",
"email": "email@example.com",
"phone": 6474010101,
"address": {
"street": "Blvd. Atardecer",
"exterior": 142,
"interior": 4,
"neighborhood": "Centro",
"city": "Huatabampo",
"municipality": "Huatabampo",
"zip": 86500,
"state": "Sonora",
"country": "MEX"
}
})
from facturapi import Facturapi
api = facturapi("FACTURAPI_SECRET_KEY")
new_product = api.products.create({
"description": "Ukelele",
"product_key": 60131324,
"price": 345.6,
"tax_included": true,
"taxability": "01",
"taxes": [{
"type": "IVA",
"rate": 0.16
}],
"local_taxes": [],
"unit_key": "H87",
"unit_name": "Elemento",
"sku": "string"
})
from facturapi import Facturapi
api = facturapi("FACTURAPI_SECRET_KEY")
new_invoice = api.invoices.create({
"customer": "YOUR_CUSTOMER_ID", # You can also use a customer object instead
"payment_form": api.catalogs.payment_forms.TRANSFERENCIA_ELECTRONICA,
"items": [{
"quantity": 1,
"product": 'YOUR_PRODUCT_ID' # You can also use a product object instead
}]
})
from facturapi import Facturapi
api = facturapi("FACTURAPI_SECRET_KEY")
with open("invoice.zip", "wb") as binary_file:
invoice = api.invoices.download_zip("INVOICE_ID")
binary_file.write(invoice)
from facturapi import Facturapi
api = facturapi("FACTURAPI_SECRET_KEY")
message = api.invoices.send_by_email("INVOICE_ID", "customer@email.com")
You can find more on what to do on the official documentation
If you find a bug for this API client, please create an issue on the project's github page
All PRs are welcome!