Python SDK for GopherQueue - Enterprise-grade background job processing
Project description
GopherQueue Python SDK
A Python client library for GopherQueue, an enterprise-grade background job processing system.
Installation
pip install gopherqueue
Or install from source:
pip install -e .
Quick Start
import asyncio
from gopherqueue import GopherQueue
async def main():
# Create client
client = GopherQueue("http://localhost:8080")
# Submit a job
job = await client.submit("email", {"to": "user@example.com", "subject": "Hello!"})
print(f"Job created: {job.id}")
# Wait for completion
result = await client.wait(job.id, timeout=30)
print(f"Job completed: {result.success}")
asyncio.run(main())
Features
- Async/await support - Built on
aiohttpfor high performance - Sync API available - Use
GopherQueueSyncfor synchronous code - Batch submission - Submit up to 1000 jobs atomically
- Long-polling wait - Efficiently wait for job completion
- SSE events - Real-time job status updates
- Type hints - Full type annotation support
- API key auth - Secure API access
API Reference
Client Options
from gopherqueue import GopherQueue
client = GopherQueue(
url="http://localhost:8080",
api_key="your-api-key", # Optional API key
timeout=30, # Request timeout in seconds
max_connections=100, # Connection pool size
)
Submit Job
job = await client.submit(
job_type="email",
payload={"to": "user@example.com"},
priority=1, # 0=Critical, 1=High, 2=Normal, 3=Low, 4=Bulk
delay="5m", # Delay before execution
timeout="30m", # Max execution time
max_attempts=3, # Retry attempts
idempotency_key="unique-key", # Deduplication
tags={"env": "prod"}, # Metadata
)
Batch Submit
results = await client.submit_batch([
{"type": "email", "payload": {"to": "user1@example.com"}},
{"type": "email", "payload": {"to": "user2@example.com"}},
], atomic=True) # All-or-nothing
print(f"Accepted: {results.accepted}, Rejected: {results.rejected}")
Wait for Job
result = await client.wait(job.id, timeout=60)
if result.completed:
if result.success:
print(f"Output: {result.result}")
else:
print(f"Error: {result.result.error}")
Get Job Status
job = await client.get(job_id)
print(f"State: {job.state}, Progress: {job.progress}%")
List Jobs
jobs = await client.list(state="running", type="email", limit=100)
for job in jobs:
print(f"{job.id}: {job.state}")
Cancel Job
job = await client.cancel(job_id, reason="No longer needed", force=True)
Retry Failed Job
job = await client.retry(job_id, reset_attempts=True)
SSE Events
async for event in client.events(job_id="*"): # Subscribe to all jobs
print(f"Event: {event.type}, Job: {event.data.id}")
Synchronous API
from gopherqueue import GopherQueueSync
client = GopherQueueSync("http://localhost:8080")
job = client.submit("email", {"to": "user@example.com"})
result = client.wait(job.id, timeout=30)
License
MIT License
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
gopherqueue-1.1.2.tar.gz
(3.0 kB
view details)
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 gopherqueue-1.1.2.tar.gz.
File metadata
- Download URL: gopherqueue-1.1.2.tar.gz
- Upload date:
- Size: 3.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
95b1985c8e4b13a3c8a9266adca9231b96737d005fda13ba4a230a2c0ef38c75
|
|
| MD5 |
fe0ce2b35ce1edafdd1f000e4e9ec66c
|
|
| BLAKE2b-256 |
37b0931de38e1d81c5aff4f232e9525a8f5cedaa8229710c030680a7f7cb61c8
|
File details
Details for the file gopherqueue-1.1.2-py3-none-any.whl.
File metadata
- Download URL: gopherqueue-1.1.2-py3-none-any.whl
- Upload date:
- Size: 2.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de85b9196a5e882ffa29a3885a2720a4ba89ece6719e338af64366d1f78b5217
|
|
| MD5 |
51c6202ab82c50540dfabd204d9ab112
|
|
| BLAKE2b-256 |
1b797234488bba844155de312daf9789e5f8c07c20aab4e9daab279d94e84a0f
|