CtrlK
CommunityDocumentationLog inGet started
Tessl Logo

tessl/pypi-requests-cache

tessl install tessl/pypi-requests-cache@1.2.0

A persistent cache for python requests

Agent Success

Agent success rate when using this tile

76%

Improvement

Agent success rate improvement when using this tile compared to baseline

1.27x

Baseline

Agent success rate without this tile

60%

task.mdevals/scenario-1/

HTTP Redirect Chain Tracker

Build a tool that fetches URLs and tracks complete redirect chains using caching to improve performance and enable offline access to redirect history.

Requirements

Your implementation should:

  1. Fetch URLs with redirect tracking: Make HTTP requests that follow redirects and preserve the complete chain of redirects for each request.

  2. Cache responses with redirect history: Store responses in a persistent cache so that the complete redirect chain is preserved across program executions.

  3. Access any URL in the chain: When a URL from a previously cached redirect chain is requested again, the system should return the cached final response without making a new HTTP request.

  4. Display redirect information: Provide functionality to display the complete redirect chain for a cached URL, including:

    • Each URL in the redirect chain
    • HTTP status codes for each redirect
    • The final destination URL
  5. Persistence: The cache should persist to disk using SQLite storage so redirect history is available across program runs.

Implementation

@generates

You should implement a Python module that provides:

  • A function to fetch a URL with caching enabled
  • A function to retrieve and display the complete redirect chain for a cached URL
  • Proper cache initialization with appropriate backend

API

def fetch_url(url: str) -> dict:
    """
    Fetch a URL with caching enabled. Follow redirects and preserve the complete chain.

    Args:
        url: The URL to fetch

    Returns:
        A dictionary containing:
        - 'final_url': The final URL after all redirects
        - 'status_code': The final response status code
        - 'redirect_count': Number of redirects encountered
    """
    pass

def get_redirect_chain(url: str) -> list:
    """
    Retrieve the redirect chain for a cached URL.

    Args:
        url: Any URL that was part of a redirect chain (initial URL, intermediate, or final)

    Returns:
        A list of dictionaries, each containing:
        - 'url': The URL at this step
        - 'status_code': The HTTP status code
        Returns an empty list if the URL is not in the cache.
    """
    pass

Test Cases

  • Fetching a URL that redirects (http://httpbin.org/redirect/2) should follow the redirects and return the final destination URL. @test

  • After caching a redirect chain, requesting any intermediate URL from that chain should return the cached final response without making a new HTTP request. @test

  • The get_redirect_chain function should return the complete redirect history including all intermediate URLs and their status codes. @test

  • Cache data should persist across program restarts - fetching the same URL after restarting should use the cached response. @test

Dependencies { .dependencies }

requests-cache { .dependency }

Provides persistent HTTP caching with redirect history support.

Version

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
pypipkg:pypi/requests-cache@1.2.x
tile.json