Skip to main content

Prefect integrations for interacting with Monte Carlo.

Project description

prefect-monte-carlo

Visit the full docs here to see additional examples and the API reference.

PyPI

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.

Installation

Install prefect-monte-carlo with pip:

pip install prefect-monte-carlo

Then, register this collection's blocks to view them on Prefect Cloud:

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 or saved through the UI.

Write and run a flow

Execute a query against the Monte Carlo GraphQL API

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

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

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 repository.

If you have any questions or issues while using prefect-monte-carlo, you can find help in either the Prefect Discourse forum or the Prefect Slack community.

Feel free to star or watch 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.

Here are the steps:

  1. Fork the repository
  2. Clone the forked repository
  3. Install the repository and its dependencies:
pip install -e ".[dev]"
  1. Make desired changes
  2. Add tests
  3. Insert an entry to CHANGELOG.md
  4. Install pre-commit to perform quality checks prior to commit:
pre-commit install
  1. git commit, git push, and create a pull request

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

prefect-monte-carlo-0.3.2.tar.gz (36.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

prefect_monte_carlo-0.3.2-py3-none-any.whl (17.7 kB view details)

Uploaded Python 3

File details

Details for the file prefect-monte-carlo-0.3.2.tar.gz.

File metadata

  • Download URL: prefect-monte-carlo-0.3.2.tar.gz
  • Upload date:
  • Size: 36.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.6

File hashes

Hashes for prefect-monte-carlo-0.3.2.tar.gz
Algorithm Hash digest
SHA256 2929ae3403898c40238d76f1a343f8f38a48e5e8470ba74310d6b0faa21d3263
MD5 3239f1f200e3ce62ec00b274ba1343ff
BLAKE2b-256 214b1dad07cb50c9b41c6f0a970f9ca9262202af04f840d0f4e44f0ac7b852f8

See more details on using hashes here.

File details

Details for the file prefect_monte_carlo-0.3.2-py3-none-any.whl.

File metadata

File hashes

Hashes for prefect_monte_carlo-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e51c341103ff6e47913960a0f5eec8b27dfdce22199cba978b028a224ee2b16e
MD5 4887553e4d15c6ede215c65a02ab1a38
BLAKE2b-256 a4daad294de6653d1ee385f7061cbbf9243275409c3776e2a80ec631e7f30bd2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page