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 bare-bones 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.3.0.tar.gz (138.7 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.3.0-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: jb_async_utils-0.3.0.tar.gz
  • Upload date:
  • Size: 138.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.3.0.tar.gz
Algorithm Hash digest
SHA256 72f525a2c86cefcb3d43a881056c005b24326a5cc9e3ff4c4fa939b2db80d11d
MD5 e77bf0499b2178bebd62d283a1d23077
BLAKE2b-256 c9608b586f55470402cc8459d1a48369655f499db16a8c8e40a3d0078704d816

See more details on using hashes here.

File details

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

File metadata

  • Download URL: jb_async_utils-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 30.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8bbbbb1a662aafd5fb1b9a48054af73f6928c28e9ff5037c65e52bddaf3a3077
MD5 9ab1a8a8055bbe1b11489781f8019c2c
BLAKE2b-256 788900346969ae29650bc59f170182d28604eeb42b34ee50e5dcd65ae73ea8d0

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