Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to specify Postgres schemas in SQLAlchemy connection strings? [duplicate]

I am currently migrating an existing Python program that uses SQLAlchemy, but almost exclusively via using the SQLAlchemy engines for use in Pandas dataframes (e.g., pandas to_sql). Currently the connection strings used in creating the engine are those of another database (namely MySQL), and accessing databases (analogous to Postgres schemas) is easily done. How would I best specify the schema (and not merely the Postgres database which contains them) within a given engine?

Edit: Someone seems to have labeled this question as being a duplicate. It is not. I am not looking to auto-generate queries by using Sessions; I am looking to create connection strings in order to create SQLAlchemy engines for use in Pandas' to_sql function.

like image 763
Dread Pirate Roberts Avatar asked Jan 17 '26 19:01

Dread Pirate Roberts


1 Answers

You can use blaze to connect to the postgreSQL and Metadata from SQL Alchemy

from blaze import data
from sqlalchemy import MetaData
ds = data(MetaData('postgresql://localhost/test', schema='my_schema')) 

before using blaze, install it by:

pip install blaze
like image 143
SillyPerson Avatar answered Jan 19 '26 07:01

SillyPerson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!