{"id":20326059,"url":"https://github.com/matteoguadrini/pyreports","last_synced_at":"2025-08-19T14:32:40.313Z","repository":{"id":39374846,"uuid":"335012344","full_name":"MatteoGuadrini/pyreports","owner":"MatteoGuadrini","description":"pyreports is a python library that allows you to create complex report from various sources","archived":false,"fork":false,"pushed_at":"2024-04-12T14:37:28.000Z","size":4982,"stargazers_count":96,"open_issues_count":0,"forks_count":7,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-04-13T02:42:59.958Z","etag":null,"topics":["cli","cli-application","complex-reports","database","database-manager","database-table","dataset","dataset-generation","file-manager","filter","ldap","ldap-manager","practices","python","python-library","report","report-generator","reporting-tool","reports"],"latest_commit_sha":null,"homepage":"https://matteoguadrini.github.io/pyreports","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MatteoGuadrini.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2021-02-01T16:28:54.000Z","updated_at":"2024-04-15T12:33:05.005Z","dependencies_parsed_at":"2024-03-08T09:23:48.188Z","dependency_job_id":"c97c269e-613d-4147-8b06-8d22fcf0c593","html_url":"https://github.com/MatteoGuadrini/pyreports","commit_stats":{"total_commits":415,"total_committers":1,"mean_commits":415.0,"dds":0.0,"last_synced_commit":"2c094396ee51f6ee6c9f496dfc099360fe79a36f"},"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatteoGuadrini%2Fpyreports","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatteoGuadrini%2Fpyreports/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatteoGuadrini%2Fpyreports/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MatteoGuadrini%2Fpyreports/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MatteoGuadrini","download_url":"https://codeload.github.com/MatteoGuadrini/pyreports/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230359935,"owners_count":18214157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cli","cli-application","complex-reports","database","database-manager","database-table","dataset","dataset-generation","file-manager","filter","ldap","ldap-manager","practices","python","python-library","report","report-generator","reporting-tool","reports"],"created_at":"2024-11-14T19:42:47.442Z","updated_at":"2025-08-19T14:32:40.292Z","avatar_url":"https://github.com/MatteoGuadrini.png","language":"Python","funding_links":["https://www.paypal.me/guos"],"categories":[],"sub_categories":[],"readme":"# pyreports\n\n\u003cimg src=\"https://pyreports.readthedocs.io/en/latest/_static/pyreports.svg\" alt=\"pyreports\" title=\"pyreports\" width=\"300\" height=\"300\" /\u003e\n\n[![Codacy Badge](https://app.codacy.com/project/badge/Grade/2bad30d308414c83836f22f012c98649)](https://www.codacy.com/gh/MatteoGuadrini/pyreports/dashboard?utm_source=github.com\u0026amp;utm_medium=referral\u0026amp;utm_content=MatteoGuadrini/pyreports\u0026amp;utm_campaign=Badge_Grade)\n[![CircleCI](https://circleci.com/gh/MatteoGuadrini/pyreports.svg?style=svg)](https://circleci.com/gh/MatteoGuadrini/pyreports)\n\n_pyreports_ is a python library that allows you to create complex reports from various sources such as databases, \ntext files, ldap, etc. and perform processing, filters, counters, etc. \nand then export or write them in various formats or in databases.\n\n## Test package\n\nTo test the package, follow these instructions:\n\n```console\n$ git clone https://github.com/MatteoGuadrini/pyreports.git\n$ cd pyreports\n$ python -m unittest discover tests\n```\n\n## Install package\n\nTo install package, follow these instructions:\n\n```console\n$ pip install pyreports #from pypi\n\n$ git clone https://github.com/MatteoGuadrini/pyreports.git #from official repo\n$ cd pyreports\n$ pip install .     # or python setup.py install\n```\n\n## Why choose this library?\n\n_pyreports_ wants to be a library that simplifies the collection of data from multiple sources such as databases, \nfiles and directory servers (through LDAP), the processing of them through built-in and customized functions, \nand the saving in various formats (or, by inserting the data in a database).\n\n## How does it work\n\n_pyreports_ uses the [**tablib**](https://tablib.readthedocs.io/en/stable/) library to organize the data into _Dataset_ object.\n\n### Simple report\n\nI take the data from a database table, filter the data I need and save it in a csv file\n\n```python\nimport pyreports\n\n# Select source: this is a DatabaseManager object\nmydb = pyreports.manager('mysql', host='mysql1.local', database='login_users', user='dba', password='dba0000')\n\n# Get data\nmydb.execute('SELECT * FROM site_login')\nsite_login = mydb.fetchall()\n\n# Filter data\nerror_login = pyreports.Executor(site_login)\nerror_login.filter([400, 401, 403, 404, 500])\n\n# Save report: this is a FileManager object\noutput = pyreports.manager('csv', '/home/report/error_login.csv')\noutput.write(error_login.get_data())\n\n```\n\n### Combine source\n\nI take the data from a database table, and a log file, and save the report in json format\n\n```python\nimport pyreports\n\n# Select source: this is a DatabaseManager object\nmydb = pyreports.manager('mysql', host='mysql1.local', database='login_users', user='dba', password='dba0000')\n# Select another source: this is a FileManager object\nmylog = pyreports.manager('file', '/var/log/httpd/error.log')\n\n# Get data\nmydb.execute('SELECT * FROM site_login')\nsite_login = mydb.fetchall()\nerror_log = mylog.read()\n\n# Filter database\nerror_login = pyreports.Executor(site_login)\nerror_login.filter([400, 401, 403, 404, 500])\nusers_in_error = set(error_login.select_column('users'))\n\n# Prepare log\nmyreport = dict()\nlog_user_error = pyreports.Executor(error_log)\nlog_user_error.filter(list(users_in_error))\nfor line in log_user_error:\n    for user in users_in_error:\n        myreport.setdefault(user, [])\n        myreport[user].append(line)\n\n# Save report: this is a FileManager object\noutput = pyreports.manager('json', '/home/report/error_login.json')\noutput.write(myreport)\n\n```\n\n### Report object\n\n```python\nimport pyreports\n\n# Select source: this is a DatabaseManager object\nmydb = pyreports.manager('mysql', host='mysql1.local', database='login_users', user='dba', password='dba0000')\noutput = pyreports.manager('xlsx', '/home/report/error_login.xlsx', mode='w')\n\n# Get data\nmydb.execute('SELECT * FROM site_login')\nsite_login = mydb.fetchall()\n\n# Create report data\nreport = pyreports.Report(site_login, title='Site login failed', filters=[400, 401, 403, 404, 500], output=output)\n# Filter data\nreport.exec()\n# Save data on file\nreport.export()\n\n```\n\n### ReportBook collection object\n\n```python\nimport pyreports\n\n# Select source: this is a DatabaseManager object\nmydb = pyreports.manager('mysql', host='mysql1.local', database='login_users', user='dba', password='dba0000')\n\n# Get data\nmydb.execute('SELECT * FROM site_login')\nsite_login = mydb.fetchall()\n\n# Create report data\nreport_failed = pyreports.Report(site_login, title='Site login failed', filters=[400, 401, 403, 404, 500])\nreport_success = pyreports.Report(site_login, title='Site login success', filters=[200, 201, 202, 'OK'])\n# Filter data\nreport_failed.exec()\nreport_success.exec()\n# Create my ReportBook object\nmy_report = pyreports.ReportBook([report_failed, report_success])\n# Save data on Excel file, with two worksheet ('Site login failed' and 'Site login success')\nmy_report.export(output='/home/report/site_login.xlsx')\n\n```\n\n## Tools for dataset\n\nThis library includes many tools for handling data received from databases and files. \nHere are some practical examples of data manipulation.\n\n```python\nimport pyreports\n\n# Select source: this is a DatabaseManager object\nmydb = pyreports.manager('mysql', host='mysql1.local', database='login_users', user='dba', password='dba0000')\n\n# Get data\nmydb.execute('SELECT * FROM site_login')\nsite_login = mydb.fetchall()\n\n# Most common error\nmost_common_error_code = pyreports.most_common(site_login, 'code')  # args: Dataset, column name\nprint(most_common_error_code)   # 200\n\n# Percentage of error 404\npercentage_error_404 = pyreports.percentage(site_login, 404)    # args: Dataset, filter\nprint(percentage_error_404)   # 16.088264794 (percent)\n\n# Count every error code\ncount_error_code = pyreports.counter(site_login, 'code')  # args: Dataset, column name\nprint(count_error_code)   # Counter({200: 4032, 201: 42, 202: 1, 400: 40, 401: 38, 403: 27, 404: 802, 500: 3})\n```\n\n### Command line\n\n```console\n$ cat car.yml\nreports:\n  - report:\n    title: 'Red ford machine'\n    input:\n      manager: 'mysql'\n      source:\n      # Connection parameters of my mysql database\n        host: 'mysql1.local'\n        database: 'cars'\n        user: 'admin'\n        password: 'dba0000'\n      params:\n        query: 'SELECT * FROM cars WHERE brand = %s AND color = %s'\n        params: ['ford', 'red']\n    # Filter km\n    filters: [40000, 45000]\n    output:\n      manager: 'csv'\n      filename: '/tmp/car_csv.csv'\n\n$ report car.yaml\n```\n\n## Official docs\n\nIn the following links there is the [official documentation](https://pyreports.readthedocs.io/en/latest/), for the use and development of the library.\n\n* Managers: [doc](https://pyreports.readthedocs.io/en/latest/managers.html)\n* Executor: [doc](https://pyreports.readthedocs.io/en/latest/executors.html)\n* Report: [doc](https://pyreports.readthedocs.io/en/latest/report.html)\n* data tools: [doc](https://pyreports.readthedocs.io/en/latest/datatools.html)\n* examples: [doc](https://pyreports.readthedocs.io/en/latest/example.html)\n* API: [io](https://pyreports.readthedocs.io/en/latest/dev/io.html), [core](https://pyreports.readthedocs.io/en/latest/dev/core.html)\n* CLI: [cli](https://pyreports.readthedocs.io/en/latest/dev/cli.html)\n\n## Open source\n_pyreports_ is an open source project. Any contribute, It's welcome.\n\n**A great thanks**.\n\nFor donations, press this\n\nFor me\n\n[![paypal](https://www.paypalobjects.com/en_US/i/btn/btn_donateCC_LG.gif)](https://www.paypal.me/guos)\n\nFor [Telethon](http://www.telethon.it/)\n\nThe Telethon Foundation is a non-profit organization recognized by the Ministry of University and Scientific and Technological Research.\nThey were born in 1990 to respond to the appeal of patients suffering from rare diseases.\nCome today, we are organized to dare to listen to them and answers, every day of the year.\n\n\u003ca href=\"https://www.telethon.it/sostienici/dona-ora\"\u003e \u003cimg src=\"https://www.telethon.it/dev/_nuxt/img/c6d474e.svg\" alt=\"Telethon\" title=\"Telethon\" width=\"200\" height=\"104\" /\u003e \u003c/a\u003e\n\n[Adopt the future](https://www.ioadottoilfuturo.it/)\n\n\n## Acknowledgments\n\nThanks to Mark Lutz for writing the _Learning Python_ and _Programming Python_ books that make up my python foundation.\n\nThanks to Kenneth Reitz and Tanya Schlusser for writing the _The Hitchhiker’s Guide to Python_ books.\n\nThanks to Dane Hillard for writing the _Practices of the Python Pro_ books.\n\nSpecial thanks go to my wife, who understood the hours of absence for this development. \nThanks to my children, for the daily inspiration they give me and to make me realize, that life must be simple.\n\nThanks Python!","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatteoguadrini%2Fpyreports","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmatteoguadrini%2Fpyreports","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmatteoguadrini%2Fpyreports/lists"}