Skip to main content

A SQL wrapper for python.

Project description

SQython

A wrapper for SQL and python.

requirments

  • psycopg2
  • os
  • numpy
  • io / StringIO
  • pandas

This was made to create an easier access to SQL through python

instalation

pip install sqython

example use cases


import sqython as sq

# creating a connection to my DB and creating a new database

conn = sq.create_connection("postgres", "postgres", "3301", 'localhost', 5432)
sq.execute_query(conn,sq.create_database('maxtest'))

# after creating we need to connect to our new database

conn = sq.create_connection("maxtest", "postgres", "3301", 'localhost', 5432)


# creating a table based on column names and datatypes to each of their respective columns

sq.execute_query(conn,sq.make_table('testtable',['test1','test2','test3'],['serial','char(50)','char(50)'],'test1'))


# sample DataFrame that we will insert

data = {'test1':[1,2,3],
       'test2':['max','luke','aids'],
       'test3':['a','B','c']}
data = pd.DataFrame(data)

# pushing the data to DB
sq.execute_many(conn,data,'testtable')


# example of deleting new table

sq.execute_query(conn,sq.delete_table('testtable'))

# if we want to delete the current database we must connect to a different one before deletion

conn = sq.create_connection("postgres", "postgres", "3301", 'localhost', 5432)
sq.execute_query(conn,sq.delete_database('maxtest'))


# example of altering a column name
sq.execute_query(conn,sq.alter_column_name(testtable,'test2','names'))

# example of changing an existing columns datatype
# changing column 'names' to varchar
sq.execute_query(conn,sq.alter_datatype(testtable,'names','VARCHAR'))

# to write your own query!

query = 'select * from table'

sq.execute_query(conn,query)

# Currently working on a more efficient and easy querying method

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

SQython-0.0.4.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file SQython-0.0.4.tar.gz.

File metadata

  • Download URL: SQython-0.0.4.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.59.0 CPython/3.7.9

File hashes

Hashes for SQython-0.0.4.tar.gz
Algorithm Hash digest
SHA256 c7f879b040f6bebda541f88ace0c2ef56dc3f4ce7ca46562d54acb63010bc0a6
MD5 6fa823ce84dd76184ec27556fee1a40c
BLAKE2b-256 d184d5e2971bdddeb7143652739e49dc868e65a47504f096838c01bde3e0e568

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