Py-OO-MySQL
Python Object-Orinted MySQL interface.
This allows to interact ith MySQL/MariaDB databases easily by constructing objects.
Table of Contents
- Requirements
- Classes / Objects
- Functions
- Samples
1. Requirements
The MySQLLib package is developed fully in Python3 and is not compatible with Python 2.X at all. Please use Python 3.6 or later to ensure the best compatibility. This package uses mysql-connector-python as backend. Make sure you have it installed by issuing the following command:
pip install mysql-connector-python
2. Classes
Database
The database class represents a simple pair hostname:port and holds connection status and other useful information about the Database itself and the connection, when the last is established.
Attributes
-
auth_pluginAuthentication plugin support.
-
connectionExisting connection object (from mysql.connector.connection) or None if there is no connection.
-
hostnameHostname/IP address used to connect to.
-
passwordPassword used for connecting to the database.
-
portPort used to connect to the database. Defaults to 3306
-
schemaAs in the default schema used for connecting to the database
-
usernameUsername set for the connection.
-
versionShort version number
-
full_versionFull version and revision
Methods
-
__init__(hostname, port=3306, schema, log_level)Constructor that will set hsotname, port and default schema along with the standard log_level INFO (as in the standard library logging.INFO)
-
connect(username: string, password: string, [schema]: string, [auth_plugin]: string)Connects to the host:port using the provided username and password. The schema defaults to "information_schema"
-
disconnectCloses the current connection if any
-
execute(command: string)Executes a command in the database provided that there's a connection established.
-
flush_privilegesFlushes privileges after granting/revoking
-
get_schemaReturns a dictionary with information about particular schema
-
get_schemasReturns a dictionary with information about all the schemas found in the database
-
get_user_by_nameReturns user/host information for a given username, it might be more than one
-
get_user_by_name_hostReturns exactly one user/host information for a given username
-
get_versionReturns the MySQL version
-
is_connectedReturns True if there's a connection established or False otherwise.
-
load_schemasLoads schemas to the databas
-
reconnectReconnects to the database in case of lost connection with same username and password
Schema
The schema class represents a schema within a database, thus it requires a database object to be passed to it at creation time.
Attributes
-
charsetReturns the character set for the schema
-
collationReturns collation for the schema
-
databaseReturns hostname:port information about the database where the schema resides
-
nameReturns the name of the schema
-
tablesReturns a list with the names of the tables in the schema
Methods
-
compareAllows the comparison of 2 schema objects
-
get_tableReturns information about a particular table
-
get_tablesReturns a list of the tables found in the schema
-
load_tablesLoads the tables to the schema attribute
Table
The Table class represents a particular table within a schema within a database.
Attributes
-
databaseDatabase whrre the table resides
-
fqnFully qualified name of the table in the form {schema_name}.{table_name}
-
nameName of the table
-
schemaSchema where the table resides
Methods
-
compare_dataAllows to compare row-per-row the contents of the table with another one
-
deleteDeletes rows from a table based on filters
-
get_columnsReturns a list with the names of the columns in the table
-
get_insert_statementReturns the normal SQL insert statement for the table
-
get_rowcountReturns the number of rows in the table
-
insertInserts data in the table
-
truncateTruncates the table, removing all data
-
updateUpdate rows in the Table based on some filters
User
The User class represents a User within the database
Attributes
-
existsBoolean showing if the user exists or not
-
grantsList of privileges that the user has
-
hostHost authorized to connect from
-
rolesList of roles granted to the user
-
usernameThis is self explanatory
Methods
-
createCreate the user if it doesn't exist in the database
-
dropDrops the user if it exists in the database
-
get_grantsUnder development
-
updateUpdates the user if it exists in the database
3. Functions
Util: SQL
4. Samples
# Import the package
import pyoomysql
# Create Database object
mydb = pyoomysql.Datbase(
hostname = "example.com",
port = 3306
)
# Connect
mydb.connect(
username="someuser",
password="super_secret_password"
)
# Create a schema object
myschema = pyoomysql.Schema(
database = mydb,
name = "some_schema"
)
# Create Table object
mytable = pyoomysql.Table(
schema = myschema,
name = "some_table"
)
# Create User object
myuser = pyoomysql.User(
name = "some_nice_username",
host = "% or host to connect from",
password = "very_long_and_strong_password"
)
# Create the user in the database
myuser.create()
Metadata
Release files for pyoomysql 0.3.3
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 |
|---|---|---|---|---|
| pyoomysql-0.3.3.tar.gz | 33.1 kB | Without provenance | Details for pyoomysql-0.3.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyoomysql-0.3.3-py3-none-any.whl | Python 3 | none | any | Details for pyoomysql-0.3.3-py3-none-any.whl |
Total release size: 67.7 kB
Release files / pyoomysql-0.3.3.tar.gz
| Download URL | pyoomysql-0.3.3.tar.gz |
|---|---|
| Size | 33.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f255195e30b22a31d557792d22b49ac3589d291a83d0e5d45ebc049de9ee8ff5
|
|
BLAKE2b-256 checksum How to use checksums |
ec971bd15aa072c70b19bda3a2971f06076d5033d92d168e56be70cab2fc0508
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.10
|
Release files / pyoomysql-0.3.3-py3-none-any.whl
| Download URL | pyoomysql-0.3.3-py3-none-any.whl |
|---|---|
| Size | 34.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
898b0948ce06c6ee8d5a11930580d6e75c4c88b9a11469e35a82f0bcb285dd74
|
|
BLAKE2b-256 checksum How to use checksums |
6afdeae77b24825a13915711c01b72921190fe4e27bc657f5d87b8473f23efbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.10
|
Security for pyoomysql 0.3.3
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.