Repository: PrefectHQ/prefect
Pull request: Add `.serve`, `.deploy`, and composite trigger examples to deployment triggers docs
<!-- 
Thanks for opening a pull request to Prefect! We've got a few requests to help us review contributions:

- Make sure that your title neatly summarizes the proposed changes.
- Provide a short overview of the change and the value it adds.
- Share an example to help us understand the change in user experience.
- Confirm that you've done common tasks so we can give a timely review.
- Review our contribution guidelines: https://docs.prefect.io/latest/contributing/overview/

Happy engineering!
-->

Closes #11720 

<!-- Include an overview here -->

### Example
<!-- 
Share an example of the change in action.

A code blurb is best. Changes to features should include an example that is executable by a new user.
If changing documentation, a link to a preview of the page is great.
 -->

### Checklist
<!-- These boxes may be checked after opening the pull request. -->

- [x] This pull request references any related issue by including "closes `<link to issue>`"
	- If no issue exists and your change is not a small fix, please [create an issue](https://github.com/PrefectHQ/prefect/issues/new/choose) first.
- [ ] If this pull request adds new functionality, it includes unit tests that cover the changes
- [x] This pull request includes a label categorizing the change e.g. `maintenance`, `fix`, `feature`, `enhancement`, `docs`.
  <!-- If you do not have permission to add a label, a maintainer will add one for you -->

For documentation changes:

- [ ] This pull request includes redirect settings in `netlify.toml` for files that are removed or renamed.

For new functions or classes in the Python SDK:

- [ ] This pull request includes helpful docstrings.
- [ ] If a new Python file was added, this pull request contains a stub page in the Python SDK docs and an entry in `mkdocs.yml` navigation.


Problem statement:
Add example of using `flow.deploy` with a trigger
### First check

- [X] I added a descriptive title to this issue.
- [X] I used GitHub search to find a similar request and didn't find it 😇

### Describe the issue

The Automations guide contains an example of `prefect deploy` with a trigger in a YAML file.

### Describe the proposed change

We should add a tab with an example of `flow.deploy` with a trigger.

We could add something like this test.

```
        deployment = await test_flow.to_deployment(
            name="test",
            tags=["price", "luggage"],
            parameters={"name": "Arthur"},
            description="This is a test",
            version="alpha",
            enforce_parameter_schema=True,
            triggers=[
                {
                    "name": "Happiness",
                    "enabled": True,
                    "match": {"prefect.resource.id": "prefect.flow-run.*"},
                    "expect": ["prefect.flow-run.Completed"],
                    "match_related": {
                        "prefect.resource.name": "seed",
                        "prefect.resource.role": "flow",
                    },
                }
            ],
        )
```

### Additional context

_No response_

Hints from issue discussion:

Commit message: Merge branch 'main' into docs-deploy-trigger

Patch to review:
diff --git a/docs/concepts/automations.md b/docs/concepts/automations.md
index 401f95e703db..e1e3d18c6900 100644
--- a/docs/concepts/automations.md
+++ b/docs/concepts/automations.md
@@ -556,15 +556,21 @@ Sequence triggers are defined as:
 
 To enable the simple configuration of event-driven deployments, Prefect provides deployment triggers - a shorthand for creating automations that are linked to specific deployments to run them based on the presence or absence of events.
 
+Trigger definitions for deployments are supported in `prefect.yaml`, `.serve`, and `.deploy`. At deployment time, this will create a linked automation that is triggered by events matching your chosen [grammar](/concepts/events/#event-grammar), which will pass the templatable `event` as a parameter to the deployment's flow run.
+
+### Defining triggers in `prefect.yaml`
+
+A list of triggers can be included directly on any deployment in a `prefect.yaml` file:
+
 ```yaml
-# prefect.yaml
 deployments:
   - name: my-deployment
     entrypoint: path/to/flow.py:decorated_fn
     work_pool:
-      name: my-process-pool
+      name: my-work-pool
     triggers:
-      - enabled: true
+      - type: event
+        enabled: true
         match:
           prefect.resource.id: my.external.resource
         expect:
@@ -573,7 +579,101 @@ deployments:
           param_1: "{{ event }}"
 ```
 
-At deployment time, this will create a linked automation that is triggered by events matching your chosen [grammar](/concepts/events/#event-grammar), which will pass the templatable `event` as a parameter to the deployment's flow run.
+This deployment will be run when an `external.resource.pinged` event _and_ an `external.resource.replied` event have been seen from `my.external.resource`:
+
+```yaml
+deployments:
+  - name: my-deployment
+    entrypoint: path/to/flow.py:decorated_fn
+    work_pool:
+      name: my-work-pool
+    triggers:
+      - type: compound
+        require: all
+        parameters:
+          param_1: "{{ event }}"
+        triggers:
+          - type: event
+            match:
+              prefect.resource.id: my.external.resource
+            expect:
+              - external.resource.pinged
+          - type: event
+            match:
+              prefect.resource.id: my.external.resource
+            expect:
+              - external.resource.replied
+```
+
+### Defining triggers in `.serve` and `.deploy`
+
+For creating deployments with triggers in Python, the trigger types `DeploymentEventTrigger`, `DeploymentMetricTrigger`, `DeploymentCompoundTrigger`, and `DeploymentSequenceTrigger` can be imported from `prefect.events`:
+
+```python
+from prefect import flow
+from prefect.events import DeploymentEventTrigger 
+
+
+@flow(log_prints=True)
+def decorated_fn(param_1):
+    print(param_1["payload"])
+
+
+if __name__=="__main__":
+    decorated_fn.serve(
+        name="my-deployment",
+        triggers=[
+            DeploymentEventTrigger(
+                enabled=True,
+                match={"prefect.resource.id": "my.external.resource"},
+                expect=["external.resource.pinged"],
+                parameters={
+                    "param_1": "{{ event }}",
+                },
+            )
+        ],
+    )
+```
+
+As with prior examples, composite triggers must be supplied with a list of underlying triggers:
+
+```python
+from prefect import flow
+from prefect.events import DeploymentEventTrigger, DeploymentCompoundTrigger
+
+
+@flow(log_prints=True)
+def decorated_fn(param_1):
+    print(param_1["payload"])
+
+
+if __name__=="__main__":
+    decorated_fn.deploy(
+        name="my-deployment",
+        image="prefecthq/prefect:2-latest"
+        triggers=[
+            DeploymentCompoundTrigger(
+                name="my-compound-trigger",
+                require="all",
+                triggers=[
+                    DeploymentEventTrigger(
+                      match={"prefect.resource.id": "my.external.resource"},
+                      expect=["external.resource.pinged"],
+                    ),
+                    DeploymentEventTrigger(
+                      match={"prefect.resource.id": "my.external.resource"},
+                      expect=["external.resource.replied"],
+                    ),
+                ],
+                parameters={
+                    "param_1": "{{ event }}",
+                },
+            )
+        ],
+        work_pool_name="my-work-pool",
+    )
+```
+
 
 ### Pass triggers to `prefect deploy`
 


Code review comments:
diff_hunk: @@ -573,7 +579,101 @@ deployments:
           param_1: "{{ event }}"
 ```
 
-At deployment time, this will create a linked automation that is triggered by events matching your chosen [grammar](/concepts/events/#event-grammar), which will pass the templatable `event` as a parameter to the deployment's flow run.
+This deployment will be run when an `external.resource.pinged` event _and_ an `external.resource.replied` event have been seen from `my.external.resource`:
+
+```yaml
+deployments:
+  - name: my-deployment
+    entrypoint: path/to/flow.py:decorated_fn
+    work_pool:
+      name: my-work-pool
+    triggers:
+      - type: compound
+        require: all
+        parameters:
+          param_1: "{{ event }}"
+        triggers:
+          - type: event
+            match:
+              prefect.resource.id: my.external.resource
+            expect:
+              - external.resource.pinged
+          - type: event
+            match:
+              prefect.resource.id: my.external.resource
+            expect:
+              - external.resource.replied
+```
+
+### Defining triggers in `.serve` and `.deploy`
+
+For creating deployments with triggers in Python, the trigger types `DeploymentEventTrigger`, `DeploymentMetricTrigger`, `DeploymentCompoundTrigger`, and `DeploymentSequenceTrigger` can be imported from `prefect.events`:
+
+```python
+from prefect import flow
+from prefect.events import DeploymentEventTrigger 
+
+
+@flow(log_prints=True)
+def decorated_fn(param_1):
+    print(param_1["payload"])
+
+
+if __name__=="__main__":
+    decorated_fn.serve(
+        name="my-deployment",
+        triggers=[
+            DeploymentEventTrigger(
+                enabled=True,
+                match={"prefect.resource.id": "my.external.resource"},
+                expect=["external.resource.pinged"],
+                parameters={
+                    "param_1": "{{ event }}",
+                },
+            )
+        ],
+    )
+```
+
+As with prior examples, composite triggers must be supplied with a list of underlying triggers:
+
+```python
+from prefect import flow
+from prefect.events import DeploymentEventTrigger, DeploymentCompoundTrigger
+
+
+@flow(log_prints=True)
+def decorated_fn(param_1):
path: docs/concepts/automations.md
text: @user1:
```suggestion
def decorated_fn(param_1: str):
```

diff_hunk: @@ -573,7 +579,101 @@ deployments:
           param_1: "{{ event }}"
 ```
 
-At deployment time, this will create a linked automation that is triggered by events matching your chosen [grammar](/concepts/events/#event-grammar), which will pass the templatable `event` as a parameter to the deployment's flow run.
+This deployment will be run when an `external.resource.pinged` event _and_ an `external.resource.replied` event have been seen from `my.external.resource`:
path: docs/concepts/automations.md
text: @user1:
```suggestion
This deployment will create a flow run when an `external.resource.pinged` event _and_ an `external.resource.replied` event have been seen from `my.external.resource`:
```

diff_hunk: @@ -573,7 +579,101 @@ deployments:
           param_1: "{{ event }}"
 ```
 
-At deployment time, this will create a linked automation that is triggered by events matching your chosen [grammar](/concepts/events/#event-grammar), which will pass the templatable `event` as a parameter to the deployment's flow run.
+This deployment will be run when an `external.resource.pinged` event _and_ an `external.resource.replied` event have been seen from `my.external.resource`:
+
+```yaml
+deployments:
+  - name: my-deployment
+    entrypoint: path/to/flow.py:decorated_fn
+    work_pool:
+      name: my-work-pool
+    triggers:
+      - type: compound
+        require: all
+        parameters:
+          param_1: "{{ event }}"
+        triggers:
+          - type: event
+            match:
+              prefect.resource.id: my.external.resource
+            expect:
+              - external.resource.pinged
+          - type: event
+            match:
+              prefect.resource.id: my.external.resource
+            expect:
+              - external.resource.replied
+```
+
+### Defining triggers in `.serve` and `.deploy`
+
+For creating deployments with triggers in Python, the trigger types `DeploymentEventTrigger`, `DeploymentMetricTrigger`, `DeploymentCompoundTrigger`, and `DeploymentSequenceTrigger` can be imported from `prefect.events`:
+
+```python
+from prefect import flow
+from prefect.events import DeploymentEventTrigger 
+
+
+@flow(log_prints=True)
+def decorated_fn(param_1):
path: docs/concepts/automations.md
text: @user1:
```suggestion
def decorated_fn(param_1: str):
```