Skip to main content

DataframeToDB


This project is a personal non-profit project rather than accepting donations to buy more coffee and carry out more open source projects!

If you want to donate: https://ko-fi.com/juanretamales

Introduction

DataframeToDB is an improved way to upload pandas dataframes to Microsoft SQL Server, MySQL, PostgreDB and support for other type of database.

DataframeToDB takes advantage of SQLAlchemy. This allows for a much lighter weight import for writing pandas dataframes to db server.

When to use:

  • When you need save dataframes, for example when scraping many tables
  • You need shared a database estructure for use in proyects
  • When you need save multi excels (ported to dataframed) in a database
  • When you consider use FastAPI (With the SQLAlchemy compatibility) (Work in progress)
  • When you need create a estructure of table for any reason

Installation


For instalation you can copy the dataframetodb folder into your proyect from github, or

pip install dataframetodb

Requirements


  • Written for Python 3.8+
  • numpy>=1.20.2
  • pandas>=1.2.4
  • python-dateutil>=2.8.1
  • SQLAlchemy>=1.4.9
  • driver for db conection

Example - Save dataframe into database


import pandas as pd
import dataframetodb
from dataframetodb import Table, refactor
from datetime import datetime
import os

nametable = "nameTable"
engine = dataframetodb.create_engine('sqlite:///{}.sqlite'.format(nametable)) #create engine for use SQLAlchemy
df = pd.read_csv("./dataset/data.csv") # Get the DataFrame
df = refactor(df) # Returns a dataframe with the correct dtype compatible with DataframeToDB.
table_class = Table(name=nametable, df=df) #create Table instance
table_class.toDb(df, engine, 'append') #insert data in database, in this example sqlite

How to work

The Table of DataframeToDB is a custom class who generate a SQLAlchemy Table when you call getTable function.

USAGE

For more information, you can view the documentation in github or view de documentation of code.

FAQ

What databases does DataframeToDB support?

The same as SQLAlchemy, for now they are SQLite, Postgresql, MySQL, Oracle, MS-SQL, Firebird, Sybase and others. But you should check this link.

why use json and not pickle?

It really cost me to decide, while pickle is faster, json is more transparent and it is easier to make modifications and transfers of files between projects, also it is expected that json can be used not only in tables, if not, in the entire database.

why did you decide to create this library?

For scrapping projects it is very tedious to be configuring tables, I wanted something more automatic, I found one but it was only compatible with MS-SQL, and in projects that could not afford that database I decided to create this and create things that I felt were missing.

When launch the 1.X release?

When y tested all function i like for a table, my plans is 0.X i create all function for transport a dataframe to db and work, in the 1.X i tried to create database class who extends the functions for work with Database.

Cats or Dogs?

Pandas!!! ...ba dum tss...

Metadata

Release files for dataframetodb 1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for dataframetodb 1.0
File Size Uploaded Provenance
dataframetodb-1.0.tar.gz 36.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for dataframetodb 1.0
File Interpreter ABI Platform
dataframetodb-1.0-py3-none-any.whl Python 3 none any Details

Total release size: 74.3 kB

Release files / dataframetodb-1.0.tar.gz

Download URL dataframetodb-1.0.tar.gz
Size 36.8 kB
Tags Source
SHA-256 checksum
How to use checksums
fdd3737b2e48243e101fbd6c0180b5e57108dc7d3fa97fbd324be91ec245c7fc
BLAKE2b-256 checksum
How to use checksums
7503cde863495ac9c93063d463239912d8fbe422e4d355dacaf689ad2541a265
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.4

Release files / dataframetodb-1.0-py3-none-any.whl

Download URL dataframetodb-1.0-py3-none-any.whl
Size 37.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f3fbdacfe2e82d504fc3ad13614facaa58fc1f3d64f42ae8757e677bd6363f3d
BLAKE2b-256 checksum
How to use checksums
0787671f42739dca1c13b09728fdd8ad23d08177ba8d4395d07c1191e79d427c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.9.4

Security for dataframetodb 1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page