A python implementation of the mysql server protocol
Project description
MySQL-Mimic
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
This library is meant to be used as the basis for a proxy SQL service. 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.
Todo
- Add support for (at least) the
mysql_native_password
authentication method with another callback. - Eventually Compression support
- Eventually SSL support
Development
You can install dependencies with make deps
. You can format your code with
make format
. You can lint with make lint
. You can run tests with make test
. This will build a coverage report in ./htmlcov/index.html
. You can
build a pip package with make build
.
Project details
Release history Release notifications | RSS feed
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
Hashes for mysql_mimic-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 52e00187b5aed260f0b3fbacb628248fa653a8e0fbaa610527299e4abd096462 |
|
MD5 | 5d0e4740d6cf0a019a99a826e885d734 |
|
BLAKE2b-256 | d91bc8c6c0f3c565a5d6321722edcd0d3b22fd099ae90c9ac7e24137cb2e2f23 |