An easy to use mariadb context manager
Project description
MariaDB Conext Manager
Installation
pip install mariadb-context-manager
Manual Installation
Setting Up
Once you have your enviornment is set up, run the following in your terminal or command line to get the latest version:
pip install --upgrade git+https://github.com/avgra3/MariaDB-Context-Manager.git
An alternative to this would be to do the following:
git clone https://github.com/avgra3/MariaDB-Context-Manager.git --depth 1
cd ./MariaDB-Context-Manager
python -m pip install --upgrade build
python -m build
python -m pip install install ./dist/MariaDB_Context_Manager-0.1.4-py3-none-any.whl
Note: For Linux or Mac systems, you may need to change "pip" to "pip3". Note: For Anaconda/Miniconda users, this module is not currently in any repositories, however, you can still use pip to install MariaDB package using the same command as above - but be aware that it may cause conflicts with packages you are using.
Implementing the Context Manager
Before you run your query, make sure that you have MariaDB installed locally or have a connection to a MariaDB database.
If you encounter an error/exception while trying to connect to the database, the connection will be closed and the exception will be printed to the console.
Example
from contextManager.contextManager import MariaDBCM
import pandas as pd
import polars as pl
# Our query we are using
query = """SELECT * FROM table;"""
# Database connection requirements
host = "HOST"
user = "USER"
password = "PASSWORD"
database = "DATABASE_NAME"
port = 3306 # The default MariaDB port
connection_params = {
"user": user,
"password": password,
"host": host,
"port": port,
"database": database,
}
# A dictionary containing results, column names and warnings
with MariaDBCM(**connection_params) as maria:
result_dictionary = maria.execute(query)
# Show data in a dataframe
# Pandas
df = pd.DataFrame(results["data"], columns=results["columns"])
# Maps the MariaDB data types to Python data types
df = df.astype(results["data_types"])
# Polars
prep = {}
column = 0
for field in result_dictionary["columns"]:
column_data = [x[column] for x in result_dictionary["data"]]
prep[field] = column_data
column+=1
df_pl = pl.DataFrame(prep)
Supported Data Types
Several standard python types are converted into SQL types and returned as Python objects when a statement is executed.
| Python Type | SQL Type |
|---|---|
| None | NULL |
| Bool | TINYINT |
| Float, Double | DOUBLE |
| Decimal | DECIMAL |
| Long | TINYINT, SMALLINT, INT, BIGINT |
| String | VARCHAR, VARSTRING, TEXT |
| ByteArray, Bytes | TINYBLOB, MEDIUMBLOB, BLOB, LONGBLOB |
| DateTime | DATETIME |
| Date | DATE |
| Time | TIME |
| Timestamp | TIMESTAMP |
For more information, see the documentation for more information.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mariadb_context_manager-1.0.0.tar.gz.
File metadata
- Download URL: mariadb_context_manager-1.0.0.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
291e923741268df1889b96207d2e532cf57a1ca35d465bd16318a3dd913feb65
|
|
| MD5 |
951db70a7c8032b9fdd340b433ecda19
|
|
| BLAKE2b-256 |
c65cc430f8248ab4eae5bf0ac6b4839451a56ebd5b6e6a1b586bf6bb339f0a6a
|
Provenance
The following attestation bundles were made for mariadb_context_manager-1.0.0.tar.gz:
Publisher:
build-for-release.yml on avgra3/MariaDB-Context-Manager
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mariadb_context_manager-1.0.0.tar.gz -
Subject digest:
291e923741268df1889b96207d2e532cf57a1ca35d465bd16318a3dd913feb65 - Sigstore transparency entry: 181229268
- Sigstore integration time:
-
Permalink:
avgra3/MariaDB-Context-Manager@1125b21d36ae4484ba901288cf3680188cab0f60 -
Branch / Tag:
refs/tags/v2.0.0 - Owner: https://github.com/avgra3
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-for-release.yml@1125b21d36ae4484ba901288cf3680188cab0f60 -
Trigger Event:
release
-
Statement type:
File details
Details for the file mariadb_context_manager-1.0.0-py3-none-any.whl.
File metadata
- Download URL: mariadb_context_manager-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1956f99a67dc8a8fe38b8c3cb220b5ad367ce9fbc8b4fbcab6cd3ccac0c9464e
|
|
| MD5 |
13a260230940abaf1f3c7313275d977f
|
|
| BLAKE2b-256 |
4fa5b46ad7536aaa667a38592e650c2a4743656e1ab62c549809fbb5f0a8bf39
|
Provenance
The following attestation bundles were made for mariadb_context_manager-1.0.0-py3-none-any.whl:
Publisher:
build-for-release.yml on avgra3/MariaDB-Context-Manager
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mariadb_context_manager-1.0.0-py3-none-any.whl -
Subject digest:
1956f99a67dc8a8fe38b8c3cb220b5ad367ce9fbc8b4fbcab6cd3ccac0c9464e - Sigstore transparency entry: 181229269
- Sigstore integration time:
-
Permalink:
avgra3/MariaDB-Context-Manager@1125b21d36ae4484ba901288cf3680188cab0f60 -
Branch / Tag:
refs/tags/v2.0.0 - Owner: https://github.com/avgra3
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
build-for-release.yml@1125b21d36ae4484ba901288cf3680188cab0f60 -
Trigger Event:
release
-
Statement type: