{"id":27603526,"url":"https://github.com/taskiq-python/taskiq-aiohttp","last_synced_at":"2025-04-22T19:17:16.229Z","repository":{"id":157383450,"uuid":"631407142","full_name":"taskiq-python/taskiq-aiohttp","owner":"taskiq-python","description":"Integration with AioHTTP framework","archived":false,"fork":false,"pushed_at":"2023-11-30T11:38:09.000Z","size":179,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2025-04-10T07:09:23.967Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/taskiq-python.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}},"created_at":"2023-04-22T23:32:46.000Z","updated_at":"2023-04-22T23:36:55.000Z","dependencies_parsed_at":"2023-12-02T11:47:17.104Z","dependency_job_id":null,"html_url":"https://github.com/taskiq-python/taskiq-aiohttp","commit_stats":{"total_commits":17,"total_committers":1,"mean_commits":17.0,"dds":0.0,"last_synced_commit":"72526997d50f4706832d823eb1e3d796ef81a4f9"},"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taskiq-python%2Ftaskiq-aiohttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taskiq-python%2Ftaskiq-aiohttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taskiq-python%2Ftaskiq-aiohttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/taskiq-python%2Ftaskiq-aiohttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/taskiq-python","download_url":"https://codeload.github.com/taskiq-python/taskiq-aiohttp/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249981844,"owners_count":21355579,"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":"2025-04-22T19:17:15.540Z","updated_at":"2025-04-22T19:17:16.218Z","avatar_url":"https://github.com/taskiq-python.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Taskiq + AioHTTP\n\nThis project is used to create mocked application and request\nthat you can use as a dependencies in your taskiq application.\n\n\nIt's useful because it runs all startup events of your application\nand everything that you might expect in your application's state is\navailable inside of your tasks.\n\nWe suggest to use this library along with [taskiq-python/aiohttp-deps](https://github.com/taskiq-python/aiohttp-deps), because it might be super handy to reuse same dependencies of your application in your tasks.\n\nTo add an integration, you need to call the function `init` in your broker's module.\n\n```python\nimport taskiq_aiohttp\n\nbroker = ...\n\ntaskiq_aiohttp.init(broker, \"project.module:app\")\n\n```\n\n## How does it work?\n\nIt adds startup functions to the broker, so it imports your aiohttp application and creates a single worker-wide Request and Application objects that you can depend on.\n\nTHIS REQUEST IS NOT RELATED TO THE ACTUAL REQUESTS IN AioHTTP! This request won't have actual data about the request you were handling while sending a task.\n\n\n## Manual context updates\n\nSometimes it's required to update context manually. For example, for tests.\nIf you need to add context in your broker by hand, please use function populate_context.\n\nImagine, you want to use InMemoryBroker for testing and your broker file looks like this:\n\n```python\nbroker = MyBroker()\n\nif env == \"pytest\":\n    broker = InMemoryBroker()\n```\n\nIn this case your context won't be updated, because inmemory brokers cannot run as workers.\nTo solve this issue, we have a populate context function. It's a bit complex and takes lots of\nparmeters. But here's a fixture that creates aiohttp test client and populates context of inmemory broker.\n\n```python\nimport asyncio\nfrom typing import AsyncGenerator\n\nimport pytest\nfrom aiohttp import web\nfrom aiohttp.test_utils import BaseTestServer, TestClient, TestServer\nfrom taskiq_aiohttp import populate_context\n\n\n@pytest.fixture\nasync def test_client(\n    app: web.Application,\n) -\u003e AsyncGenerator[TestClient, None]:\n    \"\"\"\n    Create a test client.\n\n    This function creates a TestServer\n    and a test client for the application.\n\n    Also this fixture populates context\n    with needed variables.\n\n    :param app: current application.\n    :yield: ready to use client.\n    \"\"\"\n    loop = asyncio.get_running_loop()\n    server = TestServer(app)\n    client = TestClient(server, loop=loop)\n\n    await client.start_server()\n\n    # This is important part.\n    # Since InMemoryBroker doesn't\n    # run in worker_process, we have to populate\n    # broker's context manually.\n    populate_context(\n        broker=broker,\n        server=server.runner.server,\n        app=app,\n        loop=None,\n    )\n\n    yield client\n\n    await client.close()\n\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaskiq-python%2Ftaskiq-aiohttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftaskiq-python%2Ftaskiq-aiohttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftaskiq-python%2Ftaskiq-aiohttp/lists"}