Skip to main content

Introduction to Frappe Framework

Frappe Framework is an open-source, full-stack, meta-data-driven web application framework built with Python and JavaScript. It powers ERPNext and enables rapid development of rich, scalable business applications. This guide focuses on Frappe Framework, tailored for ERP consultants, developers, and technical architects aiming to build, extend, or customize ERP solutions efficiently.

Introduction to Frappe Framework

Overview

Frappe Framework serves as the backbone of ERPNext, offering:

  • Meta-driven application design using DocTypes and Form Builders.
  • RESTful API out of the box for CRUD operations.
  • Role-based permissions for granular access control.
  • Built-in modules for database management, workflows, printing, email, and websites.
  • Extensive developer tools for rapid custom app development.

Installation / Setup

For setting up Frappe v15:

# Install bench
pip install frappe-bench
# Create bench directory
bench init frappe-bench --frappe-branch version-15
# Move into bench directory
cd frappe-bench
# Create new site
bench new-site yoursite.local
# Get ERPNext app if needed
bench get-app erpnext --branch version-15
bench --site yoursite.local install-app erpnext
# Start server
bench start

Configuration

Key configuration files include:

  • site_config.json: Database, Redis, developer mode settings.
  • Procfile: Defines process types for bench start.
  • hooks.py (in apps): Register events, overrides, scripts.

Functional Use

Frappe Framework enables:

  • App creation: Via bench new-app yourappname.
  • DocType creation: Using Desk UI > Developer > DocType.
  • Custom Scripts: JS scripts linked to DocTypes for client-side logic.
  • Workflows: Define state-based approval flows without custom code.
  • Printing: Jinja-based print formats configurable per DocType.

Developer Reference / API

Frappe v15 provides a robust REST API:

  • Authentication: Token-based or session.
  • Example GET Call:

curl -X GET https://yoursite.local/api/resource/Item \
-H "Authorization: token api_key:api_secret"

  • Example POST Call:

curl -X POST https://yoursite.local/api/resource/Item \
-H "Content-Type: application/json" \
-H "Authorization: token api_key:api_secret" \
-d '{"item_code": "Test Item", "item_name": "Test Item Name", "stock_uom": "Nos"}'

Source Reference: frappe/app.py – REST API Routes

Practical Use Case

Example: Automating Leave Application Approval

  1. DocType: Leave Application
  2. Workflow:
    • State: Applied ➡️ Approved ➡️ Rejected
    • Transitions: Only Managers can Approve/Reject.

Advanced Features

  • Event Hooks: Extend server logic without changing core code via hooks.py.
  • Job Queue: Schedule background jobs using Frappe’s Redis-based queue.
  • WebSockets: Real-time updates for notifications and dashboards.

Source Reference: frappe/frappe/hooks.py

Tips, Best Practices & Pitfalls

Tips

  • Always use version-specific branches to avoid compatibility issues (e.g. version-15).
  • Define permissions precisely in DocTypes to secure sensitive business data.
  • Test custom scripts thoroughly in developer mode before deploying to production.

Pitfalls

  • Avoid overriding core Frappe files; use hooks or custom apps for customization.
  • Monitor database migrations carefully when upgrading between major versions.
  • Use proper API authentication; exposing tokens in client-side code is a security risk.

References