I'm using sqlalchemy and psycopg to run SQL inside Python. However, there's a part of the code I want to hide when sending to other people (my passwords). Is there a way to do this?
This is how I sent to my colleagues last time, but the parts with XXXXXX were inserted by hand, I want to automate this:
import os
import sqlalchemy
pd.options.display.max_columns = 500
pd.options.display.max_rows = 500
from datetime import timedelta
import psycopg2
import csv
DB_USER = 'XXXXXX'
DB_PASS = 'XXXXXX'
DB_HOST = 'XXXXXX'
DB_PORT = XXXXXX
DB_NAME = 'xxxxxx'
def get_engine():
return sqlalchemy.create_engine(
'postgresql://{}:{}@{}:{}/{}'.format(DB_USER, DB_PASS, DB_HOST, DB_PORT, DB_NAME))
def run_query(query_txt):
engine = get_engine()
with engine.begin() as con:
return pd.read_sql(query_txt, con)
I found some related posts, like hide code in jupyter notebook and Hide selected code cells in Jupyter Notebook, but they didn't answer to my question.