A simple asynchronous HTTP client with just the essentials.
Project description
afetch
A simple asynchronous HTTP client with just the essentials.
Features
- Rate Limiting - Automatically limits requests per domain to avoid overwhelming servers
- Automatic Retries - Built-in exponential backoff retry mechanism for failed requests
- Response Caching - Cache responses to reduce redundant network calls
- Concurrent Fetching - Fetch multiple URLs in parallel with
fetch_all()
Installation
pip install afetch
Or using uv:
uv add afetch
Quick Start
import asyncio
from afetch import Fetcher
async def main():
urls = [
"https://example.com/page1",
"https://example.com/page2",
"https://example2.com",
]
async with Fetcher() as fetcher:
responses = await fetcher.fetch_all(urls)
for response in responses:
print(response)
asyncio.run(main())
Usage
Fetching a Single URL
async with Fetcher() as fetcher:
content = await fetcher.fetch("https://example.com")
print(content)
Fetching Multiple URLs
async with Fetcher() as fetcher:
urls = ["https://example.com/a", "https://example.com/b"]
responses = await fetcher.fetch_all(urls)
Custom Configuration
from afetch import Fetcher, FetcherConfig
config = FetcherConfig(
max_rate_per_domain=2, # Allow 2 requests per time period
time_period_per_domain=1, # Time period in seconds
retry_attempts=5, # Number of retry attempts
cache_enabled=True, # Enable response caching
)
async with Fetcher(config) as fetcher:
content = await fetcher.fetch("https://example.com")
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Development Setup
- Clone the repository:
git clone https://github.com/okayama-daiki/afetch.git
cd afetch
- Install dependencies with uv:
uv sync
Testing
uv run pytest -v
Formatting and Linting
uv run ruff check .
Acknowledgments
This project is built on top of these excellent libraries:
- aiohttp - Async HTTP client/server framework
- aiohttp-client-cache - Async HTTP cache backend
- aiohttp-retry - Retry functionality for aiohttp
- aiolimiter - Async rate limiter
License
This project is licensed under the MIT License - see the LICENSE file for details.
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 afetch-0.2.0.tar.gz.
File metadata
- Download URL: afetch-0.2.0.tar.gz
- Upload date:
- Size: 4.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
394a25f724c0bf22e1a9dbcd6e66a5b9f8fb9f3a06b26cb07ce248b4442d6828
|
|
| MD5 |
3021cf4c4a811aae25b474a984f9b8c5
|
|
| BLAKE2b-256 |
6531abca6d8095a37a369c91c117e45fefd99b7232ed5339783181bf710bd1b0
|
Provenance
The following attestation bundles were made for afetch-0.2.0.tar.gz:
Publisher:
release.yml on okayama-daiki/afetch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
afetch-0.2.0.tar.gz -
Subject digest:
394a25f724c0bf22e1a9dbcd6e66a5b9f8fb9f3a06b26cb07ce248b4442d6828 - Sigstore transparency entry: 728164940
- Sigstore integration time:
-
Permalink:
okayama-daiki/afetch@7b31645f42362609b30fb5d7c847e6e6be367c55 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/okayama-daiki
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7b31645f42362609b30fb5d7c847e6e6be367c55 -
Trigger Event:
push
-
Statement type:
File details
Details for the file afetch-0.2.0-py3-none-any.whl.
File metadata
- Download URL: afetch-0.2.0-py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ff0fe7e1e056406cd2e694ecdc75ef7c3e26f6760b4fdc4ba70f5280db0adaf4
|
|
| MD5 |
bed89ae00190c86f80dc9326b5adefc1
|
|
| BLAKE2b-256 |
e387c8b95f5517202b4477c66ff62eaba5c2c7203c9e55f40972c08c6acdd29e
|
Provenance
The following attestation bundles were made for afetch-0.2.0-py3-none-any.whl:
Publisher:
release.yml on okayama-daiki/afetch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
afetch-0.2.0-py3-none-any.whl -
Subject digest:
ff0fe7e1e056406cd2e694ecdc75ef7c3e26f6760b4fdc4ba70f5280db0adaf4 - Sigstore transparency entry: 728164960
- Sigstore integration time:
-
Permalink:
okayama-daiki/afetch@7b31645f42362609b30fb5d7c847e6e6be367c55 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/okayama-daiki
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7b31645f42362609b30fb5d7c847e6e6be367c55 -
Trigger Event:
push
-
Statement type: