Skip to main content

Prefect Collection Template contains all the boilerplate that you need to create a Prefect collection.

Project description

prefect-jinja

PyPI

Welcome!

prefect-jinja is a collection of pre-built Prefect tasks that can be used to quickly build Prefect flows to interact with Jinja.

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-jinja with pip:

pip install prefect-jinja

Then, register to view the block on Prefect Cloud:

prefect block register -m prefect_jinja.blocks

!!! note "Load Block" 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

Render templates from a directory

Using the JinjaEnvironmentBlock block and the jinja_render_from_template function to render an HTML page.

!!! note "Remote storage" We recommend configuring remote file storage for task execution with JinjaEnvironmentBlock block and the jinja_render_from_template function. This ensures tasks have access to templates files, particularly when accessing a instance outside the execution environment.

from prefect import flow
from prefect_jinja import JinjaEnvironmentBlock, jinja_render_from_template

@flow
def send_welcome_flow(username: str):
    jinja_environment = JinjaEnvironmentBlock(
        search_path="templates",
        namespace={
            "company_name": "Acme",
        }
    )
    
    return jinja_render_from_template(
        "welcome.html",
        jinja_environment,
        username=username
    )

print(send_welcome_flow(username="Neymar"))

Render templates from a string

Using the jinja_render_from_string function to render a string.

from prefect import flow
from prefect_jinja import jinja_render_from_string

@flow
def send_hello_flow(username: str):
    return jinja_render_from_string("Hello, {{name}}!", username=username)

print(send_hello_flow(username="Robinho"))

Resources

If you encounter any bugs while using prefect-jinja, feel free to open an issue in the prefect-jinja repository.

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

Development

If you'd like to install a version of prefect-jinja for development, clone the repository and perform an editable install with pip:

git clone https://github.com/hallenmaia/prefect-jinja.git

cd prefect-jinja/

pip install -e ".[dev]"

# Install linting pre-commit hooks
pre-commit install

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-jinja-0.0.1.tar.gz (27.1 kB view hashes)

Uploaded Source

Built Distribution

prefect_jinja-0.0.1-py3-none-any.whl (10.1 kB view hashes)

Uploaded Python 3

Supported by

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