Skip to main content

Only the standard library... but asynchronous!

Project description

aiostdlib

PyPI Version PyPI Downloads License Python Version

Key Features

  • Provides asynchronous versions of the standard libraries;
  • The same API as the Python's standard, blocking API;
  • Blocking IO is performed in a separate thread.

Getting Started

For more, see the documentation.

Installation

The library is available as aiostdlib on PyPI:

pip install aiostdlib

Usage

The aiostdlib API is the same as the standard library, except that it is asynchronous.

builtins

import asyncio

from aiostdlib import builtins


async def main() -> None:
    async with builtins.open("./file.txt", mode="w") as file:
        await file.write("aiostdlib")


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

json

import asyncio

from aiostdlib import builtins, json


async def main() -> None:
    async with builtins.open("./file.json", mode="w") as file:
        await json.dump(["aiostdlib"], file)


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

pathlib

import asyncio

from aiostdlib import pathlib


async def main() -> None:
    path = pathlib.Path("file.txt")

    if not await path.exists():
        await path.write_text("aiostdlib")


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

shutil

import asyncio

from aiostdlib import shutil


async def main() -> None:
    await shutil.rmtree("/tmp/aioshutil")


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

tarfile

import asyncio

from aiostdlib import tarfile


async def main() -> None:
    if not await tarfile.is_tarfile("./aiostdlib.tar.gz"):
        detail = "The file is not a `tar` archive"
        raise RuntimeError(detail)


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

tempfile

import asyncio

from aiostdlib import tempfile


async def main() -> None:
    tempdir, path = await asyncio.gather(
        tempfile.gettempdir(),
        tempfile.mkdtemp(),
    )

    if not path.startswith(tempdir):
        detail = "This is strange..."
        raise RuntimeError(detail)


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

tomllib

import asyncio

from aiostdlib import builtins, tomllib


async def main() -> None:
    async with builtins.open("./file.toml", mode="rb") as file:
        data = await tomllib.load(file)

        if "aiostdlib" not in data:
            detail = "Where is 'aiostdlib'?"
            raise RuntimeError(detail)


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

zipfile

import asyncio

from aiostdlib import zipfile


async def main() -> None:
    if not await zipfile.is_zipfile("./aiostdlib.zip"):
        detail = "The file is not a `zip` archive"
        raise RuntimeError(detail)


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

License

MIT License, Copyright (c) 2024 Sergei Bogdanov. See LICENSE file.

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

aiostdlib-0.0.0.tar.gz (4.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiostdlib-0.0.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file aiostdlib-0.0.0.tar.gz.

File metadata

  • Download URL: aiostdlib-0.0.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.0 Windows/10

File hashes

Hashes for aiostdlib-0.0.0.tar.gz
Algorithm Hash digest
SHA256 f8580704e0cf0223fec805a48c4e110ea866026be23bb2ede5a5cc0086503fba
MD5 dbb814413ad7c9aba2b709d9abfc5970
BLAKE2b-256 c8c3a578c0f9c8c6b9457d38dacad679b124c7dc40ac54787355205e81fdc3b0

See more details on using hashes here.

File details

Details for the file aiostdlib-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: aiostdlib-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.0 Windows/10

File hashes

Hashes for aiostdlib-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 008c6e3868746c20cbde8d3a844ced8045bd0cd884d9996dda51ca5ab16a57ff
MD5 0b4f4b351f3fc06b241714bed7db9f57
BLAKE2b-256 a099439423b2522553d7ad2313339dafb32938ef6c37cd94aee53f62ebeb1d2f

See more details on using hashes here.

Supported by

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