Skip to main content

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

Metadata

Release files for pydlfmt 0.0.12

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pydlfmt 0.0.12
File Size Uploaded
pydlfmt-0.0.12.tar.gz 11.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pydlfmt 0.0.12
File Interpreter ABI Platform
pydlfmt-0.0.12-py3-none-any.whl Python 3 none any Details

Total release size: 20.3 kB

Release files / pydlfmt-0.0.12.tar.gz

Download URL pydlfmt-0.0.12.tar.gz
Size 11.0 kB
Tags Source
SHA-256 checksum
How to use checksums
db26edea131a57d34e25aad24a41b220682ceead8f6b97cfc3e3a2f95fadab82
BLAKE2b-256 checksum
How to use checksums
d2fb7f2bacc16001f4efc2155f2ed82a55e73dd0416909a8f5ce6094aa785f90
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.9.19

Release files / pydlfmt-0.0.12-py3-none-any.whl

Download URL pydlfmt-0.0.12-py3-none-any.whl
Size 9.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
11576fb081db5008b4b6192178eb6aa9c768f9ccbdc82aa9c2da29b3e81f32cf
BLAKE2b-256 checksum
How to use checksums
389bcab77c53e4fd1cf79d43ade216e26958afc6f0fb458c0f55b22d5b6df041
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.0 CPython/3.9.19

Release history Release notifications | RSS feed

This release

0.0.12 This release

2 release files

0.0.11

2 release files

0.0.10

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page