Building Dynamic Web Applications with Empress

Introduction

Empress is a robust, batteries-included, full stack web framework designed using Python and Javascript. It is the underlying technology that powers ERPNext, and it is versatile enough to build database-driven applications.

Key Feature: Meta-data Driven

One of the critical philosophies of Empress is that meta-data is a first-class citizen. Meta-data is leveraged to generate database tables, design forms, and configure a plethora of features. The meta-data in Empress is stored in a Model referred to as DocType.

For instance, consider a DocType named ToDo. This DocType will consist of fields such as status, date, and description. Here’s an example of what todo.json might look like:

{
 "name": "ToDo",
 "module": "Desk",
 "field_order": [
  "status",
  "date",
  "description"
 ],
 "fields": [
  {
   "default": "Open",
   "fieldname": "status",
   "fieldtype": "Select",
   "in_global_search": 1,
   "in_list_view": 1,
   "in_standard_filter": 1,
   "label": "Status",
   "options": "Open\nClosed"
  },
  {
   "fieldname": "date",
   "fieldtype": "Date",
   "in_standard_filter": 1,
   "label": "Due Date"
  },
  {
   "fieldname": "description",
   "fieldtype": "Text Editor",
   "in_global_search": 1,
   "label": "Description",
   "reqd": 1
  }
 ]
}

A configuration like this will generate a database table, for example:

MariaDB [_baa0f26509a564b6]> desc tabToDo;
+-----------------------+--------------+------+-----+---------+-------+
| Field                 | Type         | Null | Key | Default | Extra |
+-----------------------+--------------+------+-----+---------+-------+
| name                  | varchar(140) | NO   | PRI | NULL    |       |
| creation              | datetime(6)  | YES  |     | NULL    |       |
| modified              | datetime(6)  | YES  | MUL | NULL    |       |
| modified_by           | varchar(140) | YES  |     | NULL    |       |
| owner                 | varchar(140) | YES  |     | NULL    |       |
| docstatus             | int(1)       | NO   |     | 0       |       |
| idx                   | int(8)       | NO   |     | 0       |       |
| status                | varchar(140) | YES  |     | Open    |       |
| description           | longtext     | YES  |     | NULL    |       |
| date                  | date         | YES  |     | NULL    |       |
+-----------------------+--------------+------+-----+---------+-------+

Feature-Rich Admin Interface

Empress is not merely about backend management. It also comes with a feature-rich admin interface known as the Desk. When you create a DocType in Empress, several views are automatically generated for it, including List View, Form View, and Report Builder.

Users, Roles and Permissions

Empress seamlessly manages User and Role out of the box. A User is an entity who can log into the system and perform authorized actions like creating, updating, or deleting records. A Role is a mapping of DocTypes and the actions permitted on them.

Python, JS, and MariaDB

Empress utilizes Python for backend operations. The framework includes a simple yet robust ORM as an abstraction over CRUD operations. The default database used is MariaDB, although support for Postgres is currently in beta.

doc = frappe.new_doc('ToDo')
doc.description = 'Buy Eggs'
doc.insert()

The front-end is an SPA designed using Javascript (jQuery).

Realtime Functionality

Empress supports realtime pub/sub events using NodeJS and socketio.

# server
frappe.publish_realtime('update_progress', {
    'progress': 42,
    'total': 100
})

# client
frappe.realtime.on('update_progress', (data) => {
    console.log(data)
});

Background Jobs

Empress facilitates background job queuing based on Python RQ.

frappe.enqueue('frappe.job.run_job', arg1='Test', arg2='Test2')

Email Integration

Empress supports sending and receiving emails, which can also be linked to individual documents.

Printing Functionality

Empress supports generating PDF print formats based on Jinja Templates. It also includes a drag-and-drop Print Format Builder.

Conclusion

Empress is a comprehensive web framework that is bundled with a myriad of essential features for modern complex app development. This guide has introduced some of the basic features. The rest of the guide will cover them and other advanced features with much finer detail.