MCPcopy
hub / github.com/PyMySQL/PyMySQL

github.com/PyMySQL/PyMySQL @v1.2.0 sqlite

repository ↗ · DeepWiki ↗ · release v1.2.0 ↗
517 symbols 2,322 edges 44 files 134 documented · 26%
README

Documentation Status codecov Ask DeepWiki

PyMySQL

This package contains a pure-Python MySQL and MariaDB client library, based on PEP 249.

Requirements

  • Python -- one of the following:
  • CPython : 3.9 and newer
  • PyPy : Latest 3.x version
  • MySQL Server -- one of the following:
  • MySQL LTS versions
  • MariaDB LTS versions

Installation

Package is uploaded on PyPI.

You can install it with pip:

$ python3 -m pip install PyMySQL

To use "sha256_password" or "caching_sha2_password" for authenticate, you need to install additional dependency:

$ python3 -m pip install PyMySQL[rsa]

To use MariaDB's "ed25519" authentication method, you need to install additional dependency:

$ python3 -m pip install PyMySQL[ed25519]

Documentation

Documentation is available online: https://pymysql.readthedocs.io/

For support, please refer to the StackOverflow.

Example

The following examples make use of a simple table

CREATE TABLE `users` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `email` varchar(255) COLLATE utf8_bin NOT NULL,
    `password` varchar(255) COLLATE utf8_bin NOT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin
AUTO_INCREMENT=1 ;
import pymysql.cursors

# Connect to the database
connection = pymysql.connect(host='localhost',
                             user='user',
                             password='passwd',
                             database='db',
                             cursorclass=pymysql.cursors.DictCursor)

with connection:
    with connection.cursor() as cursor:
        # Create a new record
        sql = "INSERT INTO `users` (`email`, `password`) VALUES (%s, %s)"
        cursor.execute(sql, ('webmaster@python.org', 'very-secret'))

    # connection is not autocommit by default. So you must commit to save
    # your changes.
    connection.commit()

    with connection.cursor() as cursor:
        # Read a single record
        sql = "SELECT `id`, `password` FROM `users` WHERE `email`=%s"
        cursor.execute(sql, ('webmaster@python.org',))
        result = cursor.fetchone()
        print(result)

This example will print:

{'password': 'very-secret', 'id': 1}

Resources

License

PyMySQL is released under the MIT License. See LICENSE for more information.

Core symbols most depended-on inside this repo

execute
called by 329
pymysql/cursors.py
add
called by 143
pymysql/charset.py
connect
called by 134
pymysql/tests/base.py
cursor
called by 125
pymysql/connections.py
fetchone
called by 84
pymysql/cursors.py
close
called by 62
pymysql/cursors.py
fetchall
called by 35
pymysql/cursors.py
get
called by 26
pymysql/optionfile.py

Shape

Method 390
Function 64
Class 61
Route 2

Languages

Python100%

Modules by API surface

pymysql/connections.py66 symbols
pymysql/tests/test_connection.py60 symbols
pymysql/tests/thirdparty/test_MySQLdb/dbapi20.py45 symbols
pymysql/protocol.py44 symbols
pymysql/cursors.py44 symbols
pymysql/tests/test_issues.py28 symbols
pymysql/converters.py24 symbols
pymysql/tests/thirdparty/test_MySQLdb/capabilities.py23 symbols
pymysql/tests/test_basic.py22 symbols
pymysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_nonstandard.py19 symbols
pymysql/err.py14 symbols
pymysql/tests/thirdparty/test_MySQLdb/test_MySQLdb_capabilities.py12 symbols

Dependencies from manifests, versioned

PyNaCl1.4.0 · 1×
sphinx8.0 · 1×
sphinx-rtd-theme3.0.0 · 1×

For agents

$ claude mcp add PyMySQL \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact