{"id":5539,"library":"types-requests-oauthlib","title":"Typing stubs for requests-oauthlib","description":"This package provides static typing stubs for the `requests-oauthlib` library, enabling type checkers like Mypy and Pyright to perform static analysis on code that uses `requests-oauthlib`. It is part of the broader typeshed project, which maintains a collection of high-quality type annotations for Python libraries. The current version, 2.0.0.20260408, aims to provide accurate annotations for `requests-oauthlib==2.0.*` and requires Python >=3.10. Stub packages from typeshed are released automatically when changes are merged into the typeshed repository.","status":"active","version":"2.0.0.20260408","language":"python","source_language":"en","source_url":"https://github.com/python/typeshed/tree/main/stubs/requests-oauthlib","tags":["types","type hints","stubs","requests-oauthlib","oauth","requests","typeshed"],"install":[{"cmd":"pip install types-requests-oauthlib","lang":"bash","label":"Install stubs"},{"cmd":"pip install requests-oauthlib","lang":"bash","label":"Install runtime library (required)"}],"dependencies":[{"reason":"This package provides typing stubs for `requests-oauthlib`, which must be installed for runtime functionality.","package":"requests-oauthlib","optional":false},{"reason":"`requests-oauthlib` depends on the `requests` library.","package":"requests","optional":false},{"reason":"`requests-oauthlib` builds upon the `oauthlib` library.","package":"oauthlib","optional":false}],"imports":[{"wrong":"from requests_oauthlib_stubs import OAuth1Session","symbol":"OAuth1Session","correct":"from requests_oauthlib_stubs import OAuth1Session"}],"quickstart":{"code":"import os\nfrom typing import Dict, Any, Tuple\nfrom requests_oauthlib import OAuth2Session\nfrom requests.models import Response\n\n# --- Configuration (replace with your actual values or env vars) ---\nCLIENT_ID: str = os.environ.get('OAUTH_CLIENT_ID', 'your_client_id')\nCLIENT_SECRET: str = os.environ.get('OAUTH_CLIENT_SECRET', 'your_client_secret')\nAUTHORIZATION_BASE_URL: str = os.environ.get('OAUTH_AUTH_URL', 'https://example.com/oauth/authorize')\nTOKEN_URL: str = os.environ.get('OAUTH_TOKEN_URL', 'https://example.com/oauth/token')\nREDIRECT_URI: str = os.environ.get('OAUTH_REDIRECT_URI', 'https://example.com/callback')\nSCOPE: list[str] = ['read', 'write'] # Example scopes\n\ndef run_oauth_flow() -> None:\n    # 1. Create an OAuth2Session instance\n    # The type hints from types-requests-oauthlib will check this.\n    oauth: OAuth2Session = OAuth2Session(CLIENT_ID, redirect_uri=REDIRECT_URI, scope=SCOPE)\n\n    # 2. Prepare the authorization request URL\n    authorization_url: str\n    state: str\n    authorization_url, state = oauth.authorization_url(AUTHORIZATION_BASE_URL)\n\n    print(f\"Visit this URL to authorize: {authorization_url}\")\n    print(f\"Remember state for CSRF protection: {state}\")\n\n    # --- Simulate authorization response ---\n    # In a real application, the user would visit authorization_url, grant access,\n    # and be redirected to REDIRECT_URI with a 'code' and 'state' in the URL.\n    # For this example, we'll simulate the response URL.\n    simulated_auth_response_url: str = f\"{REDIRECT_URI}?code=AUTHORIZATION_CODE_FROM_PROVIDER&state={state}\"\n    print(f\"\\nSimulating callback URL: {simulated_auth_response_url}\")\n\n    # 3. Fetch the access token\n    token: Dict[str, Any] = oauth.fetch_token(\n        TOKEN_URL,\n        client_secret=CLIENT_SECRET,\n        authorization_response=simulated_auth_response_url\n    )\n\n    print(f\"\\nAccess Token obtained: {token}\")\n\n    # 4. Use the obtained token to make a protected API request\n    # The 'oauth' session automatically adds the authorization header.\n    # The type hints for 'get' and 'Response' are provided by types-requests and types-requests-oauthlib.\n    try:\n        response: Response = oauth.get('https://example.com/api/protected_resource')\n        response.raise_for_status() # Raise an exception for HTTP errors\n        print(f\"\\nProtected resource content: {response.json()}\")\n    except Exception as e:\n        print(f\"\\nError accessing protected resource: {e}\")\n\nif __name__ == \"__main__\":\n    run_oauth_flow()","lang":"python","description":"This quickstart demonstrates a basic OAuth 2.0 Authorization Code flow using `requests-oauthlib` with static type checking provided by `types-requests-oauthlib`. It covers initializing an `OAuth2Session`, generating an authorization URL, simulating a callback, fetching an access token, and making a protected API call. Type hints are explicitly added to illustrate how the stub package aids in catching potential type mismatches during development."},"warnings":[{"fix":"Always install both `requests-oauthlib` and `types-requests-oauthlib`: `pip install requests-oauthlib types-requests-oauthlib`.","message":"The `types-requests-oauthlib` package only provides static type hints (stubs). It does NOT include the actual runtime code for `requests-oauthlib`. You must install `requests-oauthlib` separately for your application to function at runtime.","severity":"gotcha","affected_versions":"All versions of `types-requests-oauthlib`"},{"fix":"Pin your `types-requests-oauthlib` version to match the expected runtime version (e.g., `types-requests-oauthlib~=2.0.0`) or use a version range that ensures compatibility. Regularly update both the runtime and stub packages together after verifying compatibility.","message":"Type stub versions are explicitly tied to the runtime package versions they annotate. `types-requests-oauthlib` v2.0.0.20260408 provides annotations for `requests-oauthlib==2.0.*`. Using a stub package version that is incompatible with your runtime `requests-oauthlib` version can lead to incorrect type checking or errors. Minor updates to stub packages can also sometimes introduce new type errors, as typeshed aims for strictness.","severity":"breaking","affected_versions":"All versions"},{"fix":"Understand that stub packages are for compile-time type checking only. Any runtime issues or feature requests should be directed to the `requests-oauthlib` project.","message":"`types-requests-oauthlib` does not add or alter runtime functionality, fix bugs in `requests-oauthlib`, or change its behavior. Its sole purpose is for static analysis by type checkers. Expecting it to resolve runtime issues is a common misunderstanding.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Ensure your project uses Python 3.10 or a more recent version. If you must use an older Python version, you may need to find an older, compatible version of `types-requests-oauthlib` (if one exists) or disable type checking for this library.","message":"The `types-requests-oauthlib` package requires Python 3.10 or newer. Older Python versions (e.g., 3.9 and below) are not supported by recent versions of this stub package.","severity":"deprecated","affected_versions":"Versions 2.0.0.x and newer"}],"env_vars":null,"search_vec":"'2.0':71 '2.0.0.20260408':61 '3.10':75 'accur':65 'aim':62 'analysi':29 'annot':54,66 'automat':82 'broader':42 'chang':84 'checker':21 'code':31 'collect':48 'current':59 'enabl':19 'high':51 'high-qual':50 'hint':93 'librari':18,57 'like':22 'maintain':46 'merg':86 'mypi':23 'oauth':98 'oauthlib':6,17,36,70,97 'packag':8,77 'part':39 'perform':27 'project':44 'provid':9,64 'pyright':25 'python':56,74 'qualiti':52 'releas':81 'repositori':90 'request':5,16,35,69,96,99 'requests-oauthlib':4,15,34,68,95 'requir':73 'static':10,28 'stub':2,12,76,94 'type':1,11,20,53,91,92 'typesh':43,79,89,100 'use':33 'version':60","created_at":"2026-04-14T01:38:12.309744+00:00","updated_at":"2026-04-16T23:44:42.882132+00:00","problems":{"verify_error":"Traceback (most recent call last):\n  File \"<string>\", line 1, in <module>\nModuleNotFoundError: No module named 'requests_oauthlib_stubs'"},"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"2.0.0.20260610","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/typeshed-internal/stub_uploader","docs":null,"changelog":"https://github.com/typeshed-internal/stub_uploader/blob/main/data/changelogs/requests-oauthlib.md","pypi":"https://pypi.org/project/types-requests-oauthlib/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["type-stubs","http-networking","auth-security"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-07-03","last_verified":"2026-08-30","next_check":"2026-07-10","install_tag":null}}