The Set-up Functions
- dwopt.save_url(db_nme, url)
Use the system keyring service to save database engine url. See examples for quick-start.
A sqlalchemy engine url combines the user name, password, database names, etc into a single string.
The system keyring service is accessed via the keyring package. The service id is the full path to the dwopt package files. The service on Windows is the Windows Credential Manager.
- Parameters
db_nme (str) – Relevant database code. Either
pg
for postgre,lt
for sqlite, oroc
for oracle.url (str) – Sqlalchemy engine url.
- Returns
Message anouncing completion.
- Return type
str
Examples
Save connection urls for various databases.
>>> import dwopt >>> dwopt.save_url('pg' ... ,'postgresql://tiger:scott@localhost/mydatabase') 'Saved pg url to keyring' >>> dwopt.save_url('sqlite','sqlite:///foo.db') 'Saved lt url to keyring' >>> dwopt.save_url('oracle','oracle://tiger:scott@tnsname') 'Saved oc url to keyring'
Exit and re-enter python for it to take effect.
>>> from dwopt import pg, lt, oc >>> pg.run('select * from test') >>> lt.list_tables() >>> oc.qry('dual').head()
- dwopt.make_eng(url)
Make database connection engine.
A sqlalchemy engine url combines the user name, password, database names, etc into a single string. Engine object best to be created only once per application.
- Parameters
url (str) – Sqlalchemy engine url.
- Return type
sqlalchemy engine