Carbone Render Python SDK
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.
Install
pip install carbone-sdk
Usage
You can copy and run the code bellow to try.
Get your API token on your Carbone account: https://account.carbone.io/.
import carbone_sdk
csdk = carbone_sdk.CarboneSDK("secret-token")
csdk.set_api_version("4")
csdk.set_api_url("https://api.carbone.io")
template_id = "template"
render_options = {
"data": {
"id": 42,
"date": 1492012745,
"company": {
"name": "myCompany",
"address": "here",
"city": "Notfar",
"postalCode": 123456
},
"customer": {
"name":"myCustomer",
"address":"there",
"city":"Faraway",
"postalCode":654321
},
"products":[
{"name":"product 1","priceUnit":0.1,"quantity":10,"priceTotal":1}
],
"total":140
},
"convertTo":"pdf"
}
report_bytes, unique_report_name = csdk.render(template_id, render_options)
fd = open(unique_report_name, "wb")
fd.write(report_bytes)
fd.close()
Documentation
Tests
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
Install:
$ 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/test_carbone_sdk.py::TestRender
To run a single test:
$ pytest -s -v ./tests/test_carbone_sdk.py::TestRender::test_render_a_report_error_file_missing
To run a single test with all the DEBUG:
$ pytest ./tests/test_carbone_sdk.py::TestRender::test_render_a_report_from_an_existing_template_id --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!