# prefect-monte-carlo
Visit the full docs [here](https://PrefectHQ.github.io/prefect-monte-carlo) to see additional examples and the API reference.
<p align="center">
<a href="https://pypi.python.org/pypi/prefect-monte-carlo/" alt="PyPI version">
<img alt="PyPI" src="https://img.shields.io/pypi/v/prefect-monte-carlo?color=0052FF&labelColor=090422"></a>
<a href="https://github.com/PrefectHQ/prefect-monte-carlo/" alt="Stars">
<img src="https://img.shields.io/github/stars/PrefectHQ/prefect-monte-carlo?color=0052FF&labelColor=090422" /></a>
<a href="https://pepy.tech/badge/prefect-monte-carlo/" alt="Downloads">
<img src="https://img.shields.io/pypi/dm/prefect-monte-carlo?color=0052FF&labelColor=090422" /></a>
<a href="https://github.com/PrefectHQ/prefect-monte-carlo/pulse" alt="Activity">
<img src="https://img.shields.io/github/commit-activity/m/PrefectHQ/prefect-monte-carlo?color=0052FF&labelColor=090422" /></a>
<br>
<a href="https://prefect-community.slack.com" alt="Slack">
<img src="https://img.shields.io/badge/slack-join_community-red.svg?color=0052FF&labelColor=090422&logo=slack" /></a>
<a href="https://discourse.prefect.io/" alt="Discourse">
<img src="https://img.shields.io/badge/discourse-browse_forum-red.svg?color=0052FF&labelColor=090422&logo=discourse" /></a>
</p>
## Welcome!
A collection of Prefect tasks and flows to interact with Monte Carlo from workflows.
## Getting Started
### Python setup
Requires an installation of Python 3.7+.
We recommend using a Python virtual environment manager such as pipenv, conda or virtualenv.
These tasks are designed to work with Prefect 2.0. For more information about how to use Prefect, please refer to the [Prefect documentation](https://orion-docs.prefect.io/).
### Installation
Install `prefect-monte-carlo` with `pip`:
```bash
pip install prefect-monte-carlo
```
Then, register this collection's blocks to [view them on Prefect Cloud](https://orion-docs.prefect.io/ui/blocks/):
```bash
prefect block register -m prefect_monte_carlo
```
Note, to use the `load` method on Blocks, you must already have a block document [saved through code](https://orion-docs.prefect.io/concepts/blocks/#saving-blocks) or [saved through the UI](https://orion-docs.prefect.io/ui/blocks/).
### Write and run a flow
#### Execute a query against the Monte Carlo GraphQL API
```python
from prefect import flow
from prefect_monte_carlo.graphql import execute_graphql_operation
from prefect_monte_carlo.credentials import MonteCarloCredentials
@flow
def example_execute_query():
monte_carlo_credentials = MonteCarloCredentials.load("my-mc-creds")
result = execute_graphql_operation(
monte_carlo_credentials=monte_carlo_credentials,
operation="query getUser { getUser { email firstName lastName }}",
)
```
#### Create or update Monte Carlo lineage
```python
from prefect import flow
from prefect.context import get_run_context
from prefect_monte_carlo.credentials import MonteCarloCredentials
from prefect_monte_carlo.lineage import create_or_update_lineage, MonteCarloLineageNode
@flow
def monte_carlo_orchestrator():
current_flow_run_name = get_run_context().flow_run.name
source = MonteCarloLineageNode(
node_name="source_dataset",
object_id="source_dataset",
object_type="table",
resource_name="some_resource_name",
tags=[{"propertyName": "dataset_owner", "propertyValue": "owner_name"}],
)
destination = MonteCarloLineageNode(
node_name="destination_dataset",
object_id="destination_dataset",
object_type="table",
resource_name="some_resource_name",
tags=[{"propertyName": "dataset_owner", "propertyValue": "owner_name"}],
)
# `create_or_update_lineage` is a flow, so this will be a subflow run
# `extra_tags` are added to both the `source` and `destination` nodes
create_or_update_lineage(
monte_carlo_credentials=MonteCarloCredentials.load("my-mc-creds)
source=source,
destination=destination,
expire_at=datetime.now() + timedelta(days=10),
extra_tags=[{"propertyName": "flow_run_name", "propertyValue": current_flow_run_name}]
)
```
#### Conditionally execute a flow based on a Monte Carlo circuit breaker rule
```python
from prefect import flow
from prefect_monte_carlo.circuit_breakers import skip_if_circuit_breaker_flipped
from prefect_monte_carlo.credentials import MonteCarloCredentials
my_mc_creds = MonteCarloCredentials.load("my-mc-creds")
rule_name = "myRule"
@flow
@skip_if_circuit_breaker_flipped(
monte_carlo_credentials=my_mc_creds
rule_name=rule_name,
)
def conditional_flow():
logger = get_run_logger()
logger.info("If you see this, your circuit breaker rule was not breached!")
```
## Resources
If you encounter any bugs while using `prefect-monte-carlo`, feel free to open an issue in the [prefect-monte-carlo](https://github.com/PrefectHQ/prefect-monte-carlo) repository.
If you have any questions or issues while using `prefect-monte-carlo`, you can find help in either the [Prefect Discourse forum](https://discourse.prefect.io/) or the [Prefect Slack community](https://prefect.io/slack).
Feel free to star or watch [`prefect-monte-carlo`](https://github.com/PrefectHQ/prefect-monte-carlo) for updates too!
## Contributing
If you'd like to help contribute to fix an issue or add a feature to `prefect-monte-carlo`, please [propose changes through a pull request from a fork of the repository](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork).
Here are the steps:
1. [Fork the repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo#forking-a-repository)
2. [Clone the forked repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo#cloning-your-forked-repository)
3. Install the repository and its dependencies:
```
pip install -e ".[dev]"
```
4. Make desired changes
5. Add tests
6. Insert an entry to [CHANGELOG.md](https://github.com/PrefectHQ/prefect-monte-carlo/blob/main/CHANGELOG.md)
7. Install `pre-commit` to perform quality checks prior to commit:
```
pre-commit install
```
8. `git commit`, `git push`, and create a pull request
Raw data
{
"_id": null,
"home_page": "https://github.com/PrefectHQ/prefect-monte-carlo",
"name": "prefect-monte-carlo",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "prefect",
"author": "Prefect Technologies",
"author_email": "help@prefect.io",
"download_url": "https://files.pythonhosted.org/packages/21/4b/1dad07cb50c9b41c6f0a970f9ca9262202af04f840d0f4e44f0ac7b852f8/prefect-monte-carlo-0.3.2.tar.gz",
"platform": null,
"description": "# prefect-monte-carlo\n\nVisit the full docs [here](https://PrefectHQ.github.io/prefect-monte-carlo) to see additional examples and the API reference.\n\n<p align=\"center\">\n <a href=\"https://pypi.python.org/pypi/prefect-monte-carlo/\" alt=\"PyPI version\">\n <img alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/prefect-monte-carlo?color=0052FF&labelColor=090422\"></a>\n <a href=\"https://github.com/PrefectHQ/prefect-monte-carlo/\" alt=\"Stars\">\n <img src=\"https://img.shields.io/github/stars/PrefectHQ/prefect-monte-carlo?color=0052FF&labelColor=090422\" /></a>\n <a href=\"https://pepy.tech/badge/prefect-monte-carlo/\" alt=\"Downloads\">\n <img src=\"https://img.shields.io/pypi/dm/prefect-monte-carlo?color=0052FF&labelColor=090422\" /></a>\n <a href=\"https://github.com/PrefectHQ/prefect-monte-carlo/pulse\" alt=\"Activity\">\n <img src=\"https://img.shields.io/github/commit-activity/m/PrefectHQ/prefect-monte-carlo?color=0052FF&labelColor=090422\" /></a>\n <br>\n <a href=\"https://prefect-community.slack.com\" alt=\"Slack\">\n <img src=\"https://img.shields.io/badge/slack-join_community-red.svg?color=0052FF&labelColor=090422&logo=slack\" /></a>\n <a href=\"https://discourse.prefect.io/\" alt=\"Discourse\">\n <img src=\"https://img.shields.io/badge/discourse-browse_forum-red.svg?color=0052FF&labelColor=090422&logo=discourse\" /></a>\n</p>\n\n## Welcome!\n\nA collection of Prefect tasks and flows to interact with Monte Carlo from workflows.\n\n## Getting Started\n\n### Python setup\n\nRequires an installation of Python 3.7+.\n\nWe recommend using a Python virtual environment manager such as pipenv, conda or virtualenv.\n\nThese tasks are designed to work with Prefect 2.0. For more information about how to use Prefect, please refer to the [Prefect documentation](https://orion-docs.prefect.io/).\n\n### Installation\n\nInstall `prefect-monte-carlo` with `pip`:\n\n```bash\npip install prefect-monte-carlo\n```\n\nThen, register this collection's blocks to [view them on Prefect Cloud](https://orion-docs.prefect.io/ui/blocks/):\n\n```bash\nprefect block register -m prefect_monte_carlo\n```\n\nNote, to use the `load` method on Blocks, you must already have a block document [saved through code](https://orion-docs.prefect.io/concepts/blocks/#saving-blocks) or [saved through the UI](https://orion-docs.prefect.io/ui/blocks/).\n\n### Write and run a flow\n#### Execute a query against the Monte Carlo GraphQL API\n```python\nfrom prefect import flow\nfrom prefect_monte_carlo.graphql import execute_graphql_operation\nfrom prefect_monte_carlo.credentials import MonteCarloCredentials\n\n@flow\ndef example_execute_query():\n monte_carlo_credentials = MonteCarloCredentials.load(\"my-mc-creds\")\n result = execute_graphql_operation(\n monte_carlo_credentials=monte_carlo_credentials,\n operation=\"query getUser { getUser { email firstName lastName }}\",\n )\n```\n\n#### Create or update Monte Carlo lineage\n```python\nfrom prefect import flow\nfrom prefect.context import get_run_context\nfrom prefect_monte_carlo.credentials import MonteCarloCredentials\nfrom prefect_monte_carlo.lineage import create_or_update_lineage, MonteCarloLineageNode\n\n@flow\ndef monte_carlo_orchestrator():\n current_flow_run_name = get_run_context().flow_run.name\n\n source = MonteCarloLineageNode(\n node_name=\"source_dataset\",\n object_id=\"source_dataset\",\n object_type=\"table\",\n resource_name=\"some_resource_name\",\n tags=[{\"propertyName\": \"dataset_owner\", \"propertyValue\": \"owner_name\"}],\n )\n\n destination = MonteCarloLineageNode(\n node_name=\"destination_dataset\",\n object_id=\"destination_dataset\",\n object_type=\"table\",\n resource_name=\"some_resource_name\",\n tags=[{\"propertyName\": \"dataset_owner\", \"propertyValue\": \"owner_name\"}],\n )\n\n # `create_or_update_lineage` is a flow, so this will be a subflow run\n # `extra_tags` are added to both the `source` and `destination` nodes\n create_or_update_lineage(\n monte_carlo_credentials=MonteCarloCredentials.load(\"my-mc-creds)\n source=source,\n destination=destination,\n expire_at=datetime.now() + timedelta(days=10),\n extra_tags=[{\"propertyName\": \"flow_run_name\", \"propertyValue\": current_flow_run_name}]\n )\n```\n\n\n#### Conditionally execute a flow based on a Monte Carlo circuit breaker rule\n```python\nfrom prefect import flow\nfrom prefect_monte_carlo.circuit_breakers import skip_if_circuit_breaker_flipped\nfrom prefect_monte_carlo.credentials import MonteCarloCredentials\n\nmy_mc_creds = MonteCarloCredentials.load(\"my-mc-creds\")\nrule_name = \"myRule\"\n\n@flow\n@skip_if_circuit_breaker_flipped(\n monte_carlo_credentials=my_mc_creds\n rule_name=rule_name,\n)\ndef conditional_flow():\n logger = get_run_logger()\n logger.info(\"If you see this, your circuit breaker rule was not breached!\")\n```\n\n## Resources\n\nIf you encounter any bugs while using `prefect-monte-carlo`, feel free to open an issue in the [prefect-monte-carlo](https://github.com/PrefectHQ/prefect-monte-carlo) repository.\n\nIf you have any questions or issues while using `prefect-monte-carlo`, you can find help in either the [Prefect Discourse forum](https://discourse.prefect.io/) or the [Prefect Slack community](https://prefect.io/slack).\n\nFeel free to star or watch [`prefect-monte-carlo`](https://github.com/PrefectHQ/prefect-monte-carlo) for updates too!\n\n## Contributing\n\nIf you'd like to help contribute to fix an issue or add a feature to `prefect-monte-carlo`, please [propose changes through a pull request from a fork of the repository](https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/creating-a-pull-request-from-a-fork).\n\nHere are the steps:\n\n1. [Fork the repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo#forking-a-repository)\n2. [Clone the forked repository](https://docs.github.com/en/get-started/quickstart/fork-a-repo#cloning-your-forked-repository)\n3. Install the repository and its dependencies:\n```\npip install -e \".[dev]\"\n```\n4. Make desired changes\n5. Add tests\n6. Insert an entry to [CHANGELOG.md](https://github.com/PrefectHQ/prefect-monte-carlo/blob/main/CHANGELOG.md)\n7. Install `pre-commit` to perform quality checks prior to commit:\n\n```\npre-commit install\n```\n8. `git commit`, `git push`, and create a pull request\n",
"bugtrack_url": null,
"license": "Apache License 2.0",
"summary": "Prefect integrations for interacting with Monte Carlo.",
"version": "0.3.2",
"project_urls": {
"Homepage": "https://github.com/PrefectHQ/prefect-monte-carlo"
},
"split_keywords": [
"prefect"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a4daad294de6653d1ee385f7061cbbf9243275409c3776e2a80ec631e7f30bd2",
"md5": "4887553e4d15c6ede215c65a02ab1a38",
"sha256": "e51c341103ff6e47913960a0f5eec8b27dfdce22199cba978b028a224ee2b16e"
},
"downloads": -1,
"filename": "prefect_monte_carlo-0.3.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4887553e4d15c6ede215c65a02ab1a38",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 17685,
"upload_time": "2023-11-29T19:59:19",
"upload_time_iso_8601": "2023-11-29T19:59:19.297529Z",
"url": "https://files.pythonhosted.org/packages/a4/da/ad294de6653d1ee385f7061cbbf9243275409c3776e2a80ec631e7f30bd2/prefect_monte_carlo-0.3.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "214b1dad07cb50c9b41c6f0a970f9ca9262202af04f840d0f4e44f0ac7b852f8",
"md5": "3239f1f200e3ce62ec00b274ba1343ff",
"sha256": "2929ae3403898c40238d76f1a343f8f38a48e5e8470ba74310d6b0faa21d3263"
},
"downloads": -1,
"filename": "prefect-monte-carlo-0.3.2.tar.gz",
"has_sig": false,
"md5_digest": "3239f1f200e3ce62ec00b274ba1343ff",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 36442,
"upload_time": "2023-11-29T19:59:20",
"upload_time_iso_8601": "2023-11-29T19:59:20.624732Z",
"url": "https://files.pythonhosted.org/packages/21/4b/1dad07cb50c9b41c6f0a970f9ca9262202af04f840d0f4e44f0ac7b852f8/prefect-monte-carlo-0.3.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-11-29 19:59:20",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "PrefectHQ",
"github_project": "prefect-monte-carlo",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "prefect-monte-carlo"
}