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 details)

Uploaded Source

Built Distribution

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

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

Uploaded Python 3

File details

Details for the file prefect-jinja-0.0.1.tar.gz.

File metadata

  • Download URL: prefect-jinja-0.0.1.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for prefect-jinja-0.0.1.tar.gz
Algorithm Hash digest
SHA256 dde1cf179410a54b362bc87bb52b9c89e50767d119783fa1e15fc68c43c74b21
MD5 c02bf2725de3580862f287cfc54d9b4a
BLAKE2b-256 d78ce9ed2370b77648fbf2905487297025deabe38d63167874152b735890bdc2

See more details on using hashes here.

File details

Details for the file prefect_jinja-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: prefect_jinja-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 10.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for prefect_jinja-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0cde0c95f80db328f3a908196338a12c03a2ee93dabde01c4abadfc2cfa11023
MD5 b448bf9681524b12e11c29e9588adb37
BLAKE2b-256 e894c66442d4baccfdfe6c3b5d520ee3ab159175b2b905de4ee0594d566cd21f

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