aio-peewee
##########
DeprecationWarning
-------------------
**The package is deprecated.** Please use `peewee-aio <https://github.com/klen/peewee-aio>`_ instead.
---
.. _description:
**aio-peewee** -- Peewee support for async frameworks (Asyncio_, Trio_, Curio_)
.. _badges:
.. image:: https://github.com/klen/aio-peewee/workflows/tests/badge.svg
:target: https://github.com/klen/aio-peewee/actions
:alt: Tests Status
.. image:: https://img.shields.io/pypi/v/aio-peewee
:target: https://pypi.org/project/aio-peewee/
:alt: PYPI Version
.. image:: https://img.shields.io/pypi/pyversions/aio-peewee
:target: https://pypi.org/project/aio-peewee/
:alt: Python Versions
.. _important:
The library doesn't make peewee work async, but allows you to use Peewee with
your asyncio based libraries correctly.
.. _features:
Features
========
- Tasks Safety. The library tracks of the connection state using Task-local
storage, making the Peewee Database object safe to use with multiple tasks
inside a loop.
- Async management of connections for Peewee Connections Pool
.. _contents:
.. contents::
.. _requirements:
Requirements
=============
- python >= 3.8
.. _installation:
Installation
=============
**aio-peewee** should be installed using pip: ::
pip install aio-peewee
.. _usage:
QuickStart
==========
.. code:: python
from aiopeewee import db_url
db = db_url.connect('postgres+async://locahost:5432/database')
async def main(id=1):
async with db:
item = Model.get(Model.id == 1)
return item.name
Usage
=====
Initialization
--------------
.. code:: python
from aiopeewee import PostgresqlDatabaseAsync, SqliteDatabaseAsync, MySQLDatabaseAsync, CockroachDatabaseAsync
db = PostgresqlDatabaseAsync('my_app', user='app', password='db_password', host='10.1.0.8', port=3306)
Async Connect
-------------
.. code:: python
# Manual
async def main():
await db.connect_async()
# ...
await db.close_async()
# Context manager
async def main():
async with db:
# ...
Connection Pooling
------------------
.. code:: python
from aiopeewee import PooledPostgresqlDatabaseAsync, PooledSqliteDatabaseAsync, PooledMySQLDatabaseAsync, PooledCockroachDatabaseAsync
db = PooledPostgresqlDatabaseAsync('my_database', max_connections=8, stale_timeout=300, user='postgres')
Database URL
------------
.. code:: python
from aiopeewee import db_url
db0 = db_url.connect('cockroachdb+async://localhost/db', **db_params)
db1 = db_url.connect('cockroachdb+pool+async://localhost/db', **db_params)
db2 = db_url.connect('mysql+async://localhost/db', **db_params)
db3 = db_url.connect('mysql+pool+async://localhost/db', **db_params)
db4 = db_url.connect('postgres+async://localhost/db', **db_params)
db5 = db_url.connect('postgres+pool+async://localhost/db', **db_params)
db6 = db_url.connect('sqlite+async://localhost/db', **db_params)
db7 = db_url.connect('sqlite+pool+async://localhost/db', **db_params)
db8 = db_url.connect('sqliteexc+async://localhost/db', **db_params)
db9 = db_url.connect('sqliteexc+pool+async://localhost/db', **db_params)
ASGI Middleware
---------------
.. code:: python
import datetime as dt
from asgi_tools import App
from aiopeewee import PeeweeASGIPlugin
import peewee as pw
db = PeeweeASGIPlugin(url='sqlite+async:///db.sqlite')
@db.register
class Visit(pw.Model):
created = pw.DateTimeField(default=dt.datetime.utcnow())
address = pw.CharField()
db.create_tables()
app = App()
@app.route('/')
async def visits_json(request):
"""Store the visit and load latest 10 visits."""
Visit.create(address=request.client[0])
return [{
'id': v.id, 'address': v.address, 'timestamp': round(v.created.timestamp()),
} for v in Visit.select().order_by(Visit.id.desc()).limit(10)]
app = db.middleware(app)
Curio
-----
``aio-peewee`` uses ``contextvars`` to store db connections. So you have to
enable ``contextvars`` for Curio:
https://curio.readthedocs.io/en/latest/howto.html#how-do-you-use-contextvars
.. _bugtracker:
Bug tracker
===========
If you have any suggestions, bug reports or
annoyances please report them to the issue tracker
at https://github.com/klen/aio-peewee/issues
.. _contributing:
Contributing
============
Development of the project happens at: https://github.com/klen/aio-peewee
.. _license:
License
========
Licensed under a `MIT license`_.
.. _links:
.. _klen: https://github.com/klen
.. _Asyncio: https://docs.python.org/3/library/asyncio.html
.. _Trio: https://trio.readthedocs.io/en/stable/index.html
.. _Curio: https://github.com/dabeaz/curio
.. _MIT license: http://opensource.org/licenses/MIT
Raw data
{
"_id": null,
"home_page": "https://github.com/klen/aio-peewee",
"name": "aio-peewee",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "peewee,asyncio,trio,asgi",
"author": "Kirill Klenov",
"author_email": "horneds@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/3b/fb/44331a60813a1a4934d845fea327b89115c7632749d2d597ba9a52d84e4e/aio-peewee-0.4.1.tar.gz",
"platform": null,
"description": "aio-peewee\n##########\n\nDeprecationWarning\n-------------------\n\n**The package is deprecated.** Please use `peewee-aio <https://github.com/klen/peewee-aio>`_ instead.\n\n---\n\n.. _description:\n\n**aio-peewee** -- Peewee support for async frameworks (Asyncio_, Trio_, Curio_)\n\n.. _badges:\n\n.. image:: https://github.com/klen/aio-peewee/workflows/tests/badge.svg\n :target: https://github.com/klen/aio-peewee/actions\n :alt: Tests Status\n\n.. image:: https://img.shields.io/pypi/v/aio-peewee\n :target: https://pypi.org/project/aio-peewee/\n :alt: PYPI Version\n\n.. image:: https://img.shields.io/pypi/pyversions/aio-peewee\n :target: https://pypi.org/project/aio-peewee/\n :alt: Python Versions\n\n.. _important:\n\n The library doesn't make peewee work async, but allows you to use Peewee with\n your asyncio based libraries correctly.\n\n.. _features:\n\nFeatures\n========\n\n- Tasks Safety. The library tracks of the connection state using Task-local\n storage, making the Peewee Database object safe to use with multiple tasks\n inside a loop.\n- Async management of connections for Peewee Connections Pool\n\n.. _contents:\n\n.. contents::\n\n.. _requirements:\n\nRequirements\n=============\n\n- python >= 3.8\n\n.. _installation:\n\nInstallation\n=============\n\n**aio-peewee** should be installed using pip: ::\n\n pip install aio-peewee\n\n.. _usage:\n\nQuickStart\n==========\n\n.. code:: python\n\n from aiopeewee import db_url\n\n db = db_url.connect('postgres+async://locahost:5432/database')\n\n async def main(id=1):\n async with db:\n item = Model.get(Model.id == 1)\n\n return item.name\n\n\nUsage\n=====\n\n\nInitialization\n--------------\n\n.. code:: python\n\n from aiopeewee import PostgresqlDatabaseAsync, SqliteDatabaseAsync, MySQLDatabaseAsync, CockroachDatabaseAsync\n\n db = PostgresqlDatabaseAsync('my_app', user='app', password='db_password', host='10.1.0.8', port=3306)\n\n\nAsync Connect\n-------------\n\n.. code:: python\n\n # Manual\n async def main():\n await db.connect_async()\n # ...\n await db.close_async()\n\n # Context manager\n async def main():\n async with db:\n # ...\n\n\nConnection Pooling\n------------------\n\n.. code:: python\n\n from aiopeewee import PooledPostgresqlDatabaseAsync, PooledSqliteDatabaseAsync, PooledMySQLDatabaseAsync, PooledCockroachDatabaseAsync\n\n db = PooledPostgresqlDatabaseAsync('my_database', max_connections=8, stale_timeout=300, user='postgres')\n\n\nDatabase URL\n------------\n\n.. code:: python\n\n from aiopeewee import db_url\n\n db0 = db_url.connect('cockroachdb+async://localhost/db', **db_params)\n db1 = db_url.connect('cockroachdb+pool+async://localhost/db', **db_params)\n db2 = db_url.connect('mysql+async://localhost/db', **db_params)\n db3 = db_url.connect('mysql+pool+async://localhost/db', **db_params)\n db4 = db_url.connect('postgres+async://localhost/db', **db_params)\n db5 = db_url.connect('postgres+pool+async://localhost/db', **db_params)\n db6 = db_url.connect('sqlite+async://localhost/db', **db_params)\n db7 = db_url.connect('sqlite+pool+async://localhost/db', **db_params)\n db8 = db_url.connect('sqliteexc+async://localhost/db', **db_params)\n db9 = db_url.connect('sqliteexc+pool+async://localhost/db', **db_params)\n\n\nASGI Middleware\n---------------\n\n.. code:: python\n\n import datetime as dt\n\n from asgi_tools import App\n from aiopeewee import PeeweeASGIPlugin\n import peewee as pw\n\n\n db = PeeweeASGIPlugin(url='sqlite+async:///db.sqlite')\n\n\n @db.register\n class Visit(pw.Model):\n created = pw.DateTimeField(default=dt.datetime.utcnow())\n address = pw.CharField()\n\n\n db.create_tables()\n\n\n app = App()\n\n\n @app.route('/')\n async def visits_json(request):\n \"\"\"Store the visit and load latest 10 visits.\"\"\"\n Visit.create(address=request.client[0])\n return [{\n 'id': v.id, 'address': v.address, 'timestamp': round(v.created.timestamp()),\n } for v in Visit.select().order_by(Visit.id.desc()).limit(10)]\n\n\n app = db.middleware(app)\n\n\nCurio\n-----\n\n``aio-peewee`` uses ``contextvars`` to store db connections. So you have to\nenable ``contextvars`` for Curio:\nhttps://curio.readthedocs.io/en/latest/howto.html#how-do-you-use-contextvars\n\n\n.. _bugtracker:\n\nBug tracker\n===========\n\nIf you have any suggestions, bug reports or\nannoyances please report them to the issue tracker\nat https://github.com/klen/aio-peewee/issues\n\n.. _contributing:\n\nContributing\n============\n\nDevelopment of the project happens at: https://github.com/klen/aio-peewee\n\n.. _license:\n\nLicense\n========\n\nLicensed under a `MIT license`_.\n\n\n.. _links:\n\n\n.. _klen: https://github.com/klen\n.. _Asyncio: https://docs.python.org/3/library/asyncio.html\n.. _Trio: https://trio.readthedocs.io/en/stable/index.html\n.. _Curio: https://github.com/dabeaz/curio\n\n.. _MIT license: http://opensource.org/licenses/MIT\n\n\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Peewee support for async frameworks (Asyncio, Trio)",
"version": "0.4.1",
"split_keywords": [
"peewee",
"asyncio",
"trio",
"asgi"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "e5a5da2b48bff9d873cf3e62ee94434efb88b5554b566f9fe907eead3670ce6c",
"md5": "83f508a2fed5648a9058790a1dab2f21",
"sha256": "843141c40d0d440efef9c2eb12f956c6f8beead8cc6e8b454bf8be438d7d1ff3"
},
"downloads": -1,
"filename": "aio_peewee-0.4.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "83f508a2fed5648a9058790a1dab2f21",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 7886,
"upload_time": "2022-11-14T05:54:10",
"upload_time_iso_8601": "2022-11-14T05:54:10.472798Z",
"url": "https://files.pythonhosted.org/packages/e5/a5/da2b48bff9d873cf3e62ee94434efb88b5554b566f9fe907eead3670ce6c/aio_peewee-0.4.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "3bfb44331a60813a1a4934d845fea327b89115c7632749d2d597ba9a52d84e4e",
"md5": "1a4496023b3a2cf881e1dec9063720af",
"sha256": "8f043d8475da0e26090ee65f051e5a2d81f107d8695275905afe6d4d391dff8e"
},
"downloads": -1,
"filename": "aio-peewee-0.4.1.tar.gz",
"has_sig": false,
"md5_digest": "1a4496023b3a2cf881e1dec9063720af",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 7380,
"upload_time": "2022-11-14T05:54:11",
"upload_time_iso_8601": "2022-11-14T05:54:11.999056Z",
"url": "https://files.pythonhosted.org/packages/3b/fb/44331a60813a1a4934d845fea327b89115c7632749d2d597ba9a52d84e4e/aio-peewee-0.4.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2022-11-14 05:54:11",
"github": true,
"gitlab": false,
"bitbucket": false,
"github_user": "klen",
"github_project": "aio-peewee",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "aio-peewee"
}