Skip to main content

Utilities for running asynchronous IO tasks.

Project description

Async Utils

PyPI version PyPI license

Utilities for running asynchronous IO tasks.

Authors

  • Li Peng-Hsuan (李朋軒) @ ailabs.tw (jacobvsdanniel [at] gmail.com)

Features

  • A framework of modularized, customizable data definition, quota management, and task runner
  • A barebone math application for demo purposes
  • OpenAI and Deep Infra applications for high-throughput, real-time, batched requests

Installation

python -m pip install jb_async_utils

Usage

For more detailed usage, see examples

import json
import asyncio
import tiktoken
from openai import AsyncOpenAI
from async_utils import (
    process_batch_data, OpenAITaskDatum, OpenAIQuotaManager, openai_task_runner
)

input_file = "tmp_in.jsonl"
output_file = "tmp_out.jsonl"

api_key = input("API key: ")
OpenAITaskDatum.client = AsyncOpenAI(api_key=api_key)
OpenAITaskDatum.tokenizer = tiktoken.encoding_for_model("gpt-5")
quota_manager = OpenAIQuotaManager(60, 500)

with open(input_file, "w", encoding="utf8") as f:
    for i in range(10):
        datum = {
            "text_in": f"Reverse the word order of the sentence: I have {i + 1} fish.",
            "model": "gpt-5.2",
            "choices": 1,
        }
        json.dump(datum, f, ensure_ascii=False)
        f.write("\n")

asyncio.run(process_batch_data(
    input_file, output_file, OpenAITaskDatum, openai_task_runner, quota_manager,
    max_task_runs=3, start_id=None, end_id=None, ignore_and_rewrite_output_file=True,
    sleep_interval=0.001,
))

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

jb_async_utils-0.2.0.tar.gz (138.1 kB view details)

Uploaded Source

Built Distribution

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

jb_async_utils-0.2.0-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

Details for the file jb_async_utils-0.2.0.tar.gz.

File metadata

  • Download URL: jb_async_utils-0.2.0.tar.gz
  • Upload date:
  • Size: 138.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for jb_async_utils-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b4ddc89c82e1dd845fbf6a549326dc51aef5eb368988593b23ddc6f8eaac6974
MD5 2d9e1b7b8655be03fedd8af5ad7e21db
BLAKE2b-256 ae3d97b8261260ace5b104788b750523da1e898af79fef440fd632beac1098f2

See more details on using hashes here.

File details

Details for the file jb_async_utils-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: jb_async_utils-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 30.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.28 {"installer":{"name":"uv","version":"0.9.28","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"22.04","id":"jammy","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for jb_async_utils-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e037d22250d74265689254f0eae1ef01039d1c6c22daa3bc759b936192c69713
MD5 8c59039efc69fcbc1c6848ce728b1dc7
BLAKE2b-256 2346db0cb96978cfcc3f500af813969b86279478927fbe7b3bb1ac6d9c802ba1

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