No project description provided
Project description
Async API Data Fetcher
A high-performance asynchronous solution for fetching and organizing user data from REST APIs.
Features
- Asynchronous Architecture: Uses
aiohttpfor concurrent API requests andaiofilesfor non-blocking file operations - Structured Data Organization:
- Creates user-specific directories
- Stores posts as individual JSON files
- Configuration Management:
- Environment variables via
.env - Automatic config validation
- Environment variables via
- Efficient Resource Usage:
- Single reusable HTTP session
- Proper resource cleanup
- Error Handling:
- Basic data validation
- HTTP status code checking
Prerequisites
- Python 3.8+
- Poetry (for dependency management)
Installation
-
Clone the repository:
git clone https://github.com/roBoot-LDT/pathlib-requests.git cd pathlib-requests
-
Install dependencies:
poetry install -
Create
.envfile:API_URL=https://jsonplaceholder.typicode.com/ USERS_ENDPOINT=users POSTS_ENDPOINT=posts DATA_DIR=data TIMEOUT=5
Usage
Run the main script:
poetry run python main.py
Expected Output Structure
data/
└── user_posts/
├── 1/
│ ├── post_1.json
│ └── post_2.json
└── 2/
├── post_3.json
└── post_4.json
Configuration
| Environment Variable | Default | Description |
|---|---|---|
API_URL |
Required | Base API URL |
USERS_ENDPOINT |
users |
Users endpoint path |
POSTS_ENDPOINT |
posts |
Posts endpoint path |
DATA_DIR |
data |
Root data directory |
TIMEOUT |
5 |
Request timeout in seconds |
Architecture
classDiagram
class AppConfig{
+data_dir: Path
+user_dir: Path
+api_url: str
+timeout: int
+_find_dotenv()
+_get_project_root()
}
class Data{
+save_data()
+_async_save_data()
}
class Organizer{
+fetch_all()
+_fetch_data()
+close()
}
AppConfig --> Data : provides config
AppConfig --> Organizer : provides config
Organizer --> Data : saves data
Performance
Typical execution times:
- Fetch 10 users with posts: ~1.2s
- Fetch 100 users with posts: ~3.5s
License
Distributed under the MIT License. See LICENSE for more information.
Contributing
- Fork the project
- Create your feature branch
- Commit your changes
- Push to the branch
- Open a pull request
TODO
- Add retry mechanism for failed requests
- Implement comprehensive logging
- Add unit tests
- Support paginated API responses
Made with ❤️ by Nemkov
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 pathlib_requests_nemkov-0.1.1.tar.gz.
File metadata
- Download URL: pathlib_requests_nemkov-0.1.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.13.3 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fcccbc5d8fdd56ff26157aad72dfa9b0e29718c6677d8754f8c54f2e0de4430e
|
|
| MD5 |
dcb361132f8cacefb12d33ffd55a0962
|
|
| BLAKE2b-256 |
a534faeb227a2882f0f2c2b8f9838e7e2aaa7f9083022b066c57d2ca8b3c996e
|
File details
Details for the file pathlib_requests_nemkov-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pathlib_requests_nemkov-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.2 CPython/3.13.3 Darwin/24.4.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0611e3691d2774a918c4e80e17ed899459d1badf0fe3cd5b2c8ae02f999191ef
|
|
| MD5 |
d6acc6db0c0c616759ace6f351059776
|
|
| BLAKE2b-256 |
28b67e3a137b61b198d3e588c065d2c3018a3d92f3d44031f057cb964905310f
|