GithubHelp home page GithubHelp logo

csv-to-db's Introduction

CSV to DB (SQLite3)

CSV to DB (SQLite3) is a python based converter that converts any valid csv file into a file-based database file. It basically reads the csv and copies each row into the table of a database file with the same name.

Demo

Down below is the demo run of the program which converts demo.csv into demo.db. It writes all rows from demo.csv into demo.db in a table called t.

PS G:\csv_to_db> python .\csv_to_db.py .\demo.csv
[SUCCESS] CSV found: 'demo.csv'

Enter table name: t
[INFO] Table 't' has been created.

Processing: 100%|████████████████████████████████████████████████| 8.00/8.00 [00:00<?, ?r/s]
[SUCCESS] Database has been written.

** INFO **
Database name: demo.db
Database size: 12.0 KB
Table name   : t
Time taken   : 0.07 seconds
Rows written : 8
Rows skipped : 0

Features

  • Converts the csv into a database file (sqlite3)

  • Auto-adds and increments ID

  • Auto-infers column types

  • Highly optimized for larger CSVs

  • Errors handled like a pro!

  • Easy to use

  • That's it, it's not facebook or something..!!

Setup & Installation

Setting up this application in your pc is very easy. just follow below steps and you'll be fine.

Installing Python 3.x
  • Go to python.org and download latest python.

  • Install python into your pc and add path to enviroment variables. (follow a youtube video if stuck!)

  • Open terminal and run python --version to check if python is installed correctly!

Installing Dependencies
  • Open terminal in the project's directory.

  • Run pip install -r requirements.txt command.

  • It will install all libraries listed in the requirements.txt file.

Setting up CSV

Before conversion, make sure your csv is valid, clean, and contains a header line.

What is Header in a csv?

Header line in a csv is the first line which contains the names of the columns in the csv (separated by commas).

CSV file without header
Python,1991,Guido van Rossum
JavaScript,1995,Brendan Eich
C,1972,Dennis Ritchie
CSV file with header
title,appeared,creators
Python,1991,Guido van Rossum
JavaScript,1995,Brendan Eich
C,1972,Dennis Ritchie

Using the Program

Once you've followed the steps above, using this program should be a piece of cake!

  • Open terminal in the project directory.

  • Run python .\csv_to_db.py [csv_path\csv_name.csv]

    PS G:\csv_to_db> python .\csv_to_db.py .\test.csv
    [SUCCESS] CSV found: 'demo.csv'
    
  • If csv is found, it'll ask you for a table name. (Remember to abide the SQL rules for naming tables)

    Enter table name: test
    [INFO] Table 'test' has been created.
  • If the name is valid, it'll create a table of that name and starts the writing process.

    Processing: 100%|████████████████████████████████████████████████| 8.00/8.00 [00:00<?, ?r/s]
    [SUCCESS] Database has been written.

    r/s in the progressbar mean rows per second.

  • If all goes well, it'll write the csv into the .db file and show info like below

    ** INFO **
    Database name: demo.db
    Database size: 12.0 KB
    Table name   : t
    Time taken   : 0.07 seconds
    Rows written : 8
    Rows skipped : 0
  • Congratulations! you've successfully converted a csv into a database file.

Overview of the project

Libraries used in the project

10 libraries were used in this project. Only last 3 are third-party libraries.

os re sys time sqlite3 sqlparse csv tqdm colorama termcolor

Project's Root Directory

There are only 3 files in the project's root directory.

csv_to_db.py README.md requirements.txt


You are free to use this program however you like! No need to give credits to the developer (Well, not if you don't want to...)

Developer: Anas Shakeel

csv-to-db's People

Contributors

anas-shakeel avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.