Skip to main content

Carbone Render Python SDK to generate reports easily (PDF, docx, xlsx, ods, odt, ...) from a JSON

Project description

Carbone Render Python SDK

Pypi Package Documentation

Python SDK to use Carbone Render easily.

Carbone is a report generator (PDF, DOCX, XLSX, ODT, PPTX, ODS, XML, CSV...) using templates and JSON data. Learn more about the Carbone ecosystem.

🔖 API REFERENCE

Install

pip install carbone-sdk

Usage

You can copy and run the code bellow to try.

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")

# The template ID, it could be an ODT, DOCX, PPTX, XLSX, ODS file, etc...
template_id = "template"
json_data = {
  "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"
}

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

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 -v tests

To run a groupe of tests:

$ pytest -v ./tests/test_carbone_sdk.py::TestRender

To run a single test:

$ pytest -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!

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.2.tar.gz (8.1 kB view details)

Uploaded Source

File details

Details for the file carbone-sdk-1.0.2.tar.gz.

File metadata

  • Download URL: carbone-sdk-1.0.2.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.4.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.5

File hashes

Hashes for carbone-sdk-1.0.2.tar.gz
Algorithm Hash digest
SHA256 9a540d6dcd111280a9d2d36afd2c285d83b80a1662f37e23490c54aaa81aa17e
MD5 cb7b8036e71060874ddbc6551445bdb7
BLAKE2b-256 1d71e06e9aba0d2d1efa5c765c1e048452551321c1b2d679478e6b073d733154

See more details on using hashes here.

Supported by

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