A Fusion server that will transform your py3o.template into final LibreOffice documents
Project description
Introduction
py3o.fusion is a web server that provides a simple but important service: transform your py3o.template LibreOffice templates into final LibreOffice documents.
This is intended to avoid direct dependencies in your own applications. This also opens up the py3o ecosystem to other programming languages than Python.
Using it
You can use any language. Here is an example using python requests:
# you'll need to install requests to make this example work # pip install --upgrade requests # should do the trick import requests import json # point the client to your own py3o.fusion server url = 'http://localhost:8765/form' # target formats you want... can be ODT, PDF, DOC, DOCX targetformats = ["ODT", "PDF", "DOC", "DOCX"] class MyEncoder1(json.JSONEncoder): def default(self, obj): if isinstance(obj, Item): obj = obj._asdict() else: obj = super(MyEncoder1, self).default(obj) return obj class Item(object): def _asdict(self): return self.__dict__ items = list() item1 = Item() item1.val1 = 'Item1 Value1' item1.val2 = 'Item1 Value2' item1.val3 = 'Item1 Value3' item1.Currency = 'EUR' item1.Amount = '12345.35' item1.InvoiceRef = '#1234' items.append(item1) for i in xrange(1000): item = Item() item.val1 = 'Item%s Value1' % i item.val2 = 'Item%s Value2' % i item.val3 = 'Item%s Value3' % i item.Currency = 'EUR' item.Amount = '6666.77' item.InvoiceRef = 'Reference #%04d' % i items.append(item) document = Item() document.total = '9999999999999.999' data = dict(items=items, document=document) data_s = json.dumps(data, cls=MyEncoder1) for targetformat in targetformats: # open the files you need files = { 'tmpl_file': open('templates/py3o_example_template.odt', 'rb'), 'img_logo': open('images/new_logo.png', 'rb'), } # fusion API needs those 3 keys fields = { "targetformat": targetformat, "datadict": data_s, "image_mapping": json.dumps({"img_logo": "logo"}), } # and it needs to receive a POST with fields and files r = requests.post(url, data=fields, files=files) # TODO: handle error codes if r.status_code == 400: # server says we have a problem... # let's give the info back to our human friend print r.json() else: chunk_size = 1024 # fusion server will stream an ODT file content back ext = targetformat.lower() with open('request_out.%s' % ext, 'wb') as fd: for chunk in r.iter_content(chunk_size): fd.write(chunk) files['tmpl_file'].close() files['img_logo'].close()
And voila. You have a file called out.odt that contains the final odt fusionned with your datadictionnary.
For the full source code + template file and images just download them from our repo
If you just want to test it rapidly you can also point your browser to the server http://localhost:8765/form and fill the form manually.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file py3o.fusion-0.2.zip
.
File metadata
- Download URL: py3o.fusion-0.2.zip
- Upload date:
- Size: 267.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | deded5e831d8c0362cbced861bae95ddaaf2a86e2aeb5f0512d894e78357f38d |
|
MD5 | 377602d7d20b4dcfb5545495d655771c |
|
BLAKE2b-256 | 93c2dc825c0da9f6936629d4a62fda33c4464a818f8e6f95a4a7a964f0cf1474 |
Provenance
File details
Details for the file py3o.fusion-0.2.tar.gz
.
File metadata
- Download URL: py3o.fusion-0.2.tar.gz
- Upload date:
- Size: 257.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d52a91e6d401b0673a39bbbda11639156ce20a9ade10530be5f805160b373498 |
|
MD5 | c2a6b784dfe85c81bf6a358f491b5d78 |
|
BLAKE2b-256 | 89960c5b5995bc8b3f1f431c22ed115ea10ccf4213e43c4c21f965d4906a11be |
Provenance
File details
Details for the file py3o.fusion-0.2-py2.7.egg
.
File metadata
- Download URL: py3o.fusion-0.2-py2.7.egg
- Upload date:
- Size: 269.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 378d534687ede1589c3eacc3aaae7bc7148fa502707e5c3e0932567f0c7dcfab |
|
MD5 | 074f53799e3d0f0ef7939c6c7ab35eb6 |
|
BLAKE2b-256 | 7cae96a05af3b7140879acab39d100d70d935f84fae5717b7cf1b2ee4d9f09a8 |
Provenance
File details
Details for the file py3o.fusion-0.2-py2-none-any.whl
.
File metadata
- Download URL: py3o.fusion-0.2-py2-none-any.whl
- Upload date:
- Size: 265.2 kB
- Tags: Python 2
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8ddcab91204596ae024c754d7be105ff17a65a38a2434e2aaa66698b2a8d7075 |
|
MD5 | 5c4933c097437d2eac9eb5a2eb148615 |
|
BLAKE2b-256 | 981c6fb54ee8f0c879c43da362d8e6022bae3c6f2faf5d81ca0e644d454e2ae9 |