dark-req
🇪🇬 بالعربي
dark-req مكتبة بايثون للتعامل مع HTTP، شغالة بنفس طريقة مكتبة requests
المشهورة — بس بتصلّح كل عيوبها، ومن غير أي تعقيد زيادة.
ليه dark-req؟
- ⏱️ مهلة افتراضية ذكية: الاتصال 5 ثواني والقراءة 30 ثانية — عمرها ما هتعلّق للأبد زي
requests - 🔁 إعادة محاولة تلقائية: لو السيرفر رد
429أو5xxأو الاتصال وقع، بتحاول لوحدها مع انتظار متزايد وبتحترمRetry-After - 🚦 تحديد معدل الطلبات:
rate_limit=5يعني 5 طلبات في الثانية لكل سيرفر - 🔗 رابط أساسي للجلسة:
base_url="https://api.example.com"وبعدها نادي/usersبس - 🪝 خطافات (Hooks): نفّذ كود قبل الطلب وبعده وعند الخطأ
- ⬇️ تحميل ب progress: سطر واحد بدل ما تكتب loop بنفسك
- ⚡ دعم Async: نفس الواجهة بالظبط مع
AsyncSession - 🔐 توثيق جاهز:
BearerAuth("token")أو(user, pass)
مثال سريع
import dark_req
# شغالة زي requests بالظبط...
r = dark_req.get("https://api.example.com/users", timeout=10)
print(r.status_code, r.json())
# ...بس بقدرات زيادة
s = dark_req.Session(
base_url="https://api.example.com",
max_retries=3, # إعادة محاولة تلقائية
rate_limit=5, # 5 طلبات/ثانية لكل سيرفر
hooks={"on_error": [lambda e: print("failed:", e)]},
)
r = s.get("/users", params={"page": 2})
r.raise_for_status()
# تحميل ملف مع progress في سطر واحد
s.download("https://example.com/big.zip", "big.zip",
progress=lambda done, total: print(f"{done}/{total}"))
# Async بنفس الواجهة
import asyncio
async def main():
async with dark_req.AsyncSession(base_url="https://api.example.com") as s:
users, repos = await asyncio.gather(s.get("/users"), s.get("/repos"))
asyncio.run(main())
التثبيت
pip install dark-req
بتحتاج Python 3.9 أو أحدث.
🇬🇧 In English
dark-req is a requests-compatible Python HTTP client that fixes
everything requests gets wrong — in the same lightweight footprint
(only urllib3 + certifi).
Why dark-req?
- ⏱️ Sane default timeouts: 5s connect / 30s read — never hangs forever like
requests - 🔁 Auto-retry: on
429/5xxand network errors, with exponential backoff + jitter, honorsRetry-After - 🚦 Per-host rate limiting:
rate_limit=5= 5 req/sec per host (token bucket) - 🔗
base_urlsessions: set it once, then just call/users - 🪝 Hooks:
on_request/on_response/on_error - ⬇️ Downloads with progress: one line instead of a manual streaming loop
- ⚡ Async support:
AsyncSessionwith the exact same API - 🔐 Auth helpers:
BearerAuth("token")or(user, pass)tuples
Quick example
import dark_req
# Works exactly like requests...
r = dark_req.get("https://api.example.com/users", timeout=10)
print(r.status_code, r.json())
# ...but with superpowers baked in
s = dark_req.Session(
base_url="https://api.example.com",
max_retries=3, # auto-retry on 429/5xx + connection errors
rate_limit=5, # max 5 req/sec per host (token bucket)
hooks={"on_error": [lambda e: print("failed:", e)]},
)
r = s.get("/users", params={"page": 2}) # -> https://api.example.com/users?page=2
r.raise_for_status()
# Downloads with progress, one line
s.download("https://example.com/big.zip", "big.zip",
progress=lambda done, total: print(f"{done}/{total}"))
# Async, same API
import asyncio
async def main():
async with dark_req.AsyncSession(base_url="https://api.example.com") as s:
users, repos = await asyncio.gather(s.get("/users"), s.get("/repos"))
asyncio.run(main())
Install
pip install dark-req
Requires Python 3.9+.
⚔️ dark-req vs requests
| الميزة / Feature | requests |
dark-req |
|---|---|---|
| Default timeout | ❌ none — hangs forever | ✅ connect=5s, read=30s |
| Retries | ❌ manual | ✅ auto-retry on 429/5xx + network errors, exponential backoff + jitter, honors Retry-After |
| Rate limiting | ❌ | ✅ per-host token bucket (rate_limit=5) |
base_url on sessions |
❌ | ✅ |
| Hooks | ❌ (only transport adapters) | ✅ on_request / on_response / on_error |
| Download with progress | ❌ manual streaming loop | ✅ session.download(url, path, progress=...) |
| Async | ❌ sync only | ✅ AsyncSession, same API |
| Bearer auth helper | ❌ | ✅ BearerAuth("token") / (user, pass) tuples |
raise_for_status message |
❌ bare status | ✅ includes URL + body snippet |
response.json() errors |
❌ cryptic JSONDecodeError |
✅ dark_req.JSONDecodeError (also a ValueError), carries request/response |
| Retry exhaustion | ❌ silent last response | ✅ RetryExhausted with attempts + last_exception |
codes |
✅ | ✅ dark_req.codes.ok == 200 |
Everything else stays familiar: get/post/put/patch/delete/head/options,
Session, Request/PreparedRequest/Response, HTTPBasicAuth,
and an exception hierarchy mirroring requests (so existing except
blocks keep working).
Sane defaults / إعدادات ذكية
dark_req.get("https://slow.example.com") # gives up after 5s connect / 30s read
dark_req.get("https://flaky.example.com") # 3 automatic retries with backoff
Override per call with timeout=... (seconds, (connect, read) tuple, or
timeout=None to wait indefinitely), max_retries=0 to disable retries,
verify=False to skip TLS verification.
Roadmap / خطة التطوير
files=multipart uploads- Proxy support from environment variables
- HTTP/2 transport option
- Connection-level metrics / tracing hooks
License / الرخصة
MIT
Metadata
Release files for dark-req 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| dark_req-0.1.1.tar.gz | 19.3 kB | Without provenance | Details for dark_req-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| dark_req-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for dark_req-0.1.1-py3-none-any.whl |
Total release size: 36.2 kB
Release files / dark_req-0.1.1.tar.gz
| Download URL | dark_req-0.1.1.tar.gz |
|---|---|
| Size | 19.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9f408fafdf1e28e18bda7986f56b8a98bf01fde8c30f711357da8ac4db499c02
|
|
BLAKE2b-256 checksum How to use checksums |
bfdec404b2310bc1be64ce6c1dc92c3474880448b86e85bca97828375401fef5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / dark_req-0.1.1-py3-none-any.whl
| Download URL | dark_req-0.1.1-py3-none-any.whl |
|---|---|
| Size | 16.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a97f00a5547706b847de1363cba4c082d5a3e630426deaffeb626212b7fabbd0
|
|
BLAKE2b-256 checksum How to use checksums |
7a33a9d790ead40325848f60c4b2a8eb50302d99ecb0ff06d563d073242433b8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for dark-req 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.