cheesefactory-database
A wrapper for psycopg2.
Main Features
- Built on psycopg2.
- Pandas dataframe support.
- Test table existence.
- Test field existence.
Note: This package is still in beta status. As such, future versions may not be backwards compatible and features may change.
Installation
The source is hosted at https://bitbucket.org/hellsgrannies/cheesefactory-database
pip install cheesefactory-database
Dependencies
License
Examples
Connect to the remote PostgreSQL server and execute a query
from cheesefactory_database.postgresql import CfPostgresql
db = CfPostgresql(host='myhostname', user='myusername', password='mypassword', database='mydatabase')
Args:
- host (str): PostgreSQL server hostname/IP. Default: 127.0.0.1
- port (str): PostgreSQL server port. Default: 5432
- user (str): Username for authentication.
- password (str): Password for authentication.
- database (str): Database for connection
- autocommit (bool): Use autocommit on changes? Default: False
- dictionary_cursor (bool): Return the results as a dictionary? Default: False
- encoding (str): Database client encoding ("utf8", "latin1", "usascii"). Default: utf8
Returns:
- (CfPostgresql): An instance of the database connection.
Execute a query
results = db.execute("SELECT first_name, last_name FROM person WHERE last_name = 'Smith'")
Args:
- query (str): SQL query to execute.
- dataframe (bool): Output the results to a pandas.Dataframe?
- fetchall (bool): Perform a fetchall() and return the results?
Returns:
- If fetchall=False, None is returned.
- If dataframe=True, a pandas.Dataframe is returned.
Check connection status
status = db.connection_status()
Returns:
- (str): Connection status: "OK" or "Error"
Check database existence
status = db.database_exists(database_name='my_database')
Args:
- database_name (str): Name of the database to search for
Returns:
- (bool): True, if database exists. False, if not.
Check schema existence
status = db.schema_exists(schema_name='my_schema')
Args:
- schema_name (str): Name of the schema to search for.
Returns:
- (bool): True, if schema exists. False, if not.
Check table existence
status = db.table_exists(table_path='my_schema.my_table')
Args:
- table_path (str): Table name in the form <schema>.<table>
Returns:
- (bool): True, if table exists. False, if not.
Check field existence
status = db.fields_exist(table_path='my_schema.my_table', table_fields=['first_name', 'last_name'])
Args:
- table_path (str): Table name in the form <schema>.<table>
- table_fields (str): A list of fields to check.
Returns:
- (bool): True, if all fields are present in the table. False, if not.
Get a table's primary keys
primary_keys = db.get_primary_keys(table_path='my_schema.my_table')
Args:
- table_path (str): Table name in the form <schema>.<table>
Returns:
- (List): A list of primary keys.
Quote PostgreSQL reserved words in a list
quoted_word_list = CfPostgresql.quote_reserved_words(word_list)
Args:
- word_list (List): A list of words to check
Returnes:
- (List): word_list with all PostgreSQL reserved words surrounded in double-quotes.
Metadata
Release files for cheesefactory-database 0.9
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 |
|---|---|---|---|---|
| cheesefactory-database-0.9.tar.gz | 9.2 kB | Without provenance | Details for cheesefactory-database-0.9.tar.gz |
Release files / cheesefactory-database-0.9.tar.gz
| Download URL | cheesefactory-database-0.9.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
925d4d19ea8d33d4c53d988f81b9d928f8cc82c5744b82a826edb1088c52c11d
|
|
BLAKE2b-256 checksum How to use checksums |
71b65252918172efac97409af274d31dc034a92a28878caaac03ee4045491ee8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0.post20200309 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1
|
Security for cheesefactory-database 0.9
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.