Skip to main content

A simple sqlalchemy connection configuration manager

Project description

db_hooks

Extremely beta sqlalchemy and toml based sql connection manager.

config file

db_hooks looks for a local config file at ./.databases.toml in your working directory and then looks for a global config file using the appdirs library. Right now there isn't an obvious way to find this path, but running db_hooks list will bomb with a useful error message if the file isn't there. In general, try these locations:

os location
linux ~/.local/share/db_hooks/databases.toml
osx ~/Library/Application Support/db_hooks/databases.toml
windows 10 ~\AppData\local\jfhbrook\db_hooks

Keys in the TOML file are connection names. Under those are key/value pairs for the various parameters in a connection. Connections support the following parameters:

  • connection - a sqlalchemy-compatible connstring. May have a {password} f-string parameter.
  • password_cmd - a bash command that will be executed in order to fetch the password, which will be applied to connection as an f-string.

In general, one would use password_cmd to write a small snippet that fetches the password. This is designed to allow the most flexibility and therefore will depend on your needs.

For example, you may have a local postgres account and want to read the password using zenity:

[pg_example]
connection = "postgresql+psycopg2://josh:{password}@localhost:5432/josh"
password_cmd = "zenity --password"

in your code

Once you have a connection configured, you can load a sqlalchemy engine using the get_engine API:

from db_hooks import get_engine

engine = get_engine('pg_example')

This will pull the connection, run your password_cmd and give you a configured sqlalchemy engine.

Note that get_engine is cached with a cachetools.TTLCache configured with a ttl of 10 minutes.

the cli

db_hooks exposes a CLI that will launch either psql or mysql in a manner appropriate to the underlying connection. You can run db_hooks --help for hopefully useful help output.

licensing

This library is licensed under the Apache Software License. See the LICENSE and NOTICE files for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

db_hooks-0.3.1.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

db_hooks-0.3.1-py2.py3-none-any.whl (17.5 kB view details)

Uploaded Python 2Python 3

File details

Details for the file db_hooks-0.3.1.tar.gz.

File metadata

  • Download URL: db_hooks-0.3.1.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for db_hooks-0.3.1.tar.gz
Algorithm Hash digest
SHA256 fc5f3f488e023600c7ee8831fb467234d8778fa00261b4b5f585c0b8d10b2738
MD5 24664c09118752eb71b52d8053083c6c
BLAKE2b-256 fbeebf3322e30ca8f53c1b1bce924b8ff33463e9f607956984eb1382ea25f94d

See more details on using hashes here.

File details

Details for the file db_hooks-0.3.1-py2.py3-none-any.whl.

File metadata

  • Download URL: db_hooks-0.3.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 17.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.7.4

File hashes

Hashes for db_hooks-0.3.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b0d279a08ea0024146d2a7b0afa0a91b09bc782e165a0097fc7e9fff1a7df607
MD5 db29f9d626880487620cd8ca2f5e03c9
BLAKE2b-256 6ded33d5ebaa2e2bd4b3fb0dcc2a89e7e38ce2cfdea4f0288a26cf45c7cf8faf

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page