{"library":"restfly","title":"RESTfly","description":"RESTfly (pronounced restfully) is a framework for building libraries to easily interact with RESTful APIs. It aims to simplify the creation of API interaction libraries by providing a basic scaffolding with an emphasis on simplicity and readability of the resulting code. The library is currently at version 1.5.1 and receives regular updates, ensuring active development and maintenance.","language":"python","status":"active","last_verified":"Sun May 17","install":{"commands":["pip install restfly"],"cli":null},"imports":["from restfly.session import APISession","from restfly.endpoint import APIEndpoint","from restfly.errors import APIError, BadRequestError, UnauthorizedError"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nfrom restfly.session import APISession\nfrom restfly.endpoint import APIEndpoint\n\n# Define your base API session\nclass MyAPI(APISession):\n    _url = 'https://httpbin.org'\n    \n    # Example of adding an API key, if needed\n    def __init__(self, api_key: str = os.environ.get('MY_API_KEY', ''), **kwargs):\n        self._api_key = api_key\n        super().__init__(**kwargs)\n\n    def _build_session(self, **kwargs):\n        super()._build_session(**kwargs)\n        if self._api_key:\n            self._session.headers.update({\n                'X-API-Key': self._api_key\n            })\n\n# Define an endpoint for a specific resource\nclass StatusAPI(APIEndpoint):\n    _path = 'status'\n\n    def get_status_code(self, code: int) -> dict:\n        # _req is a protected method for making requests, leveraging _path\n        return self._req('GET', path=str(code)).json()\n\n# Instantiate and use the API\nmy_api_client = MyAPI(api_key='your_optional_api_key_here')\n\n# Link the endpoint to the API session\nmy_api_client.status = StatusAPI(my_api_client)\n\ntry:\n    # Call a simple GET request directly from the session\n    response_get = my_api_client.get('get').json()\n    print(f\"GET /get Response: {response_get.get('url')}\")\n\n    # Use the defined endpoint\n    status_200 = my_api_client.status.get_status_code(200)\n    print(f\"GET /status/200 Response: {status_200}\")\n\n    status_404 = my_api_client.status.get_status_code(404)\n    print(f\"GET /status/404 Response: {status_404}\") # This will raise an APIError\n\nexcept Exception as e:\n    print(f\"An error occurred: {e}\")\n\n# Example of handling specific errors\nfrom restfly.errors import NotFoundError, APIError\n\ntry:\n    my_api_client.status.get_status_code(404)\nexcept NotFoundError as e:\n    print(f\"Caught specific NotFoundError: {e}\")\nexcept APIError as e:\n    print(f\"Caught generic APIError: {e}\")\n\n","lang":"python","description":"This quickstart demonstrates how to set up a basic API client using `APISession` and organize API calls with `APIEndpoint`. It includes an example of handling API keys and specific HTTP status code errors.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-17","installed_version":"1.5.1","pypi_latest":"1.5.1","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":2.7,"avg_import_s":0.71,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"restfly","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.65,"mem_mb":13,"disk_size":"26.2M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"restfly","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.9,"import_time_s":0.46,"mem_mb":13,"disk_size":"44M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"restfly","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.89,"mem_mb":14.5,"disk_size":"28.6M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"restfly","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.8,"import_time_s":0.79,"mem_mb":14.5,"disk_size":"47M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"restfly","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.79,"mem_mb":14.2,"disk_size":"20.3M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"restfly","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.5,"import_time_s":0.77,"mem_mb":14.2,"disk_size":"39M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"restfly","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.73,"mem_mb":15.1,"disk_size":"20.1M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"restfly","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":2.5,"import_time_s":0.74,"mem_mb":15.1,"disk_size":"39M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"restfly","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":null,"import_time_s":0.67,"mem_mb":12.7,"disk_size":"25.5M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"restfly","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"clean","install_time_s":3,"import_time_s":0.56,"mem_mb":12.7,"disk_size":"26M"}]}}