How to Test Frappe Functions with the Console


Sometimes you want to quickly test a function in your custom Frappe app without setting up a full UI or writing extra boilerplate code. In this post, I’ll walk you through how to test your custom method using the Frappe console — a super useful tool for any Frappe developer.
Let’s say you’ve written a function inside this file:
apps/split/split/api.pyHere’s what the api.py file looks like:
import frappe
@frappe.whitelist()
def get_summary_for_session_user():
current_user = frappe.session.user
return get_summary_for_user(current_user)
def get_summary_for_user(current_user: str) -> dict:
print("current_user is:", current_user)
debit_amount = frappe.db.get_all(
"Split Ledger Entry",
filters={"debit_user": current_user},
fields=["amount as total_debit_amount", "currency", "credit_user"],
group_by="credit_user, currency"
)
credit_amount = frappe.db.get_all(
"Split Ledger Entry",
filters={"credit_user": current_user},
fields=["SUM(amount) as total_credit_amount", "currency", "debit_user"],
group_by="debit_user, currency"
)
print("debit_amount is:", debit_amount)
print("credit_amount is:", credit_amount)
return {
"debit": debit_amount,
"credit": credit_amount
}Before using the console, ensure your Frappe development server is up and running:
bench startOpen the Frappe console with your site using:
bench --site siteName console --autoreloadReplace siteName with the actual name of your site.
Since your function is located at apps/split/split/api.py, you can import and test it like this:
from split.api import get_summary_for_user
get_summary_for_user("nafis@gmail.com")You’ll get an output similar to:
current_user is: nafis@gmail.com
debit_amount is: [
{'total_debit_amount': 533.33, 'currency': 'BDT', 'credit_user': 's@gmail.com'},
{'total_debit_amount': 533.33, 'currency': 'BDT', 'credit_user': 'murad@gmail.com'},
{'total_debit_amount': 533.33, 'currency': 'BDT', 'credit_user': 'faisal@gmail.com'}
]
credit_amount is: [
{'total_credit_amount': 175.0, 'currency': 'BDT', 'debit_user': 'Administrator'},
{'total_credit_amount': 633.33, 'currency': 'USD', 'debit_user': 'Administrator'}
]That’s it! You now know how to test your custom Frappe methods directly from the console — a huge time saver for development and debugging.

Shadows disappearing in your Threlte or Three.js scene? It’s a frustum issue. Learn how to visualize the shadow box and fix clipping instantly with this guide.

What happens when you create a DocType in Frappe? We break down the .json, .js, and .py files generated by the framework and how to use them.

Confused by Shopify's lack of a database? 🤯 Learn how Shopify stores your theme data, from simple Settings to complex Metafields. Perfect for devs moving from WP/Laravel.