{"id":17657749,"url":"https://github.com/livioribeiro/asgikit","last_synced_at":"2025-05-07T10:10:42.413Z","repository":{"id":37541186,"uuid":"401524748","full_name":"livioribeiro/asgikit","owner":"livioribeiro","description":"ASGI Toolkit","archived":false,"fork":false,"pushed_at":"2025-02-15T16:43:17.000Z","size":191,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-19T20:54:15.531Z","etag":null,"topics":["asgi","asyncio","python","toolkit","web"],"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/livioribeiro.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}},"created_at":"2021-08-31T00:33:06.000Z","updated_at":"2025-02-15T16:39:11.000Z","dependencies_parsed_at":"2022-07-12T16:22:06.849Z","dependency_job_id":"56d48354-8e00-4a06-b4b8-131077df0dea","html_url":"https://github.com/livioribeiro/asgikit","commit_stats":null,"previous_names":[],"tags_count":27,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livioribeiro%2Fasgikit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livioribeiro%2Fasgikit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livioribeiro%2Fasgikit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/livioribeiro%2Fasgikit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/livioribeiro","download_url":"https://codeload.github.com/livioribeiro/asgikit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252856555,"owners_count":21814858,"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":["asgi","asyncio","python","toolkit","web"],"created_at":"2024-10-23T14:43:20.559Z","updated_at":"2025-05-07T10:10:42.356Z","avatar_url":"https://github.com/livioribeiro.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Asgikit - ASGI Toolkit\n\nAsgikit is a toolkit for building asgi applications and frameworks.\n\nIt is intended to be a minimal library and provide the building blocks for other libraries.\n\nThe [examples directory](./examples) contain usage examples of several use cases\n\n## Features:\n\n- Request\n  - Headers\n  - Cookies\n  - Body (bytes, str, json, stream)\n  - Form\n- Response\n  - Plain text\n  - Json\n  - Streaming\n  - File\n- Websockets\n\n## Request and Response\n\nAsgikit `Request` and `Response` were designed to be have minimal interfaces,\nso they only provide very few methods to read from the request and write to the response.\nIn particular, the `Response` works differently from most tools, in which you do not\nreturn a response, but you write data into it.\n\nIt is provided several functions to interact with the request and the response, for instance,\nto read form data from the request and write json to the response.\n\nThis strategy allows for simpler extensibility. For example, to parse json from the request\nusing an alternative json parser, you just need to write a function that reads the request.\nSimilarly, to write another data format into the response, you just write a function that\nwrites to the response.\n\n## Custom JSON encoder and decoder\n\nBy default, asgikit uses `json.dumps` and `json.loads` for dealing with JSON. If\nyou want to use other libraries like `orjson`, just define the environment variable\n`ASGIKIT_JSON_ENCODER` of the module compatible with `json`, or the full path to\nthe functions that perform encoding and decoding, in that order:\n\n```dotenv\nASGIKIT_JSON_ENCODER=orjson\n# or\nASGIKIT_JSON_ENCODER=msgspc.json.encode,msgspc.json.encode\n```\n\n## Example request and response\n\n```python\nfrom asgikit.requests import Request, read_json\nfrom asgikit.responses import respond_json\n\n\nasync def main(scope, receive, send):\n    request = Request(scope, receive, send)\n  \n    # request method\n    method = request.method\n  \n    # request path\n    path = request.path\n  \n    # request headers\n    headers = request.headers\n  \n    # read body as json\n    body_json = await read_json(request)\n  \n    data = {\n        \"lang\": \"Python\",\n        \"async\": True,\n        \"platform\": \"asgi\",\n        \"method\": method,\n        \"path\": path,\n        \"headers\": dict(headers.items()),\n        \"body\": body_json,\n    }\n  \n    # send json response\n    await respond_json(request.response, data)\n```\n\n## Example websocket\n\n```python\nfrom asgikit.requests import Request\nfrom asgikit.errors.websocket import WebSocketDisconnectError\n\n\nasync def app(scope, receive, send):\n    request = Request(scope, receive, send)\n    ws = request.websocket\n    await ws.accept()\n\n    while True:\n        try:\n            message = await ws.receive()\n            await ws.send(message)\n        except WebSocketDisconnectError:\n            print(\"Client disconnect\")\n            break\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flivioribeiro%2Fasgikit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flivioribeiro%2Fasgikit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flivioribeiro%2Fasgikit/lists"}