asmysql


Nameasmysql JSON
Version 1.0.0 PyPI version JSON
download
home_pagehttps://pypi.org/project/asmysql/
SummaryAn Asynchronous MySQL Client Engine Using Aiomysql.
upload_time2024-10-19 01:23:49
maintainerNone
docs_urlNone
authorvastxiao
requires_python<4.0,>=3.9
licenseMIT
keywords async asyncio mysql aiomysql
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # asmysql

[![PyPI](https://img.shields.io/pypi/v/asmysql.svg?logo=pypi&logoColor=FFE873)](https://pypi.org/project/asmysql/)
[![Python](https://img.shields.io/pypi/pyversions/asmysql.svg?logo=python&logoColor=FFE873)](https://pypi.org/project/asmysql/)
[![Licence](https://img.shields.io/github/license/Vastxiao/asmysql.svg)](https://github.com/Vastxiao/asmysql/blob/main/LICENSE)
[![Downloads](https://static.pepy.tech/badge/asmysql)](https://pepy.tech/project/asmysql)
[![Downloads](https://static.pepy.tech/badge/asmysql/month)](https://pepy.tech/project/asmysql)
[![Downloads](https://static.pepy.tech/badge/asmysql/week)](https://pepy.tech/project/asmysql)

* PyPI: https://pypi.org/project/asmysql/
* GitHub: https://github.com/vastxiao/asmysql
* Gitee: https://gitee.com/vastxiao/asmysql

## Introduction

asmysql is a library for using the MySQL asynchronous client, which is a wrapper for aiomysql.

## Features

* Code supports type annotations.
* Very easy to use, simply inherit the AsMysql class for logical development.
* Supports automatic management of the MySQL connection pool and reconnection mechanism.
* Automatically captures and handles MysqlError errors globally.
* Separates statement execution from data retrieval.

## Install

```sh
# Install from PyPI
pip install asmysql
```

## Documentation

### Quick Start

```python
import asyncio
from asmysql import AsMysql


# Directly inherit the AsMysql class for development:
class TestAsMysql(AsMysql):
    # You can define some default parameters for the Mysql instance initialization here
    # The attributes are consistent with the __init__ parameters
    host = '127.0.0.1'
    port = 3306
    user = 'root'
    password = 'pass'

    async def get_users(self):
        # The self.client attribute is specifically used to execute SQL statements, providing aiomysql's execute and execute_many methods.
        result = await self.client.execute('select user,authentication_string,host from mysql.user')
        # result is specifically used to obtain execution results, providing fetch_one, fetch_many, fetch_all, and iterate methods.
        # result.err is the exception object (Exception) for all MySQL execution errors.
        if result.err:
            print(result.err_msg)
        else:
            # result.iterate() is an asynchronous iterator that can fetch each row of the execution result.
            async for item in result.iterate():
                print(item)

                
async def main():
    # This will create an instance and connect to MySQL:
    mysql = await TestAsMysql()

    await mysql.get_users()

    # Remember to disconnect the MySQL connection before exiting the program:
    await mysql.disconnect()


asyncio.run(main())
```

### Support for asynchronous context managers.

```python
import asyncio
from asmysql import AsMysql

class TestAsMysql(AsMysql):
    async def get_users(self):
        result = await self.client.execute('select user,authentication_string,host from mysql.user')
        if result.err:
            print(result.err)
        else:
            async for item in result.iterate():
                print(item)

async def main():
    # Using async with will automatically close the MySQL connection when the code exits.
    async with TestAsMysql() as mysql:
        await mysql.get_users()

if __name__ == '__main__':
    asyncio.run(main())
```

### More Usage

```python
import asyncio
from asmysql import AsMysql

class TestAsMysql(AsMysql):
    async def get_users(self):
        result = await self.client.execute('select user,authentication_string,host from mysql.user')
        if result.err:
            print(result.err)
        else:
            return await result.fetch_all()

# When creating a MySQL instance, parameters such as MySQL address and user password can be passed in.
mysql = TestAsMysql(host='192.168.1.192', port=3306)

async def main():
    # This will connect to MySQL:
    await mysql.connect()  # or: await mysql

    print(await mysql.get_users())

    # Disconnect MySQL connection:
    await mysql.disconnect()

asyncio.run(main())
```


            

Raw data

            {
    "_id": null,
    "home_page": "https://pypi.org/project/asmysql/",
    "name": "asmysql",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": "async, asyncio, mysql, aiomysql",
    "author": "vastxiao",
    "author_email": "vastxiao@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/ee/ea/48fb63744513e39b213d0304a0dd21e39b49eab0c202c5c94e7528d735f4/asmysql-1.0.0.tar.gz",
    "platform": null,
    "description": "# asmysql\n\n[![PyPI](https://img.shields.io/pypi/v/asmysql.svg?logo=pypi&logoColor=FFE873)](https://pypi.org/project/asmysql/)\n[![Python](https://img.shields.io/pypi/pyversions/asmysql.svg?logo=python&logoColor=FFE873)](https://pypi.org/project/asmysql/)\n[![Licence](https://img.shields.io/github/license/Vastxiao/asmysql.svg)](https://github.com/Vastxiao/asmysql/blob/main/LICENSE)\n[![Downloads](https://static.pepy.tech/badge/asmysql)](https://pepy.tech/project/asmysql)\n[![Downloads](https://static.pepy.tech/badge/asmysql/month)](https://pepy.tech/project/asmysql)\n[![Downloads](https://static.pepy.tech/badge/asmysql/week)](https://pepy.tech/project/asmysql)\n\n* PyPI: https://pypi.org/project/asmysql/\n* GitHub: https://github.com/vastxiao/asmysql\n* Gitee: https://gitee.com/vastxiao/asmysql\n\n## Introduction\n\nasmysql is a library for using the MySQL asynchronous client, which is a wrapper for aiomysql.\n\n## Features\n\n* Code supports type annotations.\n* Very easy to use, simply inherit the AsMysql class for logical development.\n* Supports automatic management of the MySQL connection pool and reconnection mechanism.\n* Automatically captures and handles MysqlError errors globally.\n* Separates statement execution from data retrieval.\n\n## Install\n\n```sh\n# Install from PyPI\npip install asmysql\n```\n\n## Documentation\n\n### Quick Start\n\n```python\nimport asyncio\nfrom asmysql import AsMysql\n\n\n# Directly inherit the AsMysql class for development:\nclass TestAsMysql(AsMysql):\n    # You can define some default parameters for the Mysql instance initialization here\n    # The attributes are consistent with the __init__ parameters\n    host = '127.0.0.1'\n    port = 3306\n    user = 'root'\n    password = 'pass'\n\n    async def get_users(self):\n        # The self.client attribute is specifically used to execute SQL statements, providing aiomysql's execute and execute_many methods.\n        result = await self.client.execute('select user,authentication_string,host from mysql.user')\n        # result is specifically used to obtain execution results, providing fetch_one, fetch_many, fetch_all, and iterate methods.\n        # result.err is the exception object (Exception) for all MySQL execution errors.\n        if result.err:\n            print(result.err_msg)\n        else:\n            # result.iterate() is an asynchronous iterator that can fetch each row of the execution result.\n            async for item in result.iterate():\n                print(item)\n\n                \nasync def main():\n    # This will create an instance and connect to MySQL:\n    mysql = await TestAsMysql()\n\n    await mysql.get_users()\n\n    # Remember to disconnect the MySQL connection before exiting the program:\n    await mysql.disconnect()\n\n\nasyncio.run(main())\n```\n\n### Support for asynchronous context managers.\n\n```python\nimport asyncio\nfrom asmysql import AsMysql\n\nclass TestAsMysql(AsMysql):\n    async def get_users(self):\n        result = await self.client.execute('select user,authentication_string,host from mysql.user')\n        if result.err:\n            print(result.err)\n        else:\n            async for item in result.iterate():\n                print(item)\n\nasync def main():\n    # Using async with will automatically close the MySQL connection when the code exits.\n    async with TestAsMysql() as mysql:\n        await mysql.get_users()\n\nif __name__ == '__main__':\n    asyncio.run(main())\n```\n\n### More Usage\n\n```python\nimport asyncio\nfrom asmysql import AsMysql\n\nclass TestAsMysql(AsMysql):\n    async def get_users(self):\n        result = await self.client.execute('select user,authentication_string,host from mysql.user')\n        if result.err:\n            print(result.err)\n        else:\n            return await result.fetch_all()\n\n# When creating a MySQL instance, parameters such as MySQL address and user password can be passed in.\nmysql = TestAsMysql(host='192.168.1.192', port=3306)\n\nasync def main():\n    # This will connect to MySQL:\n    await mysql.connect()  # or: await mysql\n\n    print(await mysql.get_users())\n\n    # Disconnect MySQL connection:\n    await mysql.disconnect()\n\nasyncio.run(main())\n```\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "An Asynchronous MySQL Client Engine Using Aiomysql.",
    "version": "1.0.0",
    "project_urls": {
        "Changelog": "https://github.com/Vastxiao/asmysql/blob/main/CHANGELOG.md",
        "Changelog-zh": "https://github.com/Vastxiao/asmysql/blob/main/CHANGELOG_zh.md",
        "Documentation": "https://github.com/Vastxiao/asmysql/blob/main/README.md",
        "Gitee Repo": "https://gitee.com/vastxiao/asmysql",
        "Homepage": "https://pypi.org/project/asmysql/",
        "Readme-zh": "https://github.com/Vastxiao/asmysql/blob/main/README_zh.md",
        "Repository": "https://github.com/Vastxiao/asmysql",
        "Vastxiao Blog": "https://vastxiao.github.io/"
    },
    "split_keywords": [
        "async",
        " asyncio",
        " mysql",
        " aiomysql"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6b6c678325f2a76cf2a71f7b71ff34840373ceb8698147ff826cd782b2e5e565",
                "md5": "269e6fb2879596074761511060a7194b",
                "sha256": "cb93ef207def99b82593cfde51ea004150ec742cbe91152e7c3caf5bd25251e3"
            },
            "downloads": -1,
            "filename": "asmysql-1.0.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "269e6fb2879596074761511060a7194b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 10629,
            "upload_time": "2024-10-19T01:23:47",
            "upload_time_iso_8601": "2024-10-19T01:23:47.994363Z",
            "url": "https://files.pythonhosted.org/packages/6b/6c/678325f2a76cf2a71f7b71ff34840373ceb8698147ff826cd782b2e5e565/asmysql-1.0.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "eeea48fb63744513e39b213d0304a0dd21e39b49eab0c202c5c94e7528d735f4",
                "md5": "531b103e6bbd39ecf57b5ae08aced1e7",
                "sha256": "f7f71aa483c0a0520409872a170b5721b21acf7b2bb36b78f5b4d064ce05ba92"
            },
            "downloads": -1,
            "filename": "asmysql-1.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "531b103e6bbd39ecf57b5ae08aced1e7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 7318,
            "upload_time": "2024-10-19T01:23:49",
            "upload_time_iso_8601": "2024-10-19T01:23:49.506865Z",
            "url": "https://files.pythonhosted.org/packages/ee/ea/48fb63744513e39b213d0304a0dd21e39b49eab0c202c5c94e7528d735f4/asmysql-1.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-19 01:23:49",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "Vastxiao",
    "github_project": "asmysql",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "asmysql"
}
        
Elapsed time: 2.52645s