Skip to main content

A python implementation of the mysql server protocol

Project description

MySQL-Mimic

Tests

Pure-python implementation of the MySQL server wire protocol.

This can be used to create applications that act as a MySQL server.

MySQL-Mimic doesn't parse SQL - it only handles the wire protocol. For parsing, check out sqlglot.

Installation

pip install mysql-mimic

Usage

A minimal use case might look like this:

import asyncio

from mysql_mimic import MysqlServer, Session


class MySession(Session):
    async def init(self, connection):
        print(f"new session: {connection}")

    async def query(self, sql, attrs):
        print(f"received query: {sql}")
        return [("a", 1), ("b", 2)], ["col1", "col2"]

    async def close(self):
        print("session closed")


if __name__ == "__main__":
    server = MysqlServer(session_factory=MySession)
    asyncio.run(server.serve_forever())

See examples for more examples.

Authentication

MySQL-mimic has built in support for several standard MySQL authentication plugins:

  • mysql_native_password
    • The client sends hashed passwords to the server, and the server stores hashed passwords. See the documentation for more details on how this works.
    • example
  • mysql_clear_password
    • The client sends passwords to the server as clear text, without hashing or encryption.
    • This is typically used as the client plugin for a custom server plugin. As such, MySQL-mimic provides an abstract class, mysql_mimic.auth.AbstractMysqlClearPasswordAuthPlugin, which can be extended.
    • example
  • mysql_no_login
    • The server prevents clients from directly authenticating as an account. See the documentation for relevant use cases.

By default, a session naively accepts whatever username the client provides.

Plugins are provided to the server by implementing mysql_mimic.IdentityProvider, which configures all available plugins and a callback for fetching users.

Custom plugins can be created by extending mysql_mimic.auth.AuthPlugin.

Development

You can install dependencies with make deps. You can format your code with make format. You can lint with make lint. You can check type annotations with make types. You can run tests with make test. This will build a coverage report in ./htmlcov/index.html. You can run all the checks with make check. You can build a pip package with make build.

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

mysql-mimic-1.1.2.tar.gz (40.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mysql_mimic-1.1.2-py3-none-any.whl (46.2 kB view details)

Uploaded Python 3

File details

Details for the file mysql-mimic-1.1.2.tar.gz.

File metadata

  • Download URL: mysql-mimic-1.1.2.tar.gz
  • Upload date:
  • Size: 40.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.14

File hashes

Hashes for mysql-mimic-1.1.2.tar.gz
Algorithm Hash digest
SHA256 2b7ace543b3b0140681b172ba4472a8fd06d7d5207790473a144948a921e88ea
MD5 20b40643e015639448e7eaf37b2b4275
BLAKE2b-256 721b292697bca80034c008bd3f7eda3eee3b9875cebb6ca82ff82b79161345a0

See more details on using hashes here.

File details

Details for the file mysql_mimic-1.1.2-py3-none-any.whl.

File metadata

  • Download URL: mysql_mimic-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 46.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.14

File hashes

Hashes for mysql_mimic-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e2923d46a58371fecd8b4911bcee5c17c28fb2d7302c94e9a8f942c23b75cef3
MD5 f4a7110e77fd9a76882d4fd0eb1b10aa
BLAKE2b-256 ca3d52aa83e1ca3fd0b0c5abd661af6a5fed1571da0fbd6007a27a61fbb9d5d3

See more details on using hashes here.

Supported by

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