TUTORIAL

How to create a credit approval workflow

Receive and process credit requests, with automated and manual reviews and integrations to Slack and Sendrid.

Step-by-Step Tutorial: Creating a Credit Approval Workflow

Welcome to this tutorial where we'll guide you through setting up and using Abstra Workflows to automate business processes using Python. This tutorial is designed for new users and will provide a practical example of creating a credit approval workflow.

Access the entire project source code here.

Step 1: Installing Abstra

First, you need to install Abstra on your machine. Open your terminal and run the following command:


pip install abstra

This command installs the Abstra CLI, which is essential for starting and managing your projects.

Step 2: Starting Your Project

Once Abstra is installed, you can start a new project by navigating to your desired project directory and running:

abstra editor ./your-project-directory

This command launches the Abstra editor in your browser and automatically creates a project directory with necessary Python files and a .abstra.json file for managing workflows. If you'd like to run Abstra in an existing directory, you can navigate to that in your terminal and run the abstra editor from within that.

Step 3: Understanding Workflow Components

Abstra workflows consist of various components:

  • Forms: For user interactions, such as inputs and displays.
  • Hooks: For external system interactions.
  • Jobs: For scheduled tasks.
  • Scripts: Triggered by other scripts in the workflow.

Step 4: Creating a Credit Approval Workflow

Let's create a workflow for credit approval, which involves form submission, data processing, and manual review.

4.1 Creating a Form

Navigate to the Stages page in the Abstra editor and click on "Create new" then select "Forms". Name it "Credit Request Form". This action automatically generates a Python file for handling form inputs.

Use Abstra Forms module widgets to create the user interactions, and Abstra Workflows to store the data.

Here's an example of how you might set up the form and store the data for processing in the next stages:


import abstra.forms as af
import abstra.workflows as aw

name = af.read("👋 What is your name?")
aw.set_data("name", name)

email = af.read_email("📧 What is your email?")
aw.set_data("email", email

income = af.read_currency("💵 What is your monthly income?")
aw.set_data("income", income)

loan_amount = af.read_currency("💰 How much do you want to borrow?")
aw.set_data("loan_amount", loan_amount)

af.display(f"Thank you, {name}. We are processing your request."

4.2 Processing the Data

After the form submission, you need a script to process the data. Create a new script named "Scoring" and link it to the form's output. Here's a basic example:


import abstra.workflows as aw

name = aw.get_data("name")
email = aw.get_data("email")
income = aw.get_data("income")
loan_amount = aw.get_data("loan_amount")

# Simple decision logic
if loan_amount > income * 0.8:
  decision = "Rejected"
elif loan_amount > income * 0.3:    
	decision = "Pending"
else:
	decision = "Approved"

aw.set_data("decision", decision)

4.3 Adding a Manual Review Step

If the decision is "Pending", you might want a manual review. Add and link to a new Conditional stage, and name your stage "Decision".

In the Conditional stage settings, edit the variable that decides which next step should be taken. In our case, let's use the variable decision.

Then, create another form named "Manual Review" for this purpose, and link your "Decision" stage to to that, defining the transition (arrow) as decision == "pending".

You can now add form logic to your newly created "Manual Review" form to retrieve the data from the previous steps, and handle how the manual review should run.


import abstra.forms as af
import abstra.workflows as aw

name = aw.get_data("name")
email = aw.get_data("email")
income = aw.get_data("income")
loan_amount = aw.get_data("loan_amount")
decision = aw.get_data("decision"

ans = Page() \
	.display_markdown("""
# Loan Request
----------------------------

## Personal Data

### Name: 
{name}
### Email: 
{email}

----------------------------

## Income Data

### Income: 
$ {income}

----------------------------

## Loan Data

### Loan amount: 
$ {loan_amount}

----------------------------

## Credit Engine Result

### Decision: 
{decision}

----------------------------
""") \         
	.read_multiple_choice("Approve request?", ["Yes", "No"], key="approved") \
  .run()

aw.set_data("final_decision", reviewer_decision)

Step 5: Deploying the Workflow

Once your workflow is set up, you can deploy it using the Abstra Cloud Console. Navigate to the console through the editor's navbar and press "Deploy". This action makes your workflow live and ready to use.

Step 6: Testing and Iteration

Test your workflow by navigating through each stage and ensuring that data passes correctly between forms and scripts. Make adjustments as needed based on the test results.

Final thoughts

This tutorial provided a basic overview of setting up a workflow in Abstra. You can expand upon this by integrating more complex logic, adding more stages, or connecting to external APIs. Abstra's flexibility and Python-based setup make it a powerful tool for automating a wide range of business processes.

If you'd like to understand how to adapt this workflow to your needs, you can book a technical onboarding here.