A set of functions that interacts with a database. It contains some basic functionalities along with some other Dairy-Brain-specific functionalities.
Project description
AgDH_DairyBrainUtils
About
DairyBrainUtils is a PyPI package with some basic functionalities for interacting with a PostgreSQL database.
For now, it is hosted on TestPyPI. If the TestPyPI distribution got cleaned up, please contact the author to re-upload it.
Installation
To install the latest version of the package, use the command in PyPI.
If the above link is broken, try:
pip install DairyBrainUtils
Once installed, we recommend you to import the package with import DairyBrainUtils as dbu
.
(Update: This was resolved as we uploaded to the official PyPI) If you see an error message like this:
ERROR: Could not find a version that satisfies the requirement DairyBrainUtils-ruipeterpan==0.3.0 (from versions: 0.0.3, 0.0.4, 0.1.0, 0.1.1, 0.1.2, 0.1.3, 0.2.0, 0.2.1)
ERROR: No matching distribution found for DairyBrainUtils-ruipeterpan==0.3.0
try installing it one more time. TestPyPI is weird.
Documentation
A list of functions that are available for use are:
get_engine(credentials)
check_if_database_exists(db_engine)
create_table_if_doesnt_exist(db_engine, table_name, sql_statement)
create_table(db_engine, table_name, sql_statement)
create_schema(db_engine, schema_name)
create_sequence(db_engine, sequence_name)
get_next_from_sequence(db_engine, sequence_name)
populate_table_from_csv(table_name, csv_location, db_engine)
execute_statement(statement, db_engine)
drop_table(table_name, db_engine)
has_table(table_name, db_engine)
get_engine(credentials)
Takes in a dictionary credentials
with the keys: [dialect, user, password, host, port, db_name, log]
, and passes these
credentials into sqlalchemy.create_engine() to create a new engine instance.
dialect
: String. A database dialect. Right now this package only supportspostgresql
.user
: String. The username of a user in the database.password
: String. The password that is associated with the user.host
: String. Host name.port
: Integer. Port number.db_name
: String. A database name.log
: Boolean. If True, the engine will log all statements as well as a repr() of their parameter lists to the engines logger, which defaults to sys.stdout.
check_if_database_exists(db_engine)
Use existing sqlalchemy functionality to check if the database exists. Returns 'True' if database exists, 'False' otherwise
create_table_if_doesnt_exist(db_engine, table_name, sql_statement)
Creates a table with table_name
in the database if a table with the given name doesn't exist.
sql_statement
is a CREATE TABLE
statement that specifies the headers of the table to be created.
create_table(db_engine, table_name, sql_statement)
Creates a table with table_name in the database.
sql_statement
is a CREATE TABLE
statement that specifies the headers of the table to be created.
create_schema(db_engine, schema_name)
Creates a schema with the given schema_name
in the specified database.
create_sequence(db_engine, sequence_name)
Creates a sequence in the database.
get_next_from_sequence(db_engine, sequence_name)
Returns the next integer id in the given sequence (assuming one exists)
populate_table_from_csv(table_name, csv_location, db_engine)
Takes in a csv_location
, the file path of a csv file, and populates the table with the given table_name
(assuming one exists) in the specified database.
execute_statement(statement, db_engine)
Executes a SQL statement in the specified database.
drop_table(table_name, db_engine)
Drops a table with table_name
in the specified database.
has_table(table_name, db_engine)
Returns True
if there exists a table with the given table_name
in the specified database, returns False
otherwise
Development
See this tutorial for guidance on packaging a Python project and uploading it to the PyPI (Python Package Index). This is a sample project with the best format.
To publish a new version of the package, edit ./DairyBrainUtils/__init__.py
, change the version number in setup.py
, and publish the distribution archives following the tutorial.
More specifically, do:
python3 -m pip install --upgrade setuptools wheel
python3 setup.py sdist bdist_wheel
Now, a dist
directory should be created with two files. If the package is to be hosted on a local server, just take the .whl
file and use pip
to install the package.
For uploading the distribution packages to TestPyPI, do:
python3 -m pip install --upgrade twine
python3 -m twine upload --repository testpypi dist/*
Use __token__
when prompted to enter the username. For the password, use the token value, including the pypi-
prefix.
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
Built Distribution
File details
Details for the file DairyBrainUtils-0.3.3.tar.gz
.
File metadata
- Download URL: DairyBrainUtils-0.3.3.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9ed6c0c5b500e9cb0537dc9aad490d9b8e55cd6373dd742542bc1a1eff2a9ff6 |
|
MD5 | e57838e3c5d0348077ceb5a00ac0cf4e |
|
BLAKE2b-256 | 4735eba8b120a667e3d8a797ea0bb9b532d472d453a7ecbb49d2f95c8efed078 |
File details
Details for the file DairyBrainUtils-0.3.3-py3-none-any.whl
.
File metadata
- Download URL: DairyBrainUtils-0.3.3-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | faf2e952210b29ccd882bb5bc3eadf99290035edac1b49600508596938571595 |
|
MD5 | 494d1025ab5bebc05a89e4908699d1f2 |
|
BLAKE2b-256 | 25db4ae1be4a750f5c2a48f99bcbb05a22d2284083a69dd2a7d16209c44b44ee |