Skip to main content

pydlfmt will take a list of objects, dicts, etc and output them to a PDF or XLSX

Project description

Python data list Formatter

Take a list of data elements and transform them into a spreadsheet or PDF document.

  • Elements can be a dictionary, dataclass or any object
  • You specify which columns are to be included in the output
  • Columns can have custom formatting

Example - Assuming the data variable has been loaded prior to this snippet.

df = DataFormatter(data=data)
df.columns = [
    Column("id"),
    Column("name"),
    Column("sex"),
    Column("age"),
    Column("year"),
    Column("team"),
    Column("sport"),
]
df.to_pdf(filename=os.path.join("../examples", "output", "sample.pdf"))
df.to_excel(
    filename=os.path.join("../examples", "output", "sample.xlsx"),
    format_table=True,
)
  • Create a DataFormatter instance
  • Define the columns that you want included in your output
    • Column names are used to match up with the input data column or element names
  • Call to_pdf or to_excel to build the output

Columns

You have a lot of control over how the column is displayed. The Column dataclass object has the following attributes.

  • name - the name of the column. If your data list is a list of dictionaries, then this should match one of the keys of the dictionary. It must exist in all rows in the list. If you data list is a list of dataclasses or objects, then this much match one of the attributes of the object that exists in all rows of the list.
  • heading - the column heading. Will default to the column name if none provided.
  • font_size - default 10 - for PDF, this is override the font size of the cell.
  • bold - default False - for PDF only, should this column be bold
  • justify - default LEFT - LEFT, CENTER or RIGHT
  • scalar - for Excel only - a scalar function that should be run on this column. Valid values are SUM, AVG
  • decimal_positions - number of decimal positions to round to
  • currency - should we display the $
  • excel_formula - an Excel formula that you want run to produce the output for this column
  • datatype - defualt str - what is the datatype for this column
  • wrap - default False - wrap text to fit in the column
  • width - the default width to use for this column
  • max_width - the maximum width - use to ensure longer fields get the width they need
  • paragraph_style - PDF only - pass in custom reportlab paragraph_style to be applied to all the cells in a column
  • include_commas - default False - should we include commas when printing numbers

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

pydlfmt-0.0.12.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydlfmt-0.0.12-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file pydlfmt-0.0.12.tar.gz.

File metadata

  • Download URL: pydlfmt-0.0.12.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.19

File hashes

Hashes for pydlfmt-0.0.12.tar.gz
Algorithm Hash digest
SHA256 db26edea131a57d34e25aad24a41b220682ceead8f6b97cfc3e3a2f95fadab82
MD5 ebc808743e734251c4de4a67e19604e3
BLAKE2b-256 d2fb7f2bacc16001f4efc2155f2ed82a55e73dd0416909a8f5ce6094aa785f90

See more details on using hashes here.

File details

Details for the file pydlfmt-0.0.12-py3-none-any.whl.

File metadata

  • Download URL: pydlfmt-0.0.12-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.0 CPython/3.9.19

File hashes

Hashes for pydlfmt-0.0.12-py3-none-any.whl
Algorithm Hash digest
SHA256 11576fb081db5008b4b6192178eb6aa9c768f9ccbdc82aa9c2da29b3e81f32cf
MD5 8e945124fb66ec78fe1e3378b1ac7351
BLAKE2b-256 389bcab77c53e4fd1cf79d43ade216e26958afc6f0fb458c0f55b22d5b6df041

See more details on using hashes here.

Supported by

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