pythonGrid is an easy way to create a fully working datagrid for Python web framework that connects to a relation database such as Postgres or MySql/MariaDB database. Currently only Flask framework is supported. More frameworks support are coming.
- Python 3.6+
- Flask (Django, Web2Py, CherryPy and other major web frameworks support are coming)
- SQLAlchemy
A couple quick start options are available:
- Download the latest release
- Clone the repo (recommended):
git clone https://github.com/pycr/pythongrid.git
Within the download you will see something like this:
├── LICENSE
├── README.md
├── app
│ ├── __init__.py
│ ├── data.py
│ ├── grid.py
│ ├── export.py
│ ├── routes.py
│ ├── static
│ └── templates
│ ├── 404.html
│ ├── base.html
│ ├── grid.html
│ └── index.html
├── sample
│ ├── sampledb_postgres.sql
│ ├── sampledb_mysql.sql
├── config.py
├── index.py
└── requirements.txt
pythonGrid current has two main files in grid.py
and data.py
in app folder.
-
grid.py
is the main Python class that is responsible for creating the datagrid table. It relies on jqGrid, a popular jQuery datagrid plugin, to render grids in the browser. -
data.py
is a Python class that returns the data via AJAX to populate the grid from a database. -
static
contains all of the client side Javascript and CSS files used for rendering.
Find the sample database in folder sampledb. Using your favorite MySQL os Postgres client (more database supports are coming).
- Create a new database named
sampledb
- Run the sample sql script.
First of all, if you don't have Python installed on your computer, download and install from the Python official website now.
To make sure your Python is functional, type python3
in a terminal window, or just python
if that does not work. Here is what you should expect to see:
Python 3.6.3 (v3.6.3:2c5fed86e0, Oct 3 2017, 00:32:08)
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Next, you need to install Flask framework. You got two options.
It is highly recommended to use Python virtual environment. Basically, a Python virtual environment is a self-contained separate copy of Python installation. Different applications can then use different virtual environments with different copy of Python without worrying about system permissions.
The following command will creates a virtual environment named venv
stored in a directory also named venv
.
python3 -m venv venv
Activate the new virtual environment:
source venv/bin/activate
Now the terminal prompt is modified to include the name of the activated virtual environment
(venv) $ _
With a new virtual environment created and activated, finally let's install dependents:
pythonGrid uses SQLAlchemy to support different types of database.
pip install -r requirements.txt
Find file config.py
, and set the database connection properties according to your environment. The demo uses MySQL database.
You can also use a socket to connect to your database without specifying a database host name.
PYTHONGRID_DB_HOSTNAME = 'mysqldatabase.example.com'
PYTHONGRID_DB_NAME = 'sampledb'
PYTHONGRID_DB_USERNAME = 'root'
PYTHONGRID_DB_PASSWORD = 'root'
PYTHONGRID_DB_TYPE = 'mysql+pymysql'