{"id":17291038,"url":"https://github.com/decorator-factory/yalambda","last_synced_at":"2025-04-14T11:51:43.825Z","repository":{"id":57477995,"uuid":"414626395","full_name":"decorator-factory/yalambda","owner":"decorator-factory","description":"Yandex.Cloud Functions toolkit","archived":false,"fork":false,"pushed_at":"2021-12-06T23:17:41.000Z","size":35,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T07:07:08.449Z","etag":null,"topics":["asyncio","python","serverless-functions","yandex-cloud-functions"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/yalambda","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/decorator-factory.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":"2021-10-07T14:06:53.000Z","updated_at":"2024-03-28T10:10:12.000Z","dependencies_parsed_at":"2022-09-10T04:23:58.139Z","dependency_job_id":null,"html_url":"https://github.com/decorator-factory/yalambda","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/decorator-factory%2Fyalambda","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decorator-factory%2Fyalambda/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decorator-factory%2Fyalambda/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/decorator-factory%2Fyalambda/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/decorator-factory","download_url":"https://codeload.github.com/decorator-factory/yalambda/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248877986,"owners_count":21176239,"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":["asyncio","python","serverless-functions","yandex-cloud-functions"],"created_at":"2024-10-15T10:39:41.037Z","updated_at":"2025-04-14T11:51:43.619Z","avatar_url":"https://github.com/decorator-factory.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# `yalambda`\n\nYalambda lets you write Yanex.Cloud Functions with less boilerplate\n\nFeatures:\n- everything is type-annotated, so you'll get autocompletion in IDEs\n- base64 de/encoding and other details are handled for you\n- automatically parse JSON using `dataclass-factory`\n\n\n# Echo server example\n\n```py\nfrom yalambda import function, YaRequest, YaResponse\n\n\n@function()\nasync def handler(req: YaRequest) -\u003e YaResponse:\n    return YaResponse(200, req.body)\n```\n\n\n# Automatically parse dataclasses\n```py\nfrom dataclasses import dataclass\nfrom yalambda import function, YaResponse\n\n\n@dataclass\nclass Point:\n    x: float\n    y: float\n\n\n@function()\nasync def handler(point: Point) -\u003e YaResponse:\n    dist = (point.x**2 + point.y**2)**0.5\n    return YaResponse(200, {\"distance_to_origin\": dist})\n```\n\n\n# Access both the dataclass and the request\n\n```py\nfrom dataclasses import dataclass\nfrom yalambda import function, YaRequest, YaResponse\n\n\n@dataclass\nclass Point:\n    x: float\n    y: float\n\n\n@function()\nasync def handler(point: Point, req: YaRequest) -\u003e YaResponse:\n    if req.http_method != \"POST\":\n        return YaResponse(405, \"Only POST requests are allowed\")\n\n    dist = (point.x**2 + point.y**2)**0.5\n    return YaResponse(200, {\"distance_to_origin\": dist})\n```\n\n\n# Initialize something asynchronously on first call\n\n```py\nfrom yalambda import function, YaRequest, YaResponse\n\n\nasync def init():\n    global answer\n    answer = 42\n\n\n@function(init)\nasync def handler(req: YaRequest) -\u003e YaResponse:\n    return YaResponse(200, \"Answer: {}\".format(answer))\n```\n\n\n# Routing\n\n```py\nfrom dataclasses import dataclass\nfrom yalambda import dispatch, YaRequest, YaResponse\n\n\n@dataclass\nclass Point:\n    x: float\n    y: float\n\n\nasync def get_all_points(req: YaRequest) -\u003e YaResponse:\n    points = [{\"x\": 3.0, \"y\": 4.0}, {\"x\": -1.0, \"y\": 3.27}]\n    return YaResponse(200, points)\n\n\nasync def compute_distance(point: Point) -\u003e YaResponse:\n    dist = (point.x**2 + point.y**2)**0.5\n    return YaResponse(200, {\"distance_to_origin\": dist})\n\n\nhandler = dispatch({\n    \"GET\": get_all_points,\n    \"POST\": compute_distance,\n})\n```\n\n\n# Full example\n\nThis function acts as a GitHub webhook and sends a pretty embed on Discord webhook when an issue is opened or closed. See the source code [on GitHub](https://github.com/decorator-factory/yalambda/tree/master/examples/github-to-discord-webhook).\n\n![Screenshot from Discord showing two embeds](https://imgur.com/Kuoy0XE.png)\n\n\n# Development server\n\nYou can install `aiohttp` and run your function locally.\nIt's not the same as the real thing, but it should be enough for simple functions.\n\n```bash\n$ python -m yalambda your_module\n======== Running on http://0.0.0.0:55710 ========\n(Press CTRL+C to quit)\n```\n\n\n# Condition DSL\n\nWe can modify our GitHub-\u003eDiscord example so that it doesn't error out on the initial ping event:\n\n```py\nfrom yalambda import when\n\n...\n\nasync def handle_issue_events(event: IssueEvent) -\u003e YaResponse:\n    embed = create_embed(event)\n    if embed is not None:\n        await client.post(DISCORD_WEBHOOK, json={\"embeds\": [embed]})\n    return YaResponse(200, \"\")\n\n\nasync def handle_ping(req: YaRequest) -\u003e YaResponse:\n    return YaResponse(200, \"\")\n\n\nhandler = when.dispatch(\n    when.header_is(\"x-github-event\", \"ping\", handle_ping),\n    when.header_is(\"x-github-event\", \"issues\", handle_issue_events),\n    init=init\n)\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdecorator-factory%2Fyalambda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdecorator-factory%2Fyalambda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdecorator-factory%2Fyalambda/lists"}