{"id":13494927,"url":"https://github.com/MagicStack/httptools","last_synced_at":"2025-03-28T15:32:12.626Z","repository":{"id":43705552,"uuid":"57056922","full_name":"MagicStack/httptools","owner":"MagicStack","description":"Fast HTTP parser","archived":false,"fork":false,"pushed_at":"2024-10-16T20:34:08.000Z","size":126,"stargazers_count":1203,"open_issues_count":12,"forks_count":83,"subscribers_count":39,"default_branch":"master","last_synced_at":"2024-10-29T15:01:23.900Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MagicStack.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-25T16:13:48.000Z","updated_at":"2024-10-20T09:40:09.000Z","dependencies_parsed_at":"2024-06-18T12:16:51.132Z","dependency_job_id":"ed4c178d-95df-4aaa-b89c-71c763d777bf","html_url":"https://github.com/MagicStack/httptools","commit_stats":{"total_commits":84,"total_committers":14,"mean_commits":6.0,"dds":"0.48809523809523814","last_synced_commit":"7b1b43b4790558ff39a3dd81b72a3793091bcd49"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MagicStack%2Fhttptools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MagicStack%2Fhttptools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MagicStack%2Fhttptools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MagicStack%2Fhttptools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MagicStack","download_url":"https://codeload.github.com/MagicStack/httptools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222090770,"owners_count":16929471,"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":[],"created_at":"2024-07-31T19:01:29.534Z","updated_at":"2024-10-31T09:31:36.327Z","avatar_url":"https://github.com/MagicStack.png","language":"Python","readme":"![Tests](https://github.com/MagicStack/httptools/workflows/Tests/badge.svg)\n\nhttptools is a Python binding for the nodejs HTTP parser.\n\nThe package is available on PyPI: `pip install httptools`.\n\n\n# APIs\n\nhttptools contains two classes `httptools.HttpRequestParser`,\n`httptools.HttpResponseParser` (fulfilled through\n[llhttp](https://github.com/nodejs/llhttp)) and a function for\nparsing URLs `httptools.parse_url` (through\n[http-parse](https://github.com/nodejs/http-parser) for now).\nSee unittests for examples.\n\n\n```python\n\nclass HttpRequestParser:\n\n    def __init__(self, protocol):\n        \"\"\"HttpRequestParser\n\n        protocol -- a Python object with the following methods\n        (all optional):\n\n          - on_message_begin()\n          - on_url(url: bytes)\n          - on_header(name: bytes, value: bytes)\n          - on_headers_complete()\n          - on_body(body: bytes)\n          - on_message_complete()\n          - on_chunk_header()\n          - on_chunk_complete()\n          - on_status(status: bytes)\n        \"\"\"\n\n    def get_http_version(self) -\u003e str:\n        \"\"\"Return an HTTP protocol version.\"\"\"\n\n    def should_keep_alive(self) -\u003e bool:\n        \"\"\"Return ``True`` if keep-alive mode is preferred.\"\"\"\n\n    def should_upgrade(self) -\u003e bool:\n        \"\"\"Return ``True`` if the parsed request is a valid Upgrade request.\n\tThe method exposes a flag set just before on_headers_complete.\n\tCalling this method earlier will only yield `False`.\n\t\"\"\"\n\n    def feed_data(self, data: bytes):\n        \"\"\"Feed data to the parser.\n\n        Will eventually trigger callbacks on the ``protocol``\n        object.\n\n        On HTTP upgrade, this method will raise an\n        ``HttpParserUpgrade`` exception, with its sole argument\n        set to the offset of the non-HTTP data in ``data``.\n        \"\"\"\n\n    def get_method(self) -\u003e bytes:\n        \"\"\"Return HTTP request method (GET, HEAD, etc)\"\"\"\n\n\nclass HttpResponseParser:\n\n    \"\"\"Has all methods except ``get_method()`` that\n    HttpRequestParser has.\"\"\"\n\n    def get_status_code(self) -\u003e int:\n        \"\"\"Return the status code of the HTTP response\"\"\"\n\n\ndef parse_url(url: bytes):\n    \"\"\"Parse URL strings into a structured Python object.\n\n    Returns an instance of ``httptools.URL`` class with the\n    following attributes:\n\n      - schema: bytes\n      - host: bytes\n      - port: int\n      - path: bytes\n      - query: bytes\n      - fragment: bytes\n      - userinfo: bytes\n    \"\"\"\n```\n\n\n# Development\n\n1. Clone this repository with\n   `git clone --recursive git@github.com:MagicStack/httptools.git`\n\n2. Create a virtual environment with Python 3:\n   `python3 -m venv envname`\n\n3. Activate the environment with `source envname/bin/activate`\n\n4. Install development requirements with `pip install -e .[test]`\n\n5. Run `make` and `make test`.\n\n\n# License\n\nMIT.\n","funding_links":[],"categories":["Python","HTTP Clients"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMagicStack%2Fhttptools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FMagicStack%2Fhttptools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FMagicStack%2Fhttptools/lists"}