Script API

In the TechMaju platform, various Python modules and commands are available for use in in-app scripting. These tools are essential for customizing and automating functionalities within your TechMaju applications without the need to create a fully-featured application.

However, some commands are restricted in this context and more complex features should be implemented within dedicated applications using Python modules. Below is a detailed list of available modules and commands categorized by their functionalities.

Formatting

Function

Description

Example

_(Translate)

Translate a string

_("This is translatable")

frappe.format

Format a value based on its datatype

frappe.format_value(value,dict(fieldtype='Currency'))

frappe.date_format

Format as default date format


frappe.format_date

Returns date as "1st September 2019"


Session

Attribute/Function

Description

Example

frappe.form_dict

Form/request parameters

frappe.form_dict.name

frappe.request

Request object


frappe.response

Response object


frappe.session.user

Current user


frappe.session.csrf_token

CSRF token of the current session


frappe.user

Current user


frappe.get_fullname

Returns fullname of the current user


frappe.get_gravatar

Gets the user display image


frappe.full_name

Fullname of the current user


Documents (ORM)

Function

Description

Example

frappe.get_meta

Get metadata object


frappe.new_doc

Create a new Document record


frappe.get_doc

Get Document

frappe.get_doc("User", frappe.session.user)

frappe.get_last_doc

Get the last Document of a particular DocType

frappe.get_last_doc("User", filters={"name": ("like", "%@apple.com")})

frappe.get_cached_doc

Get Document (or cached)


frappe.get_mapped_doc

Get mapped document


frappe.rename_doc

Rename document


frappe.delete_doc

Delete document


frappe.get_system_settings

Get system default settings


Database

Function

Description

Example

frappe.db.get_list

Get list of records filtered by current user's permissions

frappe.db.get_list("Customer")

frappe.db.get_all

Get list of all records


frappe.db.sql

Run a SELECT query

frappe.db.sql("select name from Customer where name like 'm%'")

frappe.db.get_value

Get a value from a record

frappe.db.get_value("User", frappe.session.user, "first_name")

frappe.db.get_single_value

Get value from a single type document

frappe.db.get_single_value("System Settings", "default_currency")

frappe.db.get_default

Get default value


frappe.db.escape

Sanitize value for database queries


frappe.db.set_value

Set a value


frappe.db.exists

Checks for existence of a document


frappe.db.commit

Allow explicit commits in server scripts

Note: Does not work in DocType Event server scripts.

frappe.db.rollback

Allow rollback changes via server scripts

Note: Does not work in DocType Event server scripts.

Query Builder

Function

Description

Example

frappe.qb

Query builder API

frappe.qb.from_("Task").select("*").run()

Utilities

Function

Description

Example

mantera.exec_script

Executes a Script Function


run_script

Run a server script


frappe.msgprint

Show a modal on the server side

frappe.msgprint("Hello")

frappe.utils

Methods in frappe.utils


frappe.render_template

Render a Jinja template


frappe.get_url

Get URL of the current site


guess_mimetype

Returns mimetypes.guess_type


html2text

Encode HTML as text (markdown)


dev_server

True if in developer mode


frappe.log_error

Generate error log with traceback

frappe.log_error("Error")

API

Function

Description

Example

frappe.make_get_request

Make a GET request

frappe.make_get_request('https://example.com')

frappe.make_post_request

Make a POST request

frappe.make_post_request('https://example.com', data={'username: 'test'})

frappe.make_put_request

Make a PUT request

frappe.make_put_request('https://example.com', headers={'Auth': 'Bearer xyz'})

frappe.make_patch_request

Make a PATCH request


frappe.make_delete_request

Make a DELETE request


Email

Function

Description

Example

frappe.sendmail

Send an email

frappe.sendmail(recipients=['test@example.com'], sender='sender@example.com', subject='My Subject', message='<p>Hello</p>')

Discard
Save

On this page

Review Changes ← Back to Content
Message Status Space Raised By Last update on