Skip to main content

Python SDK to use Carbone Render easily

Project description

Carbone Render Python SDK

Pypi Package Documentation

Python SDK to use Carbone Render easily.

🔖 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
report_bytes = csdk.render(template_id, json_data)
fd = open("Invoice.pdf", "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.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

carbone_sdk-1.0.0-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: carbone-sdk-1.0.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.3.2 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.6

File hashes

Hashes for carbone-sdk-1.0.0.tar.gz
Algorithm Hash digest
SHA256 5c69991350550b05ddd7307b7d0696fd61de7319a99e1c9132196ccc694fc3ce
MD5 af85d8c2ac696d1a3cb6843792fac415
BLAKE2b-256 4ec9530752d7d7cd8643925510616a3d1d556641dd0dd9f9e416319c37372371

See more details on using hashes here.

File details

Details for the file carbone_sdk-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: carbone_sdk-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.3.2 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.6

File hashes

Hashes for carbone_sdk-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6f7866c1427aab5c39204edbb58418d217c33fbefcd558b4aafa24d001e9a0ee
MD5 571a746d927db0c54fc816eb6a0421ac
BLAKE2b-256 332b87538e5a22dd92ed1b062d2b0a6d815e19a3667b151ec5289e5f8396ec69

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