{"id":20812541,"url":"https://github.com/superstreamlabs/memphis-functions.py","last_synced_at":"2026-04-26T07:35:18.629Z","repository":{"id":208783695,"uuid":"722440957","full_name":"superstreamlabs/memphis-functions.py","owner":"superstreamlabs","description":null,"archived":false,"fork":false,"pushed_at":"2024-01-21T18:39:07.000Z","size":36,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2026-02-23T07:22:52.385Z","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":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/superstreamlabs.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":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-23T06:44:32.000Z","updated_at":"2023-11-23T07:25:22.000Z","dependencies_parsed_at":"2023-11-26T17:25:37.905Z","dependency_job_id":"2f59b4d9-f121-4560-9628-dfcb94ba123c","html_url":"https://github.com/superstreamlabs/memphis-functions.py","commit_stats":null,"previous_names":["memphisdev/memphis-functions.py","superstreamlabs/memphis-functions.py"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/superstreamlabs/memphis-functions.py","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superstreamlabs%2Fmemphis-functions.py","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superstreamlabs%2Fmemphis-functions.py/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superstreamlabs%2Fmemphis-functions.py/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superstreamlabs%2Fmemphis-functions.py/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/superstreamlabs","download_url":"https://codeload.github.com/superstreamlabs/memphis-functions.py/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/superstreamlabs%2Fmemphis-functions.py/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32289926,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-26T06:26:00.361Z","status":"ssl_error","status_checked_at":"2026-04-26T06:25:58.791Z","response_time":129,"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":[],"created_at":"2024-11-17T20:55:22.887Z","updated_at":"2026-04-26T07:35:18.595Z","avatar_url":"https://github.com/superstreamlabs.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Github (6)](https://github.com/memphisdev/memphis/assets/107035359/bc2feafc-946c-4569-ab8d-836bc0181890)](https://www.functions.memphis.dev/)\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://memphis.dev/discord\"\u003e\u003cimg src=\"https://img.shields.io/discord/963333392844328961?color=6557ff\u0026label=discord\" alt=\"Discord\"\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/memphisdev/memphis/issues?q=is%3Aissue+is%3Aclosed\"\u003e\u003cimg src=\"https://img.shields.io/github/issues-closed/memphisdev/memphis?color=6557ff\"\u003e\u003c/a\u003e \n  \u003cimg src=\"https://img.shields.io/npm/dw/memphis-dev?color=ffc633\u0026label=installations\"\u003e\n\u003ca href=\"https://github.com/memphisdev/memphis/blob/master/CODE_OF_CONDUCT.md\"\u003e\u003cimg src=\"https://img.shields.io/badge/Code%20of%20Conduct-v1.0-ff69b4.svg?color=ffc633\" alt=\"Code Of Conduct\"\u003e\u003c/a\u003e \n\u003cimg alt=\"GitHub release (latest by date)\" src=\"https://img.shields.io/github/v/release/memphisdev/memphis?color=61dfc6\"\u003e\n\u003cimg src=\"https://img.shields.io/github/last-commit/memphisdev/memphis?color=61dfc6\u0026label=last%20commit\"\u003e\n\u003c/p\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \n\u003cimg width=\"177\" alt=\"cloud_native 2 (5)\" src=\"https://github.com/memphisdev/memphis/assets/107035359/a20ea11c-d509-42bb-a46c-e388c8424101\"\u003e\n  \n\u003c/div\u003e\n \n \u003cb\u003e\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://memphis.dev/pricing/\"\u003eCloud\u003c/a\u003e - \u003ca href=\"https://memphis.dev/docs/\"\u003eDocs\u003c/a\u003e - \u003ca href=\"https://twitter.com/Memphis_Dev\"\u003eX\u003c/a\u003e - \u003ca href=\"https://www.youtube.com/channel/UCVdMDLCSxXOqtgrBaRUHKKg\"\u003eYouTube\u003c/a\u003e\n\u003c/p\u003e\u003c/b\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n  \u003ch4\u003e\n\n**[Memphis.dev](https://memphis.dev)** is more than a broker. It's a new streaming stack.\u003cbr\u003e\nMemphis.dev is a highly scalable event streaming and processing engine.\u003cbr\u003e\n\n  \u003c/h4\u003e\n  \n\u003c/div\u003e\n\n## ![20](https://user-images.githubusercontent.com/70286779/220196529-abb958d2-5c58-4c33-b5e0-40f5446515ad.png) About\n\nBefore Memphis came along, handling ingestion and processing of events on a large scale took months to adopt and was a capability reserved for the top 20% of mega-companies. Now, Memphis opens the door for the other 80% to unleash their event and data streaming superpowers quickly, easily, and with great cost-effectiveness.\n\n**This repository is responsible for the Memphis Functions Python SDK**\n\n## Installation\n\n```sh\n$ pip3 install memphis-functions\n```\n\n## Importing\n\n```python\nfrom memphis import create_function\n```\n\n### Creating a Memphis function\nMemphis provides a create_function utility for more easily creatin Memphis Functions.\n\nThe user created `event_handler` will be called for every message in the given batch of events. The user's `event_handler` will take in a `msg_payload` as bytes, `msg_headers` as a dict and `inputs` as a dict, and should return a modified version of the payload and headers in the same data types.\n\nThe user function should raise an exception if the message processing has failed. If any exception is raised (deliberately or by a failed operation) the message will be sent to the dead letter station.\n\nIf the returned modified version of the `msg_payload` or `msg_headers` are returned as `None`, then the message will be skipped and will not be sent to the station or dead letter station.\n\n\u003e Make sure to encode the modified `msg_payload` bytes object with utf-8 encoding!\n\nThis example function takes the bytes object `msg_payload` and encodes it into a string so that it may be parsed as JSON.  \n\n```python\nimport json\nimport base64\nfrom memphis import create_function\n\ndef handler(event, context): # The name of this file and this function should match the handler field in the memphis.yaml file in the following format \u003cfile name\u003e.\u003cfunction name\u003e\n    return create_function(event, event_handler = event_handler)\n\ndef event_handler(msg_payload, msg_headers, inputs):\n    payload =  str(msg_payload, 'utf-8')\n    as_json = json.loads(payload)\n    as_json['modified'] = True\n\n    return bytes(json.dumps(as_json), encoding='utf-8'), msg_headers\n```\n\nInstead of taking `msg_payload` as a bytes object, the as_dict flag can be used to have the JSON parsed to a dictionary.\n\n```python\nimport json\nimport base64\nfrom memphis import create_function\n\ndef handler(event, context): # The name of this file and this function should match the handler field in the memphis.yaml file in the following format \u003cfile name\u003e.\u003cfunction name\u003e\n    return create_function(event, event_handler = event_handler, as_dict=True)\n\ndef event_handler(msg_payload, msg_headers, inputs):\n    msg_payload['modified'] = True\n\n    return msg_payload, msg_headers\n```\n\nMemphis Functions support using Async functions through asyncio. When functions are async, set the use_async parameter to true.\n```python\nimport json\nimport base64\nimport asyncio\nfrom memphis import create_function\n\ndef handler(event, context): # The name of this file and this function should match the handler field in the memphis.yaml file in the following format \u003cfile name\u003e.\u003cfunction name\u003e\n    return create_function(event, event_handler = event_handler, use_async = True)\n\nasync def event_handler(msg_payload, msg_headers, inputs):\n    payload =  str(msg_payload, 'utf-8')\n    as_json = json.loads(payload)\n    as_json['modified'] = True\n    asyncio.sleep(1)\n\n    return bytes(json.dumps(as_json), encoding='utf-8'), msg_headers\n```\n\nIf the user would want to have a message that they would want to validate and send to the dead letter station if the validation fails then the user can raise an exception. In the following example, the field `check` is simply a boolean. The following function will send any messages which fail the `check` to the dead letter station.\n\n```python\nimport json\nimport base64\nfrom memphis import create_function\n\ndef handler(event, context): # The name of this file and this function should match the handler field in the memphis.yaml file in the following format \u003cfile name\u003e.\u003cfunction name\u003e\n    return create_function(event, event_handler = event_handler)\n\ndef event_handler(msg_payload, msg_headers, inputs):\n    payload =  str(msg_payload, 'utf-8')\n    as_json = json.loads(payload)\n    if as_json['check'] == False:\n        raise Exception(\"Validation Failed!\")\n\n    return bytes(json.dumps(as_json), encoding='utf-8'), msg_headers\n```\n\nIf a user would rather just skip the message and not have it be sent to the station or dead letter station, the cuser could instead return `None`, `None`:\n\n```python\nimport json\nimport base64\nfrom memphis import create_function\n\ndef handler(event, context): # The name of this file and this function should match the handler field in the memphis.yaml file in the following format \u003cfile name\u003e.\u003cfunction name\u003e\n    return create_function(event, event_handler = event_handler)\n\ndef event_handler(msg_payload, msg_headers, inputs):\n    payload =  str(msg_payload, 'utf-8')\n    as_json = json.loads(payload)\n    if as_json['check'] == False:\n        return None, None\n\n    return bytes(json.dumps(as_json), encoding='utf-8'), msg_headers\n```\n\nLastly, if the user is using another data format like Protocol Buffers, the user may simply decode the `msg_payload` into that format instead of JSON. Assuming we have a .proto definition like this: \n```proto\nsyntax = \"proto3\";\npackage protobuf_example;\n\nmessage Message{\n    string data_field = 1;\n}\n```\n\nWe can decode this and get the data_field out like this:\n\n```python\nimport json\nimport base64\nfrom memphis import create_function\nimport message_pb2\n\ndef handler(event, context): # The name of this file and this function should match the handler field in the memphis.yaml file in the following format \u003cfile name\u003e.\u003cfunction name\u003e\n    return create_function(event, event_handler = event_handler)\n\ndef event_handler(msg_payload, msg_headers, inputs):\n    message = message_pb2.Message()\n    message.ParseFromString(base64.b64decode(encoded_str))\n\n    # Arbitrarily changing the data_field\n    message.data_field = \"my new data\"\n\n    # SerializeToString returns bytes, which is the type we want\n    return message.SerializeToString(), msg_headers\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuperstreamlabs%2Fmemphis-functions.py","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsuperstreamlabs%2Fmemphis-functions.py","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsuperstreamlabs%2Fmemphis-functions.py/lists"}