Skip to main content

A python module for converting csv files to sqlite and back.

Project description

CI

pycsvtosqliteroh

The pycsvtosqliteroh module is a module to convert csv to sqlite and back.

Table of contents

  1. Introduction
  2. Getting started
    1. Prerequisites
    2. Installation
  3. How to use
    1. How to import
    2. Using the module
    3. Using the cli
  4. Releasing
  5. License

Introduction

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.

Getting started

Prerequisites

  • Python installed
  • Operatingsystem: Linux or Windows, not tested on mac
  • IDE like VS Code, if you want to contribute or change the code

Installation

There are two ways to install this module depending on the way you work and the preinstalled modules:

  1. pip install pycsvtosqliteroh
  2. python -m pip install pycsvtosqliteroh

How to use

How to Import

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.

Using the module

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()

Using the cli

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"

Releasing

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

License

MIT

Project details


Download files

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

Source Distribution

pycsvtosqliteroh-0.0.1.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

pycsvtosqliteroh-0.0.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file pycsvtosqliteroh-0.0.1.tar.gz.

File metadata

  • Download URL: pycsvtosqliteroh-0.0.1.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.9

File hashes

Hashes for pycsvtosqliteroh-0.0.1.tar.gz
Algorithm Hash digest
SHA256 5e336e22e06d934bdc3cf14cdfeb4f73aaaf623da6f5f7dba22fec6228f8ba34
MD5 690efd7d87e5ad3e2833cdd1df23ed8d
BLAKE2b-256 5ad0cad804aa02ab25d6a6ca57d90862d3de0a9965cf38098dded175ad463957

See more details on using hashes here.

File details

Details for the file pycsvtosqliteroh-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pycsvtosqliteroh-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b30e9351c5a90cfd0584fa7a7fa8d3e9655b3a6c9753048256b867c65b1d87ef
MD5 5459fab59e55af365381cf3c59b0d1cc
BLAKE2b-256 c50f7feccdbbafa6ce60f2004da5d305f9e123d4cfba2f899b370b4a81b7720d

See more details on using hashes here.

Supported by

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