so i created a postgresql database and i want to link it to my python code using sqlalchemy but since i made the database in pgadmin i dont know what to mention as the url of the database in the code. thank you in advance.
If you created your database using the defaults, you can probably login to the server using psql (SQL Shell).
Try to connect to the database you created and if you are able to connect to the database try \conninfo
.
If it's on your own machine the output will be quite standard host will be localhost
, ip will be 127.0.0.1
and port will be the default port of 5432
.
Once you make sure of these things you should try to connect to the database using the following code from this answer to a different question.
Please make sure you have both SQLAlchemy and psycopg2 installed before you try to connect. Then try this:
from sqlalchemy import create_engine
engine = create_engine('postgresql+psycopg2://user:password@hostname/database_name')
Or may be find a good tutorial on SQLAlchemy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With