The pycsvtosqliteroh module is a module to convert csv to sqlite and back.
I've written this module to bulk convert csv files into sqlite tables. The database is used as a test database in another project.
The supported delimiters for the .csv file are "," and ";".
All testfiles in the testfiles folder, are created via powershell, using the Export-Csv
cmdlet with different delimiters.
You can now convert csv to sqlite as well as sqlite to csv. When exporting a sqlite table to .csv the delimiter is "," by default.
- Python installed
- Operatingsystem: Linux or Windows, not tested on mac
- IDE like VS Code, if you want to contribute or change the code
There are two ways to install this module depending on the way you work and the preinstalled modules:
pip install pycsvtosqliteroh
python -m pip install pycsvtosqliteroh
You can import the module in two ways:
import pycsvtosqliteroh
- This will import all functions. Even the ones that are not supposed to be used (helper functions).
from pycsvtosqliteroh import *
- This will import only the significant functions, meant for using.
Depending on the way you imported the module, the following examples look a bit different.
Example 1: Converting csv to sqlite.
# Import module.
from pycsvtosqliteroh import *
# Create object and than convert to sqlite table.
csvobj = CsvToSqlite(file, database)
csvobj.create_table_from_csv()
Example 2: Converting sqlite table to csv file.
# Import module.
from pycsvtosqliteroh import *
# Create object and than convert to .csv file.
sqliteobj = SqliteToCsv(file, database, tablename)
sqliteobj.convert_table_to_csv()
To show the help run the following command:
python -m pycsvtosqliteroh.main -h
Result:
usage: __main__.py [-h] [-file FILE] [-db DATABASE] [-table TABLENAME]
options:
-h, --help show this help message and exit
CsvToSqlite:
-file FILE, --file FILE
Csv file that will be converted.
-db DATABASE, --database DATABASE
Sqlite database.
-table TABLENAME, --tablename TABLENAME
Sqlite table.
Using the conversion:
Converts a .csv file to a sqlite table:
python -m pycsvtosqliteroh --file "Filename" --database "TestDb.sqlite"
Converts a sqlite table to a .csv file:
python -m pycsvtosqliteroh --file "NewFileCreated" --database "TestDb.sqlite" --table "Tablename"
Releases are published automatically when a tag is pushed to GitHub.
# Create release variable.
$Release = "x.x.x"
# Create commit.
git commit --allow-empty -m "Release $Release"
# Create tag.
git tag -a $Release -m "Version $Release"
# Push from original.
git push origin --tags
# Push from fork.
git push upstream --tags