https://github.com/mdcatapult/py-postgres
Methods to simplify configuring and connecting to Postgresql databases
https://github.com/mdcatapult/py-postgres
postgresql python
Last synced: 2 months ago
JSON representation
Methods to simplify configuring and connecting to Postgresql databases
- Host: GitHub
- URL: https://github.com/mdcatapult/py-postgres
- Owner: mdcatapult
- License: apache-2.0
- Created: 2022-06-21T14:36:47.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2022-10-27T13:31:23.000Z (over 2 years ago)
- Last Synced: 2025-03-08T03:16:33.005Z (3 months ago)
- Topics: postgresql, python
- Language: Python
- Homepage:
- Size: 16.7 MB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Klein Postgres
Simple module to enable postgres database connections with details specified in yaml based config file.
## Example
config.yaml
``` yaml
postgres:
username: postgres_username
password: postgres_password
database: database_name
host: 127.0.0.1
port: 5432
readonly: True # Default to True, set to False if write operation is required
autocommit: True # Default to be the same as readonly. If set to false, you are expected to commit after the queries manually.
```python
``` python
from klein_postgres.connect import connectconnection = connect() # or
connection = connect('postgres') # same as in the config. You may specify multiple postgres db in the config
```
In the above example the `postgres` parameter matches the key in the config that the database details should be read from.
If you wanted multiple db connections then you would specify multiple db connection sections in the config:**N.B. if you do not have working connection details under the `postgres` config key you will encounter a runtime failure.**
```yaml
firstdb:
username: firstdb_username
password: firstdb_password
database: firstdb_name
seconddb:
username: seconddb_username
password: seconddb_password
database: seconddb_name
```## Development
Utilises python 3.7
### Ubuntu
```
sudo apt install python3.7
```## Virtualenv
```
virtualenv -p python3.7 venv
source venv/bin/activate
echo -e "[global]\nindex = https://nexus.mdcatapult.io/repository/pypi-all/pypi\nindex-url = https://nexus.mdcatapult.io/repository/pypi-all/simple" > venv/pip.conf
pip install -r requirements.txt
```### Testing
```bash
docker-compose up
python -m pytest
```
For test coverage you can run:
```bash
docker-compose up
python -m pytest --cov-report term --cov src/ tests/
```### Anything else?
Why Klein? It's probably one of [these](https://en.wikipedia.org/wiki/Klein_bottle). Possibly a statement on the tangled web of support libraries.## License
This project is licensed under the terms of the Apache 2 license, which can be found in the repository as `LICENSE.txt`