Skip to main content

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 resources folder for .csv/.xsl file templates needed for table creation/insertion/deletion

Project details


Release history Release notifications | RSS feed

This version

1.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

exql-1.0-py3-none-any.whl (13.3 kB view details)

Uploaded Python 3

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

Hashes for exql-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 396ca05f37723e464ee5e8b974a9925061ecc583294ac40803b6db3d3e01782e
MD5 685e682143496d1c002ca14f1900b967
BLAKE2b-256 5af71ec7bd41fe3d3309f0c1425732c2a66b012522e0ae16953e1ff37b1db2b0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page