# 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.
```python
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
Raw data
{
"_id": null,
"home_page": "https://github.com/jpsteil/pydlfmt",
"name": "pydlfmt",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": null,
"author": "Jim Steil",
"author_email": "jim@steilonline.com",
"download_url": "https://files.pythonhosted.org/packages/d2/fb/7f2bacc16001f4efc2155f2ed82a55e73dd0416909a8f5ce6094aa785f90/pydlfmt-0.0.12.tar.gz",
"platform": null,
"description": "# Python data list Formatter\n\nTake a list of data elements and transform them into a spreadsheet or PDF document.\n\n* Elements can be a dictionary, dataclass or any object\n* You specify which columns are to be included in the output\n* Columns can have custom formatting\n\nExample - Assuming the `data` variable has been loaded prior to this snippet.\n```python\ndf = DataFormatter(data=data)\ndf.columns = [\n Column(\"id\"),\n Column(\"name\"),\n Column(\"sex\"),\n Column(\"age\"),\n Column(\"year\"),\n Column(\"team\"),\n Column(\"sport\"),\n]\ndf.to_pdf(filename=os.path.join(\"../examples\", \"output\", \"sample.pdf\"))\ndf.to_excel(\n filename=os.path.join(\"../examples\", \"output\", \"sample.xlsx\"),\n format_table=True,\n)\n```\n* Create a DataFormatter instance\n* Define the columns that you want included in your output\n * Column `names` are used to match up with the input data column or element names\n* Call to_pdf or to_excel to build the output\n\n## Columns\nYou have a lot of control over how the column is displayed. The `Column` dataclass object has the following attributes.\n\n* 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.\n* heading - the column heading. Will default to the column name if none provided.\n* font_size - default 10 - for PDF, this is override the font size of the cell.\n* bold - default False - for PDF only, should this column be bold\n* justify - default LEFT - LEFT, CENTER or RIGHT\n* scalar - for Excel only - a scalar function that should be run on this column. Valid values are SUM, AVG\n* decimal_positions - number of decimal positions to round to\n* currency - should we display the $\n* excel_formula - an Excel formula that you want run to produce the output for this column\n* datatype - defualt str - what is the datatype for this column\n* wrap - default False - wrap text to fit in the column\n* width - the default width to use for this column\n* max_width - the maximum width - use to ensure longer fields get the width they need\n* paragraph_style - PDF only - pass in custom reportlab paragraph_style to be applied to all the cells in a column\n* include_commas - default False - should we include commas when printing numbers\n",
"bugtrack_url": null,
"license": null,
"summary": "pydlfmt will take a list of objects, dicts, etc and output them to a PDF or XLSX",
"version": "0.0.12",
"project_urls": {
"Homepage": "https://github.com/jpsteil/pydlfmt"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "389bcab77c53e4fd1cf79d43ade216e26958afc6f0fb458c0f55b22d5b6df041",
"md5": "8e945124fb66ec78fe1e3378b1ac7351",
"sha256": "11576fb081db5008b4b6192178eb6aa9c768f9ccbdc82aa9c2da29b3e81f32cf"
},
"downloads": -1,
"filename": "pydlfmt-0.0.12-py3-none-any.whl",
"has_sig": false,
"md5_digest": "8e945124fb66ec78fe1e3378b1ac7351",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 9309,
"upload_time": "2024-05-17T18:04:21",
"upload_time_iso_8601": "2024-05-17T18:04:21.955035Z",
"url": "https://files.pythonhosted.org/packages/38/9b/cab77c53e4fd1cf79d43ade216e26958afc6f0fb458c0f55b22d5b6df041/pydlfmt-0.0.12-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "d2fb7f2bacc16001f4efc2155f2ed82a55e73dd0416909a8f5ce6094aa785f90",
"md5": "ebc808743e734251c4de4a67e19604e3",
"sha256": "db26edea131a57d34e25aad24a41b220682ceead8f6b97cfc3e3a2f95fadab82"
},
"downloads": -1,
"filename": "pydlfmt-0.0.12.tar.gz",
"has_sig": false,
"md5_digest": "ebc808743e734251c4de4a67e19604e3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 11012,
"upload_time": "2024-05-17T18:04:23",
"upload_time_iso_8601": "2024-05-17T18:04:23.307462Z",
"url": "https://files.pythonhosted.org/packages/d2/fb/7f2bacc16001f4efc2155f2ed82a55e73dd0416909a8f5ce6094aa785f90/pydlfmt-0.0.12.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-17 18:04:23",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jpsteil",
"github_project": "pydlfmt",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "pytest",
"specs": []
},
{
"name": "python-dateutil",
"specs": []
},
{
"name": "reportlab",
"specs": []
},
{
"name": "xlsxwriter",
"specs": []
}
],
"lcname": "pydlfmt"
}