A unified I/O management toolkit supporting threads, coroutines, files, databases, and data formats
Project description
🧩 Gatling Utility Library
Gatling is a lightweight asynchronous utility library built on aiohttp, asyncio, and threading.
It provides concurrent HTTP requests, coroutine-thread orchestration, data pipelines, and handy file utilities.
📦 Installation
pip install gatling
📁 Module Overview
| Module | Description |
|---|---|
http_client.py |
Async/sync HTTP request handling |
coroutine_thread_mana.py |
Thread + coroutine concurrent task manager |
file_utils.py |
Common file read/write helpers |
taskflow_manager.py |
Multi-stage task pipeline system |
watch.py |
Stopwatch and timing tools |
🌐 1. HTTP Client Module
File: gatling/utility/http_client.py
Provides unified async/sync HTTP request helpers supporting GET, POST, PUT, and DELETE.
Example
from gatling.utility.http_client import sync_fetch_http, async_fetch_http, fwrap
import asyncio, aiohttp
# --- Synchronous request ---
result, status, size = sync_fetch_http("https://httpbin.org/get")
print(status, size, result[:80])
# --- Asynchronous request ---
async def main():
async with aiohttp.ClientSession() as session:
res, status, size = await async_fetch_http(
"https://httpbin.org/ip", session=session, rtype="json"
)
print(res)
asyncio.run(main())
Main functions
async_fetch_http(...): Generic async HTTP fetcherfwrap(...): Safely manages aiohttp session lifecyclesync_fetch_http(...): Simple synchronous wrapper (for scripts)
🧵 2. Coroutine & Thread Manager
File: gatling/utility/coroutine_thread_mana.py
A hybrid thread + coroutine manager that can run both sync and async tasks concurrently.
Example
from gatling.utility.coroutine_thread_mana import CoroutineThreadManager
import asyncio, time
# --- Async task ---
async def async_job(name, delay=0.5):
print(f"{name} running")
await asyncio.sleep(delay)
# --- Sync task ---
def sync_job(name, delay=0.5):
print(f"{name} running")
time.sleep(delay)
# Async mode
m = CoroutineThreadManager(async_job, args=("async-A",), kwargs={"delay": 0.3})
m.start(thread_worker=2, coroutine_worker=2)
time.sleep(2)
m.stop()
# Sync mode
m = CoroutineThreadManager(sync_job, args=("sync-B",), kwargs={"delay": 0.2})
m.start(thread_worker=2)
time.sleep(2)
m.stop()
Main methods
.start(thread_worker, coroutine_worker): Starts the workers.stop(): Stops all threads safely
💾 3. File Utility Module
File: gatling/utility/file_utils.py
Convenient helpers for reading and writing JSON, JSONL, Pickle, TOML, text, and byte files.
Example
from gatling.utility.file_utils import *
save_json({"a": 1}, "data.json")
print(read_json("data.json"))
save_jsonl([{"x": 1}, {"x": 2}], "data.jsonl")
print(read_jsonl("data.jsonl"))
save_text("Hello world", "msg.txt")
print(read_text("msg.txt"))
Main functions
save_json / read_jsonsave_jsonl / read_jsonlsave_text / read_textsave_pickle / read_picklesave_bytes / read_bytesread_tomlremove_file
🔄 4. Task Flow Manager
File: gatling/utility/taskflow_manager.py
Builds a multi-stage processing pipeline — combining threads, coroutines, and queues. Each stage can be synchronous or asynchronous.
Example
from gatling.utility.taskflow_manager import TaskFlowManager
from queue import Queue
import asyncio, time
def sync_square(x):
time.sleep(0.2)
return x * x
async def async_double(x):
await asyncio.sleep(0.3)
return x * 2
def sync_to_str(x):
return f"Result: {x}"
q_wait = Queue()
q_done = Queue()
tfm = TaskFlowManager(q_wait, q_done, retry_on_error=False)
tfm.append_stagefctn(sync_square)
tfm.append_stagefctn(async_double)
tfm.append_stagefctn(sync_to_str)
for i in range(5):
q_wait.put(i)
tfm.start()
tfm.await_print(interval=1)
tfm.stop()
print(list(q_done.queue))
Main classes
TaskFlowManager: Coordinates multi-stage parallel workflowsTaskQueueTracker: Monitors queue states, errors, and speed metrics
⏱️ 5. Stopwatch Utility
File: gatling/utility/watch.py
A simple stopwatch for timing operations, plus a decorator for measuring function execution time.
Example
from gatling.utility.watch import Watch, watch_time
import time
@watch_time
def slow_func():
time.sleep(1)
slow_func()
w = Watch()
time.sleep(0.5)
print("Δt:", w.see_seconds(), "Total:", w.total_seconds())
Main items
Watch: Manual stopwatch class for measuring intervalswatch_time: Decorator that prints function execution time
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gatling-0.2.2.tar.gz.
File metadata
- Download URL: gatling-0.2.2.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f40ecf5bb11e960c220493209cf84647bb08608d62083964e228fdcd4bd4087a
|
|
| MD5 |
a0d507cea5d5e91b0066280258dc2799
|
|
| BLAKE2b-256 |
4d1117d10683bb1404ae0d84b93f34a179f4de0582fc2387c829f587f437c9bc
|
File details
Details for the file gatling-0.2.2-py3-none-any.whl.
File metadata
- Download URL: gatling-0.2.2-py3-none-any.whl
- Upload date:
- Size: 19.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
50d0a5d6a9f4739be6b92d2108fa7da1cd739bf8b0fd348299a5098e0e56666b
|
|
| MD5 |
aa84fd9068dcab6343d875049f857a8d
|
|
| BLAKE2b-256 |
67b3da3583c00259e7430abd9e94db7e4eadb18036591ef94cf3bc89e41cce4a
|