Skip to main content

Carbone API Python SDK to generate documents (PDF, docx, xlsx, ods, odt, ...) from a JSON and a template.

Project description

Carbone Render Python SDK

GitHub release (latest by date) Documentation

Python SDK to use Carbone Render easily.

About Carbone

Carbone is a powerful document generator (PDF, DOCX, XLSX, ODT, PPTX, ODS, XML, CSV...) using templates and JSON data. It is based on LibreOffice and can convert any document. It is also possible to convert HTML to PDF. Learn more about supported files and features.



pip install carbone-sdk


You can copy and run the code bellow to try. Get your API token on your Carbone account:

import carbone_sdk

# SDK constructor
# The access token can be passed as an argument to the constructor CarboneSDK
# Or by the environment variable "CARBONE_TOKEN", use the command "export CARBONE_TOKEN=secret-token"
csdk = carbone_sdk.CarboneSDK("secret-token")
# Set API version (default : 4)
# Set API URL for Carbone On-Premise for example (default: "")

# The template ID, it could be an ODT, DOCX, PPTX, XLSX, ODS file, etc...
template_id = "template"
render_options = {
  # REQUIRED: the "data" object contains all the data to inject into the template
  "data": {
    "id": 42,
    "date": 1492012745,
    "company": {
        "name": "myCompany",
        "address": "here",
        "city": "Notfar",
        "postalCode": 123456
    "customer": {
      {"name":"product 1","priceUnit":0.1,"quantity":10,"priceTotal":1}
  # REQUIRED: the "convertTo" attribute defines the format to generate or convert
  # All rendering options are available on the following API specification:

# Render and return the report as bytes and a unique report name
report_bytes, unique_report_name = csdk.render(template_id, render_options)
fd = open(unique_report_name, "wb")
# voila 🎉



Tests - Run with Makefile

Install the test packages:

$ make install

To run the tests:

$ make test

To uninstall the test packages:

$ make uninstall

Tests - Run manually


$ pip install pytest
$ pip install requests_mock

To run all the test (-v for verbose output):

$ pytest -s -v tests

To run a groupe of tests:

$ pytest -s -v ./tests/

To run a single test:

$ pytest -s -v ./tests/

To run a single test with all the DEBUG:

$ pytest ./tests/ --log-cli-level=10

If you need to test the generation of templateId, you can use the nodejs main.js to test the sha256 generation.

$ node ./tests/main.js

👤 Author

🤝 Contributing

Contributions, issues and feature requests are welcome!

Feel free to check issues page.

Show your support

Give a ⭐️ if this project helped you!

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

carbone-sdk-1.0.8.tar.gz (11.4 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page