Package: aio-peewee
DeprecationWarningThe package is deprecated.Please usepeewee-aioinstead.—aio-peewee– Peewee support for async frameworks (Asyncio,Trio,Curio)The library doesn’t make peewee work async, but allows you to use Peewee with
your asyncio based libraries correctly.FeaturesTasks 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 PoolContentsDeprecationWarningFeaturesRequirementsInstallationQuickStartUsageInitializationAsync ConnectConnection PoolingDatabase URLASGI MiddlewareCurioBug trackerContributingLicenseRequirementspython >= 3.8Installationaio-peeweeshould be installed using pip:pip install aio-peeweeQuickStartfromaiopeeweeimportdb_urldb=db_url.connect('postgres+async://locahost:5432/database')asyncdefmain(id=1):asyncwithdb:item=Model.get(Model.id==1)returnitem.nameUsageInitializationfromaiopeeweeimportPostgresqlDatabaseAsync,SqliteDatabaseAsync,MySQLDatabaseAsync,CockroachDatabaseAsyncdb=PostgresqlDatabaseAsync('my_app',user='app',password='db_password',host='10.1.0.8',port=3306)Async Connect# Manualasyncdefmain():awaitdb.connect_async()# ...awaitdb.close_async()# Context managerasyncdefmain():asyncwithdb:# ...Connection PoolingfromaiopeeweeimportPooledPostgresqlDatabaseAsync,PooledSqliteDatabaseAsync,PooledMySQLDatabaseAsync,PooledCockroachDatabaseAsyncdb=PooledPostgresqlDatabaseAsync('my_database',max_connections=8,stale_timeout=300,user='postgres')Database URLfromaiopeeweeimportdb_urldb0=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 Middlewareimportdatetimeasdtfromasgi_toolsimportAppfromaiopeeweeimportPeeweeASGIPluginimportpeeweeaspwdb=PeeweeASGIPlugin(url='sqlite+async:///db.sqlite')@db.registerclassVisit(pw.Model):created=pw.DateTimeField(default=dt.datetime.utcnow())address=pw.CharField()db.create_tables()app=App()@app.route('/')asyncdefvisits_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()),}forvinVisit.select().order_by(Visit.id.desc()).limit(10)]app=db.middleware(app)Curioaio-peeweeusescontextvarsto store db connections. So you have to
enablecontextvarsfor Curio:https://curio.readthedocs.io/en/latest/howto.html#how-do-you-use-contextvarsBug trackerIf you have any suggestions, bug reports or
annoyances please report them to the issue tracker
athttps://github.com/klen/aio-peewee/issuesContributingDevelopment of the project happens at:https://github.com/klen/aio-peeweeLicenseLicensed under aMIT license.