Version 6.x.x Source

Introduction


globals attached to frappe module + some utility functions that should probably be moved



frappe._ (msg, lang=None)

Returns translated string in current lang, if exists.


Class _dict

Inherits from __builtin__.dict

dict like object that exposes keys as attributes

__getattr__ (self, key)

No docs


__getstate__ (self)

No docs


__setattr__ (self, key, value)

No docs


__setstate__ (self, d)

No docs


copy (self)

No docs


update (self, d)

update and return self -- the missing dict feature in python



frappe.add_version (doc)

Insert a new Version of the given document. A Version is a JSON dump of the current document state.


frappe.are_emails_muted ()

No docs


frappe.as_json (obj, indent=1)

No docs


frappe.attach_print (doctype, name, file_name=None, print_format=None, style=None, html=None)

No docs


frappe.build_match_conditions (doctype, as_condition=True)

Return match (User permissions) for given doctype as list or SQL.


frappe.cache ()

Returns memcache connection.


frappe.call (fn)

Call a function and match arguments.


frappe.clear_cache (user=None, doctype=None)

Clear User, DocType or global cache.

Parameters:


frappe.compare (val1, condition, val2)

Compare two values using frappe.utils.compare

condition could be: - "^" - "in" - "not in" - "=" - "!=" - ">" - "<" - ">=" - "<=" - "not None" - "None"


frappe.connect (site=None, db_name=None)

Connect to site database instance.

Parameters:


frappe.copy_doc (doc, ignore_no_copy=True)

No_copy fields also get copied.


frappe.create_folder (path, with_init=False)

Create a folder in the given path and add an __init__.py file (optional).

Parameters:


frappe.delete_doc (doctype=None, name=None, force=0, ignore_doctypes=None, for_reload=False, ignore_permissions=False, flags=None)

Delete a document. Calls frappe.model.delete_doc.delete_doc.

Parameters:


frappe.delete_doc_if_exists (doctype, name, force=0)

Delete document if exists.


frappe.destroy ()

Closes connection and releases werkzeug local.


frappe.errprint (msg)

Log error. This is sent back as exc in response.

Parameters:


frappe.format_value (value, df, doc=None, currency=None)

Format value with given field properties.

Parameters:


frappe.generate_hash (txt=None, length=None)

Generates random hash for given text + current timestamp + random string.


frappe.get_all (doctype)

List database query via frappe.model.db_query. Will not check for conditions. Parameters are same as frappe.get_list

Parameters:

Example usage:

# simple dict filter
frappe.get_all("ToDo", fields=["name", "description"], filters = {"owner":"test@example.com"})

# filter as a list of lists
frappe.get_all("ToDo", fields=["*"], filters = [["modified", ">", "2014-01-01"]])

# filter as a list of dicts
frappe.get_all("ToDo", fields=["*"], filters = {"description": ("like", "test%")})

frappe.get_all_apps (with_frappe=False, with_internal_apps=True, sites_path=None)

Get list of all apps via sites/apps.txt.


frappe.get_app_path (app_name)

Return path of given app.

Parameters:


frappe.get_attr (method_string)

Get python method object from its name.


frappe.get_doc (arg1, arg2=None)

Return a frappe.model.document.Document object of the given type and name.

Parameters:

Examples:

# insert a new document
todo = frappe.get_doc({"doctype":"ToDo", "description": "test"})
tood.insert()

# open an existing document
todo = frappe.get_doc("ToDo", "TD0001")

frappe.get_doctype_app (doctype)

No docs


frappe.get_file_items (path, raise_not_found=False, ignore_empty_lines=True)

Returns items from text file as a list. Ignores empty lines.


frappe.get_file_json (path)

Read a file and return parsed JSON object.


frappe.get_hooks (hook=None, default=None, app_name=None)

Get hooks via app/hooks.py

Parameters:


frappe.get_installed_apps (sort=False, frappe_last=False)

Get list of installed apps in current site.


frappe.get_lang_dict (fortype, name=None)

Returns the translated language dict for the given type and name.

Parameters:


frappe.get_last_doc (doctype)

Get last created document of this type.


frappe.get_list (doctype)

List database query via frappe.model.db_query. Will also check for permissions.

Parameters:

Example usage:

# simple dict filter
frappe.get_list("ToDo", fields=["name", "description"], filters = {"owner":"test@example.com"})

# filter as a list of lists
frappe.get_list("ToDo", fields="*", filters = [["modified", ">", "2014-01-01"]])

# filter as a list of dicts
frappe.get_list("ToDo", fields="*", filters = {"description": ("like", "test%")})

frappe.get_logger (module=None)

No docs


frappe.get_meta (doctype, cached=True)

Get frappe.model.meta.Meta instance of given doctype name.


frappe.get_meta_module (doctype)

No docs


frappe.get_module (modulename)

Returns a module object for given Python module name using importlib.import_module.


frappe.get_module_list (app_name)

Get list of modules for given all via app/modules.txt.


frappe.get_module_path (module)

Get the path of the given module name.

Parameters:


frappe.get_precision (doctype, fieldname, currency=None, doc=None)

Get precision for a given field


frappe.get_print (doctype, name, print_format=None, style=None, html=None, as_pdf=False)

Get Print Format for given document.

Parameters:


frappe.get_pymodule_path (modulename)

Return path of given Python module name.

Parameters:


frappe.get_request_header (key, default=None)

Return HTTP request header.

Parameters:


frappe.get_roles (username=None)

Returns roles of current user.


frappe.get_single (doctype)

Return a frappe.model.document.Document object of the given Single doctype.


frappe.get_site_config (sites_path=None, site_path=None)

Returns site_config.json combined with sites/common_site_config.json. site_config is a set of site wide settings like database name, password, email etc.


frappe.get_site_path ()

Return path of current site.

Parameters:


frappe.get_test_records (doctype)

Returns list of objects from test_records.json in the given doctype's folder.


frappe.get_traceback ()

Returns error traceback.


frappe.get_user ()

No docs


frappe.get_value ()

Returns a document property or list of properties.

Alias for frappe.db.get_value

Parameters:


frappe.has_permission (doctype, ptype=read, doc=None, user=None, verbose=False, throw=False)

Raises frappe.PermissionError if not permitted.

Parameters:


frappe.has_website_permission (doctype, ptype=read, doc=None, user=None, verbose=False)

Raises frappe.PermissionError if not permitted.

Parameters:


frappe.import_doc (path, ignore_links=False, ignore_insert=False, insert=False)

Import a file using Data Import Tool.


frappe.init (site, sites_path=None)

Initialize frappe for the current site. Reset thread locals frappe.local


frappe.is_table (doctype)

Returns True if istable property (indicating child Table) is set for given DocType.


frappe.local_cache (namespace, key, generator, regenerate_if_none=False)

A key value store for caching within a request

Parameters:


frappe.log (msg)

Add to debug_log.

Parameters:


frappe.make_property_setter (args, ignore_validate=False, validate_fields_for_doctype=True)

Create a new Property Setter (for overriding DocType and DocField properties).


frappe.msgprint (msg, small=0, raise_exception=0, as_table=False)

Print a message to the user (via HTTP response). Messages are sent in the __server_messages property in the response JSON and shown in a pop-up / modal.

Parameters:


frappe.new_doc (doctype, parent_doc=None, parentfield=None, as_dict=False)

Returns a new document of the given DocType with defaults set.

Parameters:


frappe.only_for (roles)

Raise frappe.PermissionError if the user does not have any of the given Roles.

Parameters:


frappe.publish_realtime ()

Publish real-time updates

Parameters:


frappe.read_file (path, raise_not_found=False)

Open a file and return its content as Unicode.


frappe.reload_doc (module, dt=None, dn=None, force=False)

Reload Document from model ([module]/[doctype]/[name]/[name].json) files.

Parameters:


frappe.reload_doctype (doctype, force=False)

Reload DocType from model ([module]/[doctype]/[name]/[name].json) files.


frappe.rename_doc (doctype, old, new, debug=0, force=False, merge=False, ignore_permissions=False)

Rename a document. Calls frappe.model.rename_doc.rename_doc


frappe.reset_metadata_version ()

Reset metadata_version (Client (Javascript) build ID) hash.


frappe.respond_as_web_page (title, html, success=None, http_status_code=None)

Send response as a web page with a message rather than JSON. Used to show permission errors etc.

Parameters:


frappe.scrub (txt)

Returns sluggified string. e.g. Sales Order becomes sales_order.


frappe.sendmail (recipients=(), sender=, subject=No Subject, message=No Message, as_markdown=False, bulk=False, reference_doctype=None, reference_name=None, unsubscribe_method=None, unsubscribe_params=None, unsubscribe_message=None, attachments=None, content=None, doctype=None, name=None, reply_to=None, cc=(), show_as_cc=(), message_id=None, as_bulk=False, send_after=None, expose_recipients=False, bulk_priority=1)

Send email using user's default Email Account or global default Email Account.

Parameters:


frappe.set_user (username)

Set current user.

Parameters:


frappe.set_user_lang (user, user_language=None)

Guess and set user language for the session. frappe.local.lang


frappe.set_value (doctype, docname, fieldname, value)

Set document value. Calls frappe.client.set_value


frappe.setup_module_map ()

Rebuild map of all modules (internal).


frappe.throw (msg, exc=)

Throw execption and show message (msgprint).

Parameters:


frappe.unscrub (txt)

Returns titlified string. e.g. sales_order becomes Sales Order.


frappe.whitelist (allow_guest=False, xss_safe=False)

Decorator for whitelisting a function and making it accessible via HTTP. Standard request will be /api/method/[path.to.method]

Parameters:

Use as:

@frappe.whitelist()
def myfunc(param1, param2):
    pass