Skip to main content

asyncio Context Manager with Explicit Interface

Project description

PyPi Package Version Supported Python versions Documentation Status MIT License Github Actions workflow https://codecov.io/gh/Bibo-Joshi/aiorem/graph/badge.svg?token=H1HUA2FDR3 pre-commit.ci status Code Style: Black

A simple asyncio context manager with explicit interface.

Introduction

This library provides a simple context manager for managing resources in an asyncio environment. It’s designed to have an explicit interface, which makes it easy to use both as context manager and as a regular object for custom use cases.

Installing

You can install or upgrade aiorem via

$ pip install aiorem --upgrade

Quick Start

Here is a simple example of how to use aiorem:

import asyncio
from aiorem import AbstractResourceManager


class ResourceManager(AbstractResourceManager):
    async def acquire_resources(self):
        print("Resource acquired")

    async def release_resources(self):
        print("Resource released")


async def context_manager():
    async with ResourceManager():
        print("Context manager block")


@ResourceManager()
async def decorator():
    print("Decorator block")


async def explicit_interface():
    rm = ResourceManager()
    await rm.acquire_resources()
    print("Explicit interface block")
    await rm.release_resources()


async def main():
    await context_manager()
    await decorator()
    await explicit_interface()


if __name__ == "__main__":
    asyncio.run(main())

For more information on how to use aiorem, please refer to the documentation.

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

aiorem-0.0.1.tar.gz (6.0 kB view hashes)

Uploaded Source

Built Distribution

aiorem-0.0.1-py3-none-any.whl (6.0 kB view hashes)

Uploaded Python 3

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