Skip to main content

Write classes with async def __ainit__

Project description

async-class

PyPI - License Wheel PyPI PyPI

Adding abillity to write classes with awaitable initialization function.

Example

import asyncio
from async_class import AsyncClass


class MyAsyncClass(AsyncClass):
    async def __ainit__(self):
        future = self.create_future()
        self.loop.call_soon(future.set_result)
        await future


async def main():
    instance = await MyAsyncClass()
    print(instance)


asyncio.run(main())

Documentation

Module provides metaclasses and some usefule abstractions for writing async code.

TaskStore

TBD

AsyncClass

Base class with task store instance and helpers for simple task management.

AsyncClassBase

Is a base wrapper with metaclass has no additional methods and properties like self.loop and TaskStore related helpers (self.create_task, self.create_future).

import asyncio
from async_class import AsyncClassBase


class MyAsyncClass(AsyncClassBase):
    async def __ainit__(self):
        loop = asyncio.get_event_loop()
        future = loop.create_future()
        loop.call_soon(future.set_result)
        await future


async def main():
    instance = await MyAsyncClass()
    print(instance)


asyncio.run(main())

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

async-class-0.0.3.tar.gz (3.2 kB view details)

Uploaded Source

Built Distribution

async_class-0.0.3-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file async-class-0.0.3.tar.gz.

File metadata

  • Download URL: async-class-0.0.3.tar.gz
  • Upload date:
  • Size: 3.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

File hashes

Hashes for async-class-0.0.3.tar.gz
Algorithm Hash digest
SHA256 91e1c679d18073c653567ade5e812d81a91b2213249b0f755bd4dce54eb7939a
MD5 78858862d2d289fd4e8ed456a16875b4
BLAKE2b-256 dadc8024b136fd7c2cf37853ab114348c1bb9c61f8abb830bbb96e1badd55285

See more details on using hashes here.

File details

Details for the file async_class-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: async_class-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6

File hashes

Hashes for async_class-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 16f6c01bbf82e6c97527f432c5591a5820ae1b48fd50e19a2eadf99752fa5747
MD5 275a699a7ccecc5632ea8f3c37021b4d
BLAKE2b-256 65555d26c3d498f1450c582bc5feee92f3c9a5004b5ac90f47057d764e0e4dbc

See more details on using hashes here.

Supported by

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