Skip to main content

An easy to use mariadb context manager

Project description

MariaDB Conext Manager

Simpler setup

pip install mariadb-context-manager

Manual Setup

Setting Up

Once you have your enviornment 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

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

# 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": 3306, "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
df = pd.DataFrame(results["data"], columns=results["columns"])

# Maps the MariaDB data types to Python data types
df = df.astype(results["data_types"])

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

mariadb_context_manager-0.1.13.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

MariaDB_Context_Manager-0.1.13-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file mariadb_context_manager-0.1.13.tar.gz.

File metadata

File hashes

Hashes for mariadb_context_manager-0.1.13.tar.gz
Algorithm Hash digest
SHA256 47e60f3a35c54c213d14cd53526eb3b026b634b86876eb43b58325a9e6244682
MD5 97600e593f6e368fba3a02140e8164b3
BLAKE2b-256 704442cbc4c92a37c1caae4c48d43d341efc7f5f3ee9b81f63fc4fa6168987d4

See more details on using hashes here.

File details

Details for the file MariaDB_Context_Manager-0.1.13-py3-none-any.whl.

File metadata

File hashes

Hashes for MariaDB_Context_Manager-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 ed1104edec65282999546373320051104212753fe8c8561c66457bbe96e11a2f
MD5 c376418610c5eb6e090f013c6dca7044
BLAKE2b-256 39facf5c8a198cc3aeebfec1555ec4892b7fef8015fee42ba7ce2046b1ef2d05

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page