Skip to main content

No project description provided

Project description

Async API Data Fetcher

Python aiohttp Poetry MIT License

A high-performance asynchronous solution for fetching and organizing user data from REST APIs.

Features

  • Asynchronous Architecture: Uses aiohttp for concurrent API requests and aiofiles for 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
  • 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

  1. Clone the repository:

    git clone https://github.com/roBoot-LDT/pathlib-requests.git
    cd pathlib-requests
    
  2. Install dependencies:

    poetry install
    
  3. Create .env file:

    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

  1. Fork the project
  2. Create your feature branch
  3. Commit your changes
  4. Push to the branch
  5. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pathlib_requests_nemkov-0.1.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pathlib_requests_nemkov-0.1.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

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

Hashes for pathlib_requests_nemkov-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fcccbc5d8fdd56ff26157aad72dfa9b0e29718c6677d8754f8c54f2e0de4430e
MD5 dcb361132f8cacefb12d33ffd55a0962
BLAKE2b-256 a534faeb227a2882f0f2c2b8f9838e7e2aaa7f9083022b066c57d2ca8b3c996e

See more details on using hashes here.

File details

Details for the file pathlib_requests_nemkov-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pathlib_requests_nemkov-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0611e3691d2774a918c4e80e17ed899459d1badf0fe3cd5b2c8ae02f999191ef
MD5 d6acc6db0c0c616759ace6f351059776
BLAKE2b-256 28b67e3a137b61b198d3e588c065d2c3018a3d92f3d44031f057cb964905310f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page