psycopg_dbconn_class
A simple class to handle database connections using psycopg2 (PostgreSQL).
Use
To properly use this class, just get it from PyPI.
pip install psycopg-dbconn-class
Alternatively, you can also clone it from the GitHub repository and install manually.
git clone https://github.com/kstenio/psycopg_dbconn_class.git
cd psycopg_dbconn_class
pip install -r requirements.txt
pip install .
Then, you can create an object, connect to a server and begin running queries. By default, parameters for connecting into the server are expected do be in environment variables ('DBN', 'DBU', 'DBK', 'DBH', 'DBP'), but you can also use a json file (conn.json). Finally, you may also enter parameters manually.
from psycopg_dbconn_class import DataBaseConnection
DB = DataBaseConnection(auto_config=False)
DB.update_config_values(name='db', host='127.0.0.0', port="15432", user="postgres", password="PostgresPass")
DB.connect()
if DB.connected:
# For queries without need of return
DB.run_query('INSERT INTO colum VALUES (NULL)')
DB.run_query('INSERT INTO colum VALUES (%s)', [1])
# For queries that need the return
result = DB.run_read_query('SELECT * FROM table WHERE val = %s', [2], fetch_all=True)
print(result)
DB.close()
Development background
When I've started to work with Python + PostgreSQL, I have begun using the pysycopg2 library. However, I do prefer working with classes, and the usual connection/cursor methods were not very functional for my applications.
Eventually, I decided to structure the objects I needed inside a DataBaseConnection class, and created this repository for further improvements.
Warranty
psycopg_dbconn_class is an open-source project. It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License version 3 attached for more details.
Developed by: Kleydson Stenio @ 2023
Metadata
Release files for psycopg-dbconn-class 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| psycopg_dbconn_class-0.0.2.tar.gz | 20.1 kB | Without provenance | Details for psycopg_dbconn_class-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| psycopg_dbconn_class-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for psycopg_dbconn_class-0.0.2-py3-none-any.whl |
Total release size: 40.9 kB
Release files / psycopg_dbconn_class-0.0.2.tar.gz
| Download URL | psycopg_dbconn_class-0.0.2.tar.gz |
|---|---|
| Size | 20.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7959deefcd03631c7db6bbfe635957d0ddb51a062b1bcc3f881951d22e7889e6
|
|
BLAKE2b-256 checksum How to use checksums |
4c660a41d26108a8e808c2d29616878da7aba5b4a979f7a1c8d12867f327a67c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Release files / psycopg_dbconn_class-0.0.2-py3-none-any.whl
| Download URL | psycopg_dbconn_class-0.0.2-py3-none-any.whl |
|---|---|
| Size | 20.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8db37f886d21d44e9f71d3561a7cf95af00e0a8e1fc4a4114625560d108106b9
|
|
BLAKE2b-256 checksum How to use checksums |
c09a9f1362fecebcf3d9eeac6fd00ff4af1b65afc6a818d4ccbd77a9299cca39
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.2
|
Security for psycopg-dbconn-class 0.0.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.