Skip to content

syubogdanov/aiostdlib

Repository files navigation

aiostdlib

PyPI Version PyPI Downloads License Python Version

Warning

The library is in the pre-alpha stage.

Key Features

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

Getting Started

Installation

The library is available as aiostdlib on PyPI:

pip install aiostdlib

Usage

The aiostdlib API is the same as the standard library (v3.13), except that it is asynchronous.

[SOON] builtins

For more, see the documentation.

import asyncio

from aiostdlib import builtins


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


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

[SOON] io

For more, see the documentation.

import asyncio

from aiostdlib import io


async def main() -> None:
    async with io.open_code("aiostdlib.py") as file:
        data = await file.read()


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

json

For more, see the documentation.

import asyncio

from aiostdlib import builtins, json


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


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

[SOON] os

For more, see the documentation.

import asyncio

from aiostdlib import os


async def main() -> None:
    if not await os.access("aiostdlib.txt", os.R_OK):
        detail = "You have not been granted access to the file"
        raise RuntimeError(detail)


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

[SOON] pathlib

For more, see the documentation.

import asyncio

from aiostdlib import pathlib


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

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


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

[SOON] shutil

For more, see the documentation.

import asyncio

from aiostdlib import shutil


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


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

[SOON] sys

For more, see the documentation.

import asyncio

from aiostdlib import sys


async def main() -> None:
    await sys.stdout.write("aiostdlib")


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

[SOON] tarfile

For more, see the documentation.

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())

[SOON] tempfile

For more, see the documentation.

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

For more, see the documentation.

import asyncio

from aiostdlib import builtins, tomllib


async def main() -> None:
    async with builtins.open("./aiostdlib.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())

[SOON] zipfile

For more, see the documentation.

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.