frappe-syntax-serverscripts

Write RestrictedPython Server Scripts for Frappe and ERPNext events.

163|53|Updated Jan 14, 2026
One-click install
npx skills add https://github.com/Impertio-Studio/Frappe_Claude_Skill_Package --skill frappe-syntax-serverscripts-impertio-studio
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: frappe-syntax-serverscripts
Source: https://github.com/Impertio-Studio/Frappe_Claude_Skill_Package/tree/main/skills/source/syntax/frappe-syntax-serverscripts
Command: npx skills add https://github.com/Impertio-Studio/Frappe_Claude_Skill_Package --skill frappe-syntax-serverscripts-impertio-studio

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill prevents production-breaking mistakes when writing ERPNext/Frappe Server Script Python by enforcing the RestrictedPython sandbox rules, especially the critical ban on import statements.

Core Features & Use Cases

  • Sandbox-safe syntax: Ensures you never use import lines and instead rely on the pre-loaded frappe namespace and whitelisted utilities.
  • Correct event mapping: Clarifies how the Server Script UI event labels map to the internal lifecycle hooks (for example, “Before Save” → validate).
  • Role- and scenario-specific templates: Covers the right patterns for Document Events, API scripts, Scheduler events (including commit rules), and Permission Query conditions.
  • Production-ready guardrails: Reinforces key anti-patterns such as no doc.save() in Before Save and no frappe.db.commit() in Document Events.

Quick Start

Use the frappe-syntax-serverscripts skill when generating Python code for a Server Script and ask: “Write a Frappe Server Script for event ‘Before Save’ on DocType Sales Invoice that validates grand_total is non-negative without using any imports.”

Frequently Asked Questions about frappe-syntax-serverscripts

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a Frappe Server Script without using import statements?

To write a Frappe Server Script without imports, rely entirely on the pre-loaded `frappe` namespace and whitelisted utilities. Avoiding imports is required because the RestrictedPython sandbox blocks them to prevent unsafe operations.

Why does my Frappe Server Script fail on 'Before Save' when calling doc.save()?

Calling `doc.save()` inside a 'Before Save' event causes a recursive loop and production failure. 'Before Save' maps to the internal `validate` hook, so you must modify properties directly without triggering another save action.

How do I map Frappe Server Script UI event labels to internal lifecycle hooks?

To map Frappe Server Script UI event labels to internal lifecycle hooks, match the UI selection to the underlying docstate action, such as mapping 'Before Save' to the `validate` hook or 'After Insert' to `on_update`.

Can I use frappe.db.commit() in ERPNext Document Event Server Scripts?

You cannot use `frappe.db.commit()` in ERPNext Document Event Server Scripts. Manual commits are restricted, but Scheduler event scripts require applying specific commit rules to ensure database transactions are finalized safely.

What is the correct way to run parameterized SQL in Frappe Server Scripts?

The correct way to run parameterized SQL in Frappe Server Scripts is to use the pre-loaded `frappe.db.sql` method with standard parameter binding. This ensures SQL safety by preventing injection within the RestrictedPython sandbox.

Does RestrictedPython sandbox rules block standard libraries in Frappe Server Scripts?

RestrictedPython sandbox rules block standard libraries in Frappe Server Scripts by restricting all import statements. Developers must use only the pre-loaded `frappe` namespace and approved whitelisted utilities to execute logic safely.