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
esparto-1.1.0.dev2.tar.gz
(43.0 kB
view hashes)
Built Distribution
Close
Hashes for esparto-1.1.0.dev2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf95f976742c99383bdc0f28139a741b747d10ec9a09f149a9c850aba5f56fa8 |
|
MD5 | b63b55dd3736b07dc10f2990cb74c57c |
|
BLAKE2b-256 | a1e665279de3f2044e7ce21f663905a8a59b478c1e39339fee163514babe2956 |