{"id":20550569,"url":"https://github.com/manmolecular/py-request-interceptor","last_synced_at":"2025-04-14T11:18:02.617Z","repository":{"id":48523257,"uuid":"276651289","full_name":"manmolecular/py-request-interceptor","owner":"manmolecular","description":":rat: Intercepts your HTTP(S) requests from Python standard library. Allows to redirect, sniff, and modify requests transparently.","archived":false,"fork":false,"pushed_at":"2021-07-21T18:11:09.000Z","size":21,"stargazers_count":13,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-14T11:17:50.277Z","etag":null,"topics":["dirty-patching","http-client","monkey-patching","patch","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/manmolecular.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-07-02T13:18:13.000Z","updated_at":"2025-04-06T05:56:43.000Z","dependencies_parsed_at":"2022-08-31T16:11:14.737Z","dependency_job_id":null,"html_url":"https://github.com/manmolecular/py-request-interceptor","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manmolecular%2Fpy-request-interceptor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manmolecular%2Fpy-request-interceptor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manmolecular%2Fpy-request-interceptor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/manmolecular%2Fpy-request-interceptor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/manmolecular","download_url":"https://codeload.github.com/manmolecular/py-request-interceptor/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248868766,"owners_count":21174758,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dirty-patching","http-client","monkey-patching","patch","python"],"created_at":"2024-11-16T02:25:37.488Z","updated_at":"2025-04-14T11:18:02.597Z","avatar_url":"https://github.com/manmolecular.png","language":"Python","readme":"# py-request-interceptor\n[![Python3 Version](https://img.shields.io/badge/python-3.6%20%28%3F%29%20%7C%203.7%2B-blue)](https://www.python.org/downloads/)\n[![License](https://img.shields.io/badge/license-GPL--3.0-blue)](/LICENSE)\n[![Code Style](https://img.shields.io/badge/code%20style-black-000000)](https://github.com/psf/black)  \n## Description\n:rat: Intercepts your HTTP(S) requests from Python standard libraries. Allows you to catch API calls and HTTP(S) requests from different `requests`/`urllib`/`http`-based libraries (and many others based on the original `http.client`/`socket` stack).\n\n## Warning\n:construction: **Note:** This is just a WIP/PoC project w/o rocket science in it - just a bunch of dirty monkey patches. So, enjoy it \"as is\" if you are interested in it. Not properly tested lol.\n\n## Proof of Concept\n```python3\n#!/usr/bin/env python3\n\nfrom src.interceptor import Interceptor\nfrom requests import get\n\n# Initialize 'Interceptor' here, nothing special\nintercept = Interceptor()\n\n@intercept.sniff(listener=\"http://YOUR_LISTENER_ENDPOINT\")\n@intercept.dump()\n@intercept.data(data=\"GET / HTTP/1.1\\r\\n ...modified request goes here\")\ndef example_sniff_connect() -\u003e CaseInsensitiveDict:\n    \"\"\"\n    Patch request data, dump modified request to the logs, and re-send copy of the request\n    to another endpoint\n    :return: response headers\n    \"\"\"\n    return get(url=\"http://ORIGINAL_HOST\").headers\n\n\nif __name__ == \"__main__\":\n    example_sniff_connect()\n```\n\n## Handlers\n### Redirect to another target\nDefinition:  \n```python3\ndef target(self, host: str, port: int) -\u003e callable:\n```\nExample:\n```python3\nintercept = Interceptor()\n\n@intercept.target(host=\"http://evil.com\", port=80)\ndef my_func():\n    ...\n```\n### Replace raw requests data\nDefinition:  \n```python3\ndef data(self, data: Union[str, bytes]) -\u003e callable:\n```\nExample:\n```python3\nintercept = Interceptor()\n\n@intercept.data(data=\"GET / HTTP/1.1\\r\\n...\")\ndef my_func():\n    ...\n```\n### Log raw requests to the console \nDefinition:  \n```python3\ndef dump(self) -\u003e callable:\n```\nExample:\n```python3\nintercept = Interceptor()\n\n@intercept.dump()\ndef my_func():\n    ...\n```\n### Re-send copy of the original raw requests to another endpoint\nDefinition:  \n```python3\ndef sniff(self, listener: str) -\u003e callable:\n```\nExample:\n```python3\nintercept = Interceptor()\n\n@intercept.sniff(listener=\"http://requestbin.net/r/YOUR_REQUESTBIN_ID\")\ndef my_func():\n    ...\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanmolecular%2Fpy-request-interceptor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmanmolecular%2Fpy-request-interceptor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmanmolecular%2Fpy-request-interceptor/lists"}