{"id":34045504,"url":"https://github.com/nggit/netizen","last_synced_at":"2026-04-01T19:18:50.216Z","repository":{"id":323839419,"uuid":"895377896","full_name":"nggit/netizen","owner":"nggit","description":"A manual HTTP client for testing.","archived":false,"fork":false,"pushed_at":"2026-01-31T03:01:50.000Z","size":50,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-28T00:58:08.266Z","etag":null,"topics":["asyncio","http-client","httpx","python","python3","requests"],"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/nggit.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-11-28T05:11:05.000Z","updated_at":"2026-01-31T03:01:54.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/nggit/netizen","commit_stats":null,"previous_names":["nggit/netizen"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/nggit/netizen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nggit%2Fnetizen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nggit%2Fnetizen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nggit%2Fnetizen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nggit%2Fnetizen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nggit","download_url":"https://codeload.github.com/nggit/netizen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nggit%2Fnetizen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31291117,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-01T13:12:26.723Z","status":"ssl_error","status_checked_at":"2026-04-01T13:12:25.102Z","response_time":53,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["asyncio","http-client","httpx","python","python3","requests"],"created_at":"2025-12-13T23:11:57.104Z","updated_at":"2026-04-01T19:18:50.209Z","avatar_url":"https://github.com/nggit.png","language":"Python","readme":"# Netizen\nNetizen is a minimalist HTTP client with a symmetrical interface between async\nand sync modes.\nIt doesn't aim to be feature-complete like *requests* or *httpx*.\n\nNetizen is just enough for poking API endpoints and performing basic HTTP\noperations or testing. It suits me, as I prefer working closely with sockets\nand don't need high-level abstraction.\n\n## Features\n* Symmetrical interface, e.g. `client.send()` vs `await client.send()`\n* The [retries](#timeout-and-retries-parameters) parameter makes it resilient and prevents flaky tests\n* ~500 lines of code\n* No dependencies other than the [Python Standard Library](https://docs.python.org/3/library/index.html)\n\n## Installation\n```\npip install git+https://github.com/nggit/netizen.git\n```\n\n## `timeout` and `retries` parameters\nThese two are related, but what you probably want to know is how retries work.\n\nBasically, here is the flow of an HTTP request:\n1. Connect to the `host` and `port`\n2. Send the request header and (optionally) the body\n3. Receive the response header\n4. Stream the body if necessary\n\nNetizen only guarantees retries until the 3rd stage is successful.\n\nRetries in stage 1 are useful for waiting for the server to be ready to accept\nconnections.\nThis is suitable for testing without having to worry about sequence or timing.\n\n`retries` depends on `timeout` to determine the interval value:\n```\ninterval = timeout / retries\n```\n\n## Handling a JSON response body\n```python\nimport asyncio\n\nfrom netizen import HTTPClient\n\n\n# sync\nwith HTTPClient('ip-api.com', 80) as client:\n    response = client.send(b'GET /json HTTP/1.1')\n\n    print(response.json())\n\n# async\nasync def main():\n    async with HTTPClient('ip-api.com', 80) as client:\n        response = await client.send(b'GET /json HTTP/1.1')\n\n        print(await response.json())\n\nasyncio.run(main())\n```\n\n## Handling a raw response body with streaming\n```python\nimport asyncio\n\nfrom netizen import HTTPClient\n\nclient = HTTPClient('example.com', 80)\n\n\n# sync\nwith client:\n    response = client.send(b'GET / HTTP/1.1')\n\n    for data in response:\n        print('Received:', len(data), 'Bytes')\n\n# async\nasync def main():\n    async with client:\n        response = await client.send(b'GET / HTTP/1.1')\n\n        async for data in response:\n            print('Received:', len(data), 'Bytes')\n\nasyncio.run(main())\n```\n\n## Append request headers via `*args` also `body` parameter\n```python\nwith HTTPClient('example.com', 80) as client:\n    response = client.send(\n        b'POST / HTTP/1.1',\n        b'Content-Type: application/json',\n        b'Content-Length: 14',\n        body=b'{\"foo\": \"bar\"}'\n    )\n\n    print('Status code:', response.status)  # 403\n    print('Reason phrase:', response.message)  # b'Forbidden'\n\n# out of context, close the connection without reading the entire response body\n```\n\nIf you don't specify any headers, then `Content-Length` will be automatically\ninserted along with `Content-Type: application/x-www-form-urlencoded`.\n\n```python\nwith HTTPClient('example.com', 80) as client:\n    response = client.send(b'POST / HTTP/1.1', body=b'foo=bar')\n\n```\n\n## Send multiple requests within the same context/connection\n```python\nwith HTTPClient('ip-api.com', 80) as client:\n    # first request\n    response = client.send(b'GET /json HTTP/1.1')\n\n    # the first response body must be consumed before sending another one\n    print(response.json())\n\n    # second request\n    response = client.send(b'GET /json HTTP/1.1')\n\n    print(response.body())\n```\n\n## Handling URL redirects\n```python\nfrom urllib.parse import urlparse\n\n\nwith HTTPClient('google.com', 443, ssl=True) as client:\n    response = client.send(b'GET / HTTP/1.1')\n\n    print('1. Status code:', response.status)  # 301\n    print('1. Reason phrase:', response.message)  # b'Moved Permanently'\n    print('1. Location:', response.url)  # b'http://www.google.com/'\n\n    for data in response:\n        pass\n\n    if response.url:\n        url = urlparse(response.url)\n\n        if url.netloc:  # b'www.google.com' (different host)\n            with HTTPClient(url.netloc.decode(), 443, ssl=True) as client:\n                response = client.send(b'GET %s HTTP/1.1' % url.path)\n\n                print('2. Status code:', response.status)  # 200\n                print('2. Reason phrase:', response.message)  # b'OK'\n\n                for data in response:\n                    pass\n        else:\n            pass\n```\n\n## Working directly with socket using `client.sendall()` and `client.recv()`\n```python\nwith HTTPClient('localhost', 8000, timeout=10, retries=10) as client:\n    response = client.send(\n        b'GET /chat HTTP/1.1',\n        b'Upgrade: WebSocket',\n        b'Connection: Upgrade',\n        b'Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==',\n        b'Sec-WebSocket-Version: 13'\n    )\n\n    if response.status == 101:\n        client.sendall(b'\\x81\\x0dHello, World!\\x88\\x02\\x03\\xe8')\n        print('Received:', client.recv(4096))\n```\n\n## Manually craft a bad request with `client.sendall()` and `client.end()`\n```python\nwith HTTPClient('localhost', 8000) as client:\n    client.sendall(\n        b'POST /upload HTTP/1.1\\r\\n'\n        b'Host: localhost\\r\\n'\n        b'Content-Length: 5\\r\\n'\n        b'Transfer-Encoding: chunked\\r\\n\\r\\n'\n    )\n    client.sendall(b'0\\r\\n\\r\\n')\n\n    # we are not using the `client.send()`, but we need the response object?\n    response = client.end()\n\n    print(response.body())\n```\n\n## License\nMIT License\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnggit%2Fnetizen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnggit%2Fnetizen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnggit%2Fnetizen/lists"}