Persist Excel/CSV sheets to MySQL (and vice versa)
Project description
exql
Persist Excel/CSV sheets to MySQL (and vice versa)
Installation
pip install exql
How it works
Convert a directory into a database and the .csv and .xls files in that directory to tables (or vice versa i.e. database/table to director/.csv). Currently, only .csv/.xsl to MySQL conversion is supported.
directory <==> database
CSV/Excel sheets in directory <==> tables in database
For example,
MyDir <-> CREATE SCHEMA MyDir;
|-file1.csv <-> CREATE TABLE file1 (...);
|-file2.xlsx <-> CREATE TABLE file2 (...);
Usage
Import exql and create an Exql object passing your MySQL username, password, etc.
from exql import exql
exql_obj = exql.Exql("root", "mysql@123", "localhost", 3306, False)
Create a database by passing path of directory to be converted to a DB. A sample directory is present in the resources directory
exql_obj.create_db_from_directory("/path/demo_university_db")
Similarly, other methds can be used to create individual tables, delete rows, etc.
| Method | Description |
|---|---|
| create_db_from_directory | Create MySQL DB with name same as the directory name and tables built using .csv/.xlsx files present within the directory |
| create_table_from_csv | Persist data from a .csv/.xslx file to a single MySQL table |
| insert_in_table | Insert data from .csv into existing table |
| select_into_csv | Select rows read from a DB using the provided query into a .csv |
| delete_from_db | Delete rows matching column-value pairs provided in .csv from MySQL table |
| write_db_to_dir | Create a directory containing all tables of a DB saved as .csv files |
Note
- In the .xsl or .csc files, SQL commands can be provided directly. Thus, the .csv or .xsl can have SQL queries as follows
| student_id | name | age | added_on |
|---|---|---|---|
| INT | VARCHAR(100) | INT | DATETIME |
| PRIMARY KEY | NOT NULL | NOT NULL | |
| 100001 | (SELECT UPPER('John Keats')) | 45 | now() |
| 100002 | 'William Shakespeare' | 23 | now() |
| (SELECT COUNT(*) FROM table2) | 'Robert Frost' | 54 | now() |
- Cells containing text must be enclosed in inverted commas or else they would be interpreted as SQL keywords/identifiers
- Refer to the
resourcesfolder for .csv/.xsl file templates needed for table creation/insertion/deletion
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file exql-1.0-py3-none-any.whl.
File metadata
- Download URL: exql-1.0-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
396ca05f37723e464ee5e8b974a9925061ecc583294ac40803b6db3d3e01782e
|
|
| MD5 |
685e682143496d1c002ca14f1900b967
|
|
| BLAKE2b-256 |
5af71ec7bd41fe3d3309f0c1425732c2a66b012522e0ae16953e1ff37b1db2b0
|