Skip to main content

Super framework for your super app

Project description

๐Ÿซฐ Installation | ๐Ÿ“– Documentation | ๐Ÿ Getting Started | ๐Ÿ’ƒ Common Mistakes | โ“ FAQ

๐Ÿค– Zrb: A Framework to Enhance Your Workflow

Zrb is a CLI-based automation tool and low-code platform. Zrb can help you to:

  • Automate day-to-day tasks.
  • Generate projects or applications.
  • Prepare, run, and deploy your applications with a single command.
  • Etc.

You can also write custom task definitions in Python, enhancing Zrb's base capabilities. Defining your tasks in Zrb gives you several advantages because:

  • Every task has a retry mechanism.
  • Zrb handles your task dependencies automatically.
  • Zrb runs your task dependencies concurrently.

๐Ÿซฐ Installing Zrb

You can install Zrb as a pip package by invoking the following command:

pip install zrb

Alternatively, you can also use our installation script to install Zrb along with pyenv:

curl https://raw.githubusercontent.com/state-alchemists/zrb/main/install.sh | bash

Check our installation guide for more information about the installation methods, including installation as a docker container.

โš™๏ธ Zrb as A Task-Automation Tool

At the very core, Zrb is a task automation tool. It helps you to automate some tedious jobs so that you can focus on what matters.

Let's say you want to be able to describe the statistics property of any public CSV dataset. To do this, you need to perform three tasks like the following:

  • Install pandas.
  • Download the CSV dataset (at the same time).
  • Show statistics properties of the CSV dataset.
       ๐Ÿผ
Install Pandas โ”€โ”€โ”€โ”€โ”€โ”           ๐Ÿ“Š
                    โ”œโ”€โ”€โ–บ Show Statistics
Download Datasets โ”€โ”€โ”˜
       โฌ‡๏ธ

You can create a file named zrb_init.py and define the tasks as follows:

# File name: zrb_init.py
from zrb import runner, CmdTask, python_task, StrInput

DEFAULT_URL = 'https://raw.githubusercontent.com/state-alchemists/datasets/main/iris.csv'

# ๐Ÿผ Define a task named `install-pandas` to install pandas.
# If this task failed, we want Zrb to retry it again 4 times at most.
install_pandas = CmdTask(
    name='install-pandas',
    cmd='pip install pandas',
    retry=4
)

# โฌ‡๏ธ Define a task named `download-dataset` to download dataset.
# This task has an input named `url`.
# The input will be accessible by using Jinja template: `{{input.url}}`
# If this task failed, we want Zrb to retry it again 4 times at most
download_dataset = CmdTask(
    name='download-dataset',
    inputs=[
        StrInput(name='url', default=DEFAULT_URL)
    ],
    cmd='wget -O dataset.csv {{input.url}}',
    retry=4
)

# ๐Ÿ“Š Define a task named `show-stat` to show the statistics properties of the dataset.
# We use `@python_task` decorator since this task is better written in Python.
# This tasks depends on our previous tasks, `download_dataset` and `install_pandas`
# If this task failed, then it is failed. No need to retry
@python_task(
    name='show-stat',
    upstreams=[download_dataset, install_pandas],
    retry=0
)
def show_stat(*args, **kwargs):
    import pandas as pd
    df = pd.read_csv('dataset.csv')
    return df.describe()

# Register `show_stat`, so that the task is accessible from the CLI (i.e., zrb show-stat)
runner.register(show_stat)

๐Ÿ“ NOTE: It is possible (although less readable) to define show_stat as CmdTask:

Show code
show_stat = CmdTask(
    name='show-stat',
    upstreams=[download_dataset, install_pandas],
    cmd='python -c "import pandas as pd; df=pd.read_csv(\'dataset.csv\'); print(df.describe())"',
    retry=0
)

Once you write the definitions, Zrb will automatically load your zrb_init.py so that you can invoke your registered task:

zrb show-stat
Show output
Url [https://raw.githubusercontent.com/state-alchemists/datasets/main/iris.csv]:
๐Ÿค– โ—‹ โ—ท โ 43598 โ†’ 1/3 ๐Ÿฎ zrb project install-pandas โ€ข Run script: pip install pandas
๐Ÿค– โ—‹ โ—ท โ 43598 โ†’ 1/3 ๐Ÿฎ zrb project install-pandas โ€ข Working directory: /home/gofrendi/playground/my-project
๐Ÿค– โ—‹ โ—ท โ 43598 โ†’ 1/3 ๐Ÿ“ zrb project download-dataset โ€ข Run script: wget -O dataset.csv https://raw.githubusercontent.com/state-alchemists/datasets/main/iris.csv
๐Ÿค– โ—‹ โ—ท โ 43598 โ†’ 1/3 ๐Ÿ“ zrb project download-dataset โ€ข Working directory: /home/gofrendi/playground/my-project
๐Ÿค– โ–ณ โ—ท โ 43603 โ†’ 1/3 ๐Ÿ“ zrb project download-dataset โ€ข --2023-11-12 09:45:12--  https://raw.githubusercontent.com/state-alchemists/datasets/main/iris.csv
๐Ÿค– โ–ณ โ—ท โ 43603 โ†’ 1/3 ๐Ÿ“ zrb project download-dataset โ€ข Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.111.133, 185.199.109.133, 185.199.110.133, ...
๐Ÿค– โ–ณ โ—ท โ 43603 โ†’ 1/3 ๐Ÿ“ zrb project download-dataset โ€ข Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.111.133|:443... connected.
๐Ÿค– โ–ณ โ—ท โ 43603 โ†’ 1/3 ๐Ÿ“ zrb project download-dataset โ€ข HTTP request sent, awaiting response... 200 OK
๐Ÿค– โ–ณ โ—ท โ 43603 โ†’ 1/3 ๐Ÿ“ zrb project download-dataset โ€ข Length: 4606 (4.5K) [text/plain]
๐Ÿค– โ–ณ โ—ท โ 43603 โ†’ 1/3 ๐Ÿ“ zrb project download-dataset โ€ข Saving to: โ€˜dataset.csvโ€™
๐Ÿค– โ–ณ โ—ท โ 43603 โ†’ 1/3 ๐Ÿ“ zrb project download-dataset โ€ข
๐Ÿค– โ–ณ โ—ท โ 43603 โ†’ 1/3 ๐Ÿ“ zrb project download-dataset โ€ข      0K ....                                                  100% 1.39M=0.003s
๐Ÿค– โ–ณ โ—ท โ 43603 โ†’ 1/3 ๐Ÿ“ zrb project download-dataset โ€ข
๐Ÿค– โ–ณ โ—ท โ 43603 โ†’ 1/3 ๐Ÿ“ zrb project download-dataset โ€ข 2023-11-12 09:45:12 (1.39 MB/s) - โ€˜dataset.csvโ€™ saved [4606/4606]
๐Ÿค– โ–ณ โ—ท โ 43603 โ†’ 1/3 ๐Ÿ“ zrb project download-dataset โ€ข
๐Ÿค– โ—‹ โ—ท โ 43601 โ†’ 1/3 ๐Ÿฎ zrb project install-pandas โ€ข Requirement already satisfied: pandas in /home/gofrendi/zrb/.venv/lib/python3.10/site-packages (2.1.3)
๐Ÿค– โ—‹ โ—ท โ 43601 โ†’ 1/3 ๐Ÿฎ zrb project install-pandas โ€ข Requirement already satisfied: numpy<2,>=1.22.4 in /home/gofrendi/zrb/.venv/lib/python3.10/site-packages (from pandas) (1.26.1)
๐Ÿค– โ—‹ โ—ท โ 43601 โ†’ 1/3 ๐Ÿฎ zrb project install-pandas โ€ข Requirement already satisfied: python-dateutil>=2.8.2 in /home/gofrendi/zrb/.venv/lib/python3.10/site-packages (from pandas) (2.8.2)
๐Ÿค– โ—‹ โ—ท โ 43601 โ†’ 1/3 ๐Ÿฎ zrb project install-pandas โ€ข Requirement already satisfied: pytz>=2020.1 in /home/gofrendi/zrb/.venv/lib/python3.10/site-packages (from pandas) (2023.3.post1)
๐Ÿค– โ—‹ โ—ท โ 43601 โ†’ 1/3 ๐Ÿฎ zrb project install-pandas โ€ข Requirement already satisfied: tzdata>=2022.1 in /home/gofrendi/zrb/.venv/lib/python3.10/site-packages (from pandas) (2023.3)
๐Ÿค– โ—‹ โ—ท โ 43601 โ†’ 1/3 ๐Ÿฎ zrb project install-pandas โ€ข Requirement already satisfied: six>=1.5 in /home/gofrendi/zrb/.venv/lib/python3.10/site-packages (from python-dateutil>=2.8.2->pandas) (1.16.0)
Support zrb growth and development!
โ˜• Donate at: https://stalchmst.com/donation
๐Ÿ™ Submit issues/PR at: https://github.com/state-alchemists/zrb
๐Ÿค Follow us at: https://twitter.com/zarubastalchmst
๐Ÿค– โ—‹ โ—ท 2023-11-12 09:45:14.366 โ 43598 โ†’ 1/3 ๐ŸŽ zrb project show-stats โ€ข Completed in 2.2365798950195312 seconds
       sepal_length  sepal_width  petal_length  petal_width
count    150.000000   150.000000    150.000000   150.000000
mean       5.843333     3.054000      3.758667     1.198667
std        0.828066     0.433594      1.764420     0.763161
min        4.300000     2.000000      1.000000     0.100000
25%        5.100000     2.800000      1.600000     0.300000
50%        5.800000     3.000000      4.350000     1.300000
75%        6.400000     3.300000      5.100000     1.800000
max        7.900000     4.400000      6.900000     2.500000
To run again: zrb project show-stats --url "https://raw.githubusercontent.com/state-alchemists/datasets/main/iris.csv"

๐Ÿ“ NOTE: When executing a task, you can also provide the parameter directly, for example you want to provide the url

zrb show-stat --url https://raw.githubusercontent.com/state-alchemists/datasets/main/iris.csv

When you provide the parameter directly, Zrb will not prompt you to supply the URL. Another way to disable the prompt is by set ZRB_SHOW_PROMPT to 0 or false.

You can also run a Docker compose file, start a Web server, generate a CRUD application, or set up multiple servers simultaneously.

See our getting started guide and tutorials to learn more about the details.

โœ‚๏ธ Zrb as A Low-Code Framework

Zrb has some built-in tasks that allow you to create and run a CRUD application.

Let's see the following example.

# Create a project
zrb project create --project-dir my-project --project-name "My Project"
cd my-project

# Create a Fastapp
zrb project add fastapp --project-dir . --app-name "fastapp" --http-port 3000

# Add library module to fastapp
zrb project add fastapp-module --project-dir . --app-name "fastapp" --module-name "library"

# Add entity named "books"
zrb project add fastapp-crud --project-dir . --app-name "fastapp" --module-name "library" \
    --entity-name "book" --plural-entity-name "books" --column-name "code"

# Add column to the entity
zrb project add fastapp-field --project-dir . --app-name "fastapp" --module-name "library" \
    --entity-name "book" --column-name "title" --column-type "str"

# Run Fastapp as monolith
zrb project start-fastapp --fastapp-run-mode "monolith"

Once you invoke the commands, you will be able to access the CRUD application by pointing your browser to http://localhost:3000

Furthermore, you can also split your application into microservices, run them as docker containers, and even deploy them to your kubernetes cluster.

# Run Fastapp as microservices
zrb project start-fastapp --fastapp-run-mode "microservices"

# Run Fastapp as container
zrb project start-fastapp-container --fastapp-run-mode "microservices"
zrb project stop-fastapp-container

# Deploy fastapp and all it's dependencies to kubernetes
docker login
zrb project deploy-fastapp --fastapp-deploy-mode "microservices"

Visit our tutorials to see more cool tricks.

๐Ÿ“– Documentation

๐Ÿž Bug Report + Feature Request

You can submit bug report and feature request by creating a new issue on Zrb Github Repositories. When reporting a bug or requesting a feature, please be sure to:

  • Include the version of Zrb you are using (i.e., zrb version)
  • Tell us what you have try
  • Tell us what you expect
  • Tell us what you get

We will also welcome your pull requests and contributions.

โ˜• Donation

Help Red Skull to click the donation button:

๐ŸŽ‰ Fun Fact

Madou Ring Zaruba (้ญ”ๅฐŽ่ผชใ‚ถใƒซใƒ, Madลrin Zaruba) is a Madougu which supports bearers of the Garo Armor. (Garo Wiki | Fandom)

Madou Ring Zaruba on Kouga's Hand

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

zrb-0.0.118.tar.gz (2.8 MB view details)

Uploaded Source

Built Distribution

zrb-0.0.118-py3-none-any.whl (2.7 MB view details)

Uploaded Python 3

File details

Details for the file zrb-0.0.118.tar.gz.

File metadata

  • Download URL: zrb-0.0.118.tar.gz
  • Upload date:
  • Size: 2.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for zrb-0.0.118.tar.gz
Algorithm Hash digest
SHA256 010a66177b2e1345b074e07113a34a49b35a27722f6e311b7f17275da2c4ea94
MD5 855a6e43f95260c4b24bd76e2ffe6776
BLAKE2b-256 329e272f662b9bda1645ac107781781219c7dec08fcb082182f8a7bde7f44e35

See more details on using hashes here.

File details

Details for the file zrb-0.0.118-py3-none-any.whl.

File metadata

  • Download URL: zrb-0.0.118-py3-none-any.whl
  • Upload date:
  • Size: 2.7 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-requests/2.31.0

File hashes

Hashes for zrb-0.0.118-py3-none-any.whl
Algorithm Hash digest
SHA256 3ac3ebd54a386fa3e02dd98bb77e0bb045658bdbbef0161ed6f777657974b38e
MD5 638b48e5b14e5f3b69eeec9e5f71061b
BLAKE2b-256 f01a22477ddbe5143e784a366b60b507c24f4360caad871eda221aa2872023b4

See more details on using hashes here.

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