Simple HTML and PDF document generator for Python.
Project description
esparto
Introduction
esparto is a simple HTML and PDF document generator for Python. The API design emphasises
productivity and reliability over flexibility or complexity - although you should find that it serves many
use cases more than adequately. esparto is suitable for tasks such as:
- Designing simple web pages
- Automated MI reporting
- Collating and sharing data graphics
- ML model performance and evaluation documents
Main Features
- Lightweight API
- Jupyter Notebook support
- Output self-contained HTML and PDF files
- Responsive layout from Bootstrap
- No CSS or HTML required
- Automatic conversion for:
- Markdown
- Images
- Pandas DataFrames
- Matplotlib
- Bokeh
- Plotly
Installation
esparto is available from PyPI:
pip install esparto
If PDF output is required, weasyprint must also be installed:
pip install weasyprint
Dependencies
- python >= 3.6
- jinja2
- markdown
- Pillow
- weasyprint (optional - for PDF output)
License
Documentation
Full documentation and examples are available at domvwt.github.io/esparto/.
Basic Usage
import esparto as es
# Instantiating a Page
page = es.Page(title="Research")
# Page layout hierarchy:
# Page -> Section -> Row -> Column -> Content
# Add or update content
# Keys are used as titles
page["Introduction"]["Part One"]["Item A"] = "lorem ipsum"
page["Introduction"]["Part One"]["Item B"] = "./pictures/image1.jpg"
# Add content without a title
page["Introduction"]["Part One"][""] = "Hello, Wolrd!"
# Replace child at index - useful if no title given
page["Introduction"]["Part One"][-1] = "Hello, World!"
# Set content and return input object
# Useful in Jupyter Notebook as it will be displayed in cell output
page["Methodology"]["Part One"]["Item A"] << "dolor sit amet"
# >>> "dolor sit amet"
# Set content and return new layout
page["Methodology"]["Part Two"]["Item B"] >> "foobar"
# >>> {'Item B': ['Markdown']}
# Show document structure
page.tree()
# >>> {'Research': [{'Introduction': [{'Part One': [{'Item A': ['Markdown']},
# {'Item B': ['Image']}]}]},
# {'Methodology': [{'Part One': [{'Item A': ['Markdown']}]},
# {'Part Two': [{'Item A': ['Markdown']}]}]}]}
# Remove content
del page["Methodology"]["Part One"]["Item A"]
del page.methodology.part_two.item_b
# Access existing content as an attribute
page.introduction.part_one.item_a = "./pictures/image2.jpg"
page.introduction.part_one.tree()
# >>> {'Part One': [{'Item A': ['Image']},
# {'Item B': ['Image']},
# {'Column 2': ['Markdown']}]}
# Save the document
page.save_html("my-page.html")
page.save_pdf("my-page.pdf")
Example Output
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 Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file esparto-1.1.0.dev1.tar.gz.
File metadata
- Download URL: esparto-1.1.0.dev1.tar.gz
- Upload date:
- Size: 43.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.10 CPython/3.8.5 Linux/4.19.128-microsoft-standard
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e79c4de5cb7b21f4fc538621a364bc418ed94b12e966a934145ef40602960e1
|
|
| MD5 |
38448cdeddc2b8977d3a9871d4cd79b6
|
|
| BLAKE2b-256 |
64cf369f3811016ac8538439ca3bf1a90185b8b2dd4d6de6c12f1b10c66950f3
|
File details
Details for the file esparto-1.1.0.dev1-py3-none-any.whl.
File metadata
- Download URL: esparto-1.1.0.dev1-py3-none-any.whl
- Upload date:
- Size: 44.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.0.10 CPython/3.8.5 Linux/4.19.128-microsoft-standard
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ae0b4c4d345a9b7713b8c5b9bfbbdbaefada3269f150cc771740b4f2773819b
|
|
| MD5 |
205f9fba8b481bf17f1f14f986bdd260
|
|
| BLAKE2b-256 |
1255d096bf359c8d61da4fb34b50bc21c28bba039150a6a7df4fb0473c243175
|