A simple PYODBC/SQLAlchemy wrapper for connection handling
Project description
EuroDB Lib
TLDR
Generate/Fill your config file and use :
import eurodb
import pandas as pd
db = connect()
data : pandas.Dataframe = db.query("select stuff from somewhere")
Setup
Install it with :
pip install eurodb
Input your credentials into a JSON file of your choosing with the given format (default name is dblogs.json
) :
> dblogs.json
[{
"name": "Thefirstone",
"server": "tcp:somefunnyurl.windows.net",
"username": "johndoofus",
"database": "veryprivatedata",
"password": "dontsharethisplz"
},
{
"name": "thecorrectone",
"server": "tcp:somefunnyurl.windows.net",
"username": "notjohndoofus",
"database": "notveryprivatedata",
"password": "sharethisplz"
}]
Yes it has to be an array even if it's only one entry.
Now you can connect to the DB and query stuff easily like so :
import eurodb
db = eurodb.connect()
# If you don't have a file containing the login credentials ready, it will generate one for you
# else, you can specify it's name
db = eurodb.connect("connectionFile.json")
# By default, it will connect using the first entry but,
# If you have multiple connections in the file, you can specify which one to use.
# With the example file displayed above, you could use the second entry as so :
db = eurodb.connect("dblogs.json", connName="thecorrectone")
# Carefull, the `.query` function will be using the last called/loaded entry :
data = db.query("SELECT * from stuff") #would be using "thecorrectone"
db.__loadConnection__("Thefirstone")
data = db.query("SELECT * from stuff") #would be using "Thefirstone"
The return variable will be a pandas dataframe with the desired output.
The underlying library used for the SQL results is PYODBC. Running a query will create a new Connection and a Cursor, returning both objects at once.
If you wish to collect your results manually, use the engine method :
import eurodb
db = connect("dblogs.json", connName="reader")
eg = db.getEngine()
with eg.begin() as conn:
cursor = conn.execute(stx("SELECT * from res.allRegions where country = 'FR' and geocode like '10%'"))
data = cursor.fetchall()
print(data)
conn.execute requires special formatting provided by the
sqlalchemy.text()
function, shortened tostx()
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file eurodb-1.0.1.tar.gz
.
File metadata
- Download URL: eurodb-1.0.1.tar.gz
- Upload date:
- Size: 3.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29ef91b23ae12021b0228c4483f77bc0827989f17796bf8e9606336d4703d0e7 |
|
MD5 | b64a275941c60ba769b53cff154ffe7c |
|
BLAKE2b-256 | d2ca2a8f365b41f5da0328758289117b1eac40786a34d0c79a53d6ec6dd2cb8d |