CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-hishel

Persistent cache implementation for httpx and httpcore following RFC 9111 specification

74

1.48x
Overview
Eval results
Files

task.mdevals/scenario-2/

HTTP Client with Persistent Caching

Build a Python HTTP client utility that adds persistent caching capabilities to the requests library.

Requirements

Create a module that provides a configured HTTP session with caching enabled.

Cached Session Setup

Create a function create_cached_session() that returns a requests Session object with the following caching configuration:

  • The session must have caching enabled through an adapter-based mechanism
  • The caching adapter should be mounted for both http:// and https:// URL schemes
  • Cache storage should persist to a SQLite database at the path .cache/http_cache.db
  • Cached responses should have a default time-to-live (TTL) of 300 seconds

Cache Observability

After making requests with the session, it should be possible to inspect response metadata to determine:

  • Whether the response was served from the cache
  • When a cached response was originally stored
  • Whether the current response was saved to the cache

Test Cases

  • Making two identical GET requests to https://httpbin.org/json results in the first response being stored and the second retrieved from cache @test
  • The created session has caching adapters properly mounted for both HTTP and HTTPS schemes @test
  • Response objects contain metadata indicating cache hit/miss status and timestamps @test

Implementation

@generates

API

from requests import Session

def create_cached_session() -> Session:
    """
    Creates and returns a requests Session with persistent caching enabled.

    The session uses an adapter-based caching mechanism that stores responses
    in a SQLite database with a 5-minute default TTL.

    Returns:
        Session: A configured requests Session object with caching support
    """
    pass

Dependencies { .dependencies }

hishel { .dependency }

Provides HTTP caching capabilities through adapter integration with requests.

@satisfied-by

requests { .dependency }

HTTP library for making requests.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/pypi-hishel

tile.json