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-4/

OAuth API Client with Caching

A library that provides a cached OAuth-authenticated HTTP client for accessing protected API resources efficiently.

Capabilities

OAuth Token Management with Caching

Build a client that authenticates using OAuth 2.0 and caches API responses. The client should integrate OAuth authentication with HTTP response caching.

  • When making an authenticated API request, the client correctly applies OAuth authentication and caches the response @test
  • API responses from authenticated requests are cached and reused on subsequent identical requests @test
  • The cache can be cleared independently of the OAuth session @test

Request Mocking for Testing

Provide functionality to test the cached client using mocked HTTP responses, verifying that caching behavior works correctly without making real network requests.

  • When using mocked responses, the client correctly caches the mocked data and returns it on subsequent requests @test
  • The client can be tested with both successful and error responses from the mock adapter @test

Implementation

@generates

API

class CachedOAuthClient:
    """
    An OAuth 2.0 authenticated HTTP client with response caching.

    This client manages OAuth token lifecycle and caches both tokens
    and API responses to minimize network requests.
    """

    def __init__(self, client_id: str, client_secret: str, token_url: str,
                 cache_name: str = 'oauth_cache', cache_backend: str = 'sqlite'):
        """
        Initialize the cached OAuth client.

        Args:
            client_id: OAuth client identifier
            client_secret: OAuth client secret
            token_url: URL to fetch OAuth tokens from
            cache_name: Name for the cache storage
            cache_backend: Backend type for caching (default: 'sqlite')
        """
        pass

    def get(self, url: str, **kwargs) -> requests.Response:
        """
        Make a GET request with OAuth authentication and response caching.

        Args:
            url: The URL to request
            **kwargs: Additional arguments passed to requests

        Returns:
            Response object (may be from cache)
        """
        pass

    def clear_cache(self) -> None:
        """Clear all cached responses (but not tokens)."""
        pass

    def clear_token_cache(self) -> None:
        """Clear cached OAuth tokens."""
        pass

Dependencies { .dependencies }

requests-cache { .dependency }

Provides HTTP response caching capabilities with support for different storage backends and flexible cache management.

@satisfied-by

requests-oauthlib { .dependency }

Provides OAuth 2.0 authentication support for requests library, handling token management and authenticated request signing.

@satisfied-by

requests-mock { .dependency }

Provides HTTP request mocking capabilities for testing, allowing simulation of API responses without network calls.

@satisfied-by

Version

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