{"id":29132358,"url":"https://github.com/expediagroup/flyte-client-python","last_synced_at":"2025-10-12T22:15:45.570Z","repository":{"id":150177292,"uuid":"212380902","full_name":"ExpediaGroup/flyte-client-python","owner":"ExpediaGroup","description":"A Python library designed to make the writing of flyte packs simple","archived":false,"fork":false,"pushed_at":"2024-03-05T07:59:33.000Z","size":30,"stargazers_count":0,"open_issues_count":1,"forks_count":2,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-06-30T06:44:40.362Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ExpediaGroup.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2019-10-02T15:49:32.000Z","updated_at":"2020-08-25T13:30:11.000Z","dependencies_parsed_at":null,"dependency_job_id":"a5859b15-2312-44ca-ab5b-100be3eddeab","html_url":"https://github.com/ExpediaGroup/flyte-client-python","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ExpediaGroup/flyte-client-python","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaGroup%2Fflyte-client-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaGroup%2Fflyte-client-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaGroup%2Fflyte-client-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaGroup%2Fflyte-client-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ExpediaGroup","download_url":"https://codeload.github.com/ExpediaGroup/flyte-client-python/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ExpediaGroup%2Fflyte-client-python/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264787463,"owners_count":23663937,"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-06-30T06:39:29.272Z","updated_at":"2025-10-12T22:15:40.535Z","avatar_url":"https://github.com/ExpediaGroup.png","language":"Python","readme":"# flyte-client\n\nflyte-client is a python library designed to make the writing of flyte packs simple. \nThe client handles the registration of a pack with the flyte server, consuming and handling command actions, and gives the ability to send\npack events to the flyte server. This allows the pack writer to concentrate solely on the functionality of their pack.\n\n\n## Getting started\n\n* Clone this repo\n* Run `make prepare-dev` only once (must have python3 installed )\n* Run `make init` to setup virtualenv and download all the dependencies.\n\n#### Classes\nThe classes that a pack developer interacts with can be found in `flyte/pack/classes.py`.\nThe main ones are as follows:\n\n- **PackDef**: defines the pack - it's name, what commands it has and what events it can raise.\n- **EventDef**: defines an event - it's name and an optional help URL to describe the event in more detail\n- **Command**: defines a command that can be called on the pack - its name, what event it returns, and an optional help URL to describe the event in more detail. \nAlso includes a **CommandHandler** which is the function that will be executed when the command is called.\n- **Event**: this dto is sent from the pack to the flyte server api - it contains the name of the event and it's payload \n\n\n#### Events\n\nPacks can send events to the flyte server in 3 ways:\n\n1. The pack can observe something happening and spontaneously send an event to the flyte server. \nFor example a chat-ops pack, may observe an instant message being sent and raise a \"MessageSent\" event to the flyte server. \nIt would do this by calling the `send_event` function on the `Pack` class.\n\n1. A flow on the flyte server creates an action for the pack to execute. \nThe client will poll for this action and invoke the relevant `CommandHandler` that the pack dev has defined. \nThis handler will return an event that the client will then send to the flyte server. \nFor example the same IM pack as above may have a 'sendMessage' command that would return either a 'MessageSent' or 'MessageSendFailure' event.\n\n1. The client will produce `FATAL` events as a result of panic happening while handling a `Command`. This will be intercepted by the\nclient and it will recover. If they need to, packs can also produce `FATAL` events themselves as a result of the handling if they detect\nany errors using `NewFatalEvent(payload interface{})`. This is preferred over throwing an exception in the handler. E.g.\n```python\nclass MyCommandHandler(CommandHandler):\n    def handle(self, request) -\u003e Event:\n        ...\n        \"\"\"Preferred\"\"\" \n        event = fatal_event(\"Error message\")\n        \"\"\"Over\"\"\"\n        raise Exception(\"something went wrong\")\n        ...\n```\n\nThe 'EventDefs' field on a Command is mandatory.\nThe 'EventDefs' on the PackDef are optional. Here you would specify any events that the pack observes and sends spontaneously. \nIf the event you want to define is already defined in a command (as with 'MessageSent' above) then you are not required to add it to the separate EventDefs section - however there is no harm in doing so.\n\n#### Help URLs\n\nYou will notice that a `helpURL` field is present in 3 locations - PackDef, Command, and EventDef. \nThese correspond to the URLs visible in the json on the flyte server at that level.\nThe help URLs are all optional, though you should generally always have the pack level one. \nIt's up to pack developers to provide which ones they think are the most useful. \nFor a simple pack you'd probably just provide a single pack level help link. \nFor a more complex pack you might want to deep link commands \u0026 event definitions to a specific piece of documentation.\n\nThe URL should link to a page that describes what a flow writer needs to know i.e. what the pack does, the format of the json in the event payloads and the format of the json for command inputs.\nIt's up to the pack dev where and how they host their help docs - for example it could be a link to a README file or a hosted web page.\n\n#### Example Pack\n\nThe example below shows how to create a pack. The pack exposes a \"Rota\" command allowing users to query for who is on duty.\nIf this command succeeds it returns an \"RotaRetrieved\" event.\n\n\n```python\nimport asyncio\nimport functools\nimport logging\nimport os\nimport random\nimport signal\n\nfrom flyte import Pack\nfrom flyte.client.client import Client\nfrom flyte.pack.classes import PackDef, Command, EventDef, CommandHandler, Event\n\n\nclass RotaCommandHandler(CommandHandler):\n    \"\"\"command handler that process rota commands\"\"\"\n\n    def __init__(self, log) -\u003e None:\n        self.logger = log\n\n    def handle(self, request) -\u003e Event:\n        candidates = [\"Isaac\", \"Jane\", \"Tom\", \"Lukas\", \"Emilie\"]\n        self.logger.info(\"message successfully consumed\")\n        return Event(eventDef=EventDef(name=\"RotaRetrieved\"), payload=random.choice(candidates))\n\n\ndef shutdown(event_loop):\n    logger.info('received stop signal, cancelling tasks...')\n    for task in asyncio.Task.all_tasks():\n        task.cancel()\n    logger.info('bye, exiting in a minute...')\n    event_loop.stop()\n\n\nif __name__ == \"__main__\":\n    logger = logging.getLogger()\n    logger.setLevel(logging.INFO)\n\n    logger.addHandler(logging.StreamHandler())\n\n    loop = asyncio.get_event_loop()\n    loop.add_signal_handler(signal.SIGTERM, functools.partial(shutdown, loop))\n    loop.add_signal_handler(signal.SIGHUP, functools.partial(shutdown, loop))\n\n    try:\n        pack_def = PackDef(\n            name=\"page-of-duty-pack\",\n            commands=[\n                Command(name=\"Rota\", handler=RotaCommandHandler(logger), output_events=[\n                    EventDef(name=\"RotaRetrieved\"),\n                    EventDef(name=\"Error\"),\n                ]),\n            ],\n            labels={},\n            event_defs=[],\n            help_url=\"http://github.com/your-repo.git\")\n\n        pack = Pack(pack_def=pack_def, client=Client(url=os.environ['FLYTE_API']))\n\n        loop.run_until_complete(pack.start())\n    except KeyboardInterrupt:\n        shutdown(loop)\n        logger.info('Keyboard exception received. Exiting.')\n        exit()\n```\n\n## Running Tests\n\n```\nmake test\n```\n## Running the example pack\n\nYou need to make sure that flyte server and flyte-slack pack are up and running. \nPlease check how to run them locally [here](https://github.com/ExpediaGroup/flyte/blob/master/docs/quickstart.md#spin-up-your-local-environment):\n\n```\nmake run-example\n```\n\nYou will also need to push an [example flow](example/flow.yaml) to test it. Check how to do it [here](https://github.com/ExpediaGroup/flyte/blob/master/docs/quickstart.md#installing-a-flow)\n\n## Create a docker container\n\n```\nmake docker-build\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpediagroup%2Fflyte-client-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fexpediagroup%2Fflyte-client-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fexpediagroup%2Fflyte-client-python/lists"}