{"library":"prefect-client","title":"Prefect Client","description":"Prefect Client is a lightweight Python library providing essential client-side functionality for interacting with Prefect Cloud or a self-hosted Prefect server instance. It's designed for ephemeral execution environments like AWS Lambda, omitting the full Prefect SDK's CLI and local server components. The current version is 3.6.26, and it follows the active release cadence of the main Prefect project, including frequent stable and nightly builds.","language":"python","status":"active","last_verified":"Thu Apr 16","install":{"commands":["pip install prefect-client","pip install prefect"],"cli":null},"imports":["from prefect.deployments import run_deployment","from prefect.events import emit_event","from prefect.client.orchestration import get_client"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import os\nimport asyncio\nfrom prefect.deployments import run_deployment\nfrom prefect.client.orchestration import get_client\n\n# Ensure API URL and Key are set as environment variables for remote connection\nos.environ['PREFECT_API_URL'] = os.environ.get('PREFECT_API_URL', 'http://localhost:4200/api')\nos.environ['PREFECT_API_KEY'] = os.environ.get('PREFECT_API_KEY', 'your_api_key_if_needed')\n\nasync def interact_with_prefect_api():\n    print(f\"Connecting to Prefect API at: {os.environ['PREFECT_API_URL']}\")\n    async with get_client() as client:\n        # Example 1: Remotely trigger a deployment\n        try:\n            flow_run = await run_deployment(\n                name=\"my-flow/my-deployment\",\n                parameters={\"message\": \"Hello from prefect-client!\"},\n                timeout=0 # Do not wait for the flow run to complete\n            )\n            print(f\"Triggered flow run: {flow_run.name} (ID: {flow_run.id})\")\n        except Exception as e:\n            print(f\"Could not trigger deployment: {e}. Ensure 'my-flow/my-deployment' exists and is accessible.\")\n\n        # Example 2: Read some information from the API\n        try:\n            deployments = await client.read_deployments(limit=5)\n            print(f\"\\nFound {len(deployments)} deployments:\")\n            for dep in deployments:\n                print(f\"  - {dep.name} (ID: {dep.id})\")\n        except Exception as e:\n            print(f\"Could not read deployments: {e}. Check API URL/Key and server status.\")\n\nif __name__ == \"__main__\":\n    # Note: If connecting to Prefect Cloud, ensure PREFECT_API_KEY is set\n    # os.environ['PREFECT_API_KEY'] = 'your_prefect_cloud_api_key'\n    asyncio.run(interact_with_prefect_api())\n","lang":"python","description":"This quickstart demonstrates how to use `prefect-client` to interact with a remote Prefect server or Prefect Cloud. It shows how to trigger a deployed flow and how to query the API for existing deployments. Ensure the `PREFECT_API_URL` and `PREFECT_API_KEY` environment variables are set for successful connection to your Prefect instance.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}