This package allows flet developers to easily import SQL, CSV, Excel or Json tables into flet's DataTable.
Project description
Simple DataTable
This is a third party package for a new framework Flet
. Simple DataTable
is capable of importing CSV
, Excel
, Json
or SQL
table into Flet
's DataTable
. Simple DataTable
uses a few different libraries for serializtion that must be installed according to requirements.txt.
Simple DataTable
returns DataTable
instance, there is no hardcoded values and anything can be changed according to Flet docs
Installation
Note: Publishing this package on PyPi is not planned yet, so you need to clone the repo.
-
Clone the repository into your project directory
git clone https://github.com/StanMathers/simple-datatable .
-
Install required packages
pip3 install -r requirements.txt
And you're good to go!
Examples
-
Importing a table from a CSV file
import flet as ft from simpledt import CSVDataTable def main(page: ft.Page): csv = CSVDataTable("dataset/MOCK_DATA.csv") dt = csv.datatable page.add(dt) ft.app(target=main)
-
Importing a table from a CSV url
import flet as ft from simpledt import CSVDataTable def main(page: ft.Page): csv = CSVDataTable("https://raw.githubusercontent.com/kb22/Heart-Disease-Prediction/master/dataset.csv") dt = csv.datatable page.add(dt) ft.app(target=main)
-
Importing a table from an Excel file
import flet as ft from simpledt import ExcelDataTable def main(page: ft.Page): excel = ExcelDataTable('dataset/Excel_MOCK_DATA.xlsx') dt = excel.datatable page.add(dt) ft.app(target=main)
-
Importing a table from a SQL table
import flet as ft from simpledt import SQLDataTable def main(page: ft.Page): sql = SQLDataTable('sqlite', 'data.db', 'users') dt = sql.datatable page.add(dt) ft.app(target=main)
Attributes
Every class returns Flet's DataTable, list of DataRow
and DataColumn
instances as attributes, so they can be changed according to Flet docs
After initializing any of the classes, the following attributes are available
- datatable - is a serialized DataTable instance
- datarows - is a list of serialized DataRow instance included in datatable attribute.
- datacolumns - is a list of serialized DataColumn instance included in datatable attribute
Classes
-
BaseDataTable()
Implements AbstractDataTable and is a parent class of all the other classess. BaseDataTable ensures setting up datatable, datacolumns and datarows which are common among other classes, so all its attributes are available among child classes.
-
CSVDataTable(csv_file: str)
Takes a CSV file, or CSV url as an argument for serialization
-
ExcelDataTable(excel_file: str)
Takes an Excel file as an argument for serialization
-
JsonDataTable(json_file: str)
Takes a Json file as an argument for serialization
-
SQLDataTable(sql_engine: str, database: str, table: str, user: str = None, password: str = None, host: str = None, port: int = None)
Takes a SQL database details as an argument for serialization
Required arguments
- sql_engine is a literal which can be sqlite, mysql, postgresql
- database is a database file, like data.sqlite3
- table is a SQL table which must be serialized
As for optional arguments, according to your choice of SQL, you can provide the following arguments
- user
- password
- host
- port
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.