### Install and list apps Source: https://docs.frappe.io/framework/user/en/tutorial/create-a-site Commands to install an application on a site and verify the installation. ```bash $ bench --site library.localhost install-app library_management Installing library_management... ``` ```bash $ bench --site library.localhost list-apps frappe library_management ``` -------------------------------- ### App Installation and Build Source: https://docs.frappe.io/framework/user/en/tutorial/create-an-app Install the newly created app and build its assets. ```bash Installing library_management $ ./env/bin/pip install -q -U -e ./apps/library_management $ bench build --app library_management yarn run v1.22.4 $ FRAPPE_ENV=production node rollup/build.js --app library_management Production mode ✔ Built js/moment-bundle.min.js ✔ Built js/libs.min.js ✨ Done in 1.95s. ``` -------------------------------- ### Setup Let's Encrypt SSL using Bench Command Source: https://docs.frappe.io/framework/user/en/bench/guides/lets-encrypt-ssl-setup.html Use this command to automate the Let's Encrypt SSL setup for your site. It handles certificate generation and renewal setup. ```bash sudo -H bench setup lets-encrypt [site-name] ``` -------------------------------- ### Setup Bench Manager Source: https://docs.frappe.io/framework/user/en/bench/bench-commands Installs the Bench Manager UI for managing bench operations. This provides a web-based interface for deployment management. ```zsh ➜ bench setup manager ``` -------------------------------- ### Create Site and Install App Source: https://docs.frappe.io/framework/user/en/bench/reference/new-site This command creates a new site and automatically installs a specified app that is available in the current bench. ```bash bench new-site {site} --install-app {app} ``` -------------------------------- ### Install Bench CLI Source: https://docs.frappe.io/framework/user/en/installation Installs the Frappe Bench CLI tool using UV. ```bash uv tool install frappe-bench ``` -------------------------------- ### Install an app to a site Source: https://docs.frappe.io/framework/user/en/guides/basics/apps Commands to download an app from a repository and install it onto a specific site. ```bash bench get-app https://github.com/org/app_name ``` ```bash bench --site site_name install-app app_name ``` -------------------------------- ### Execute Setup Commands Source: https://docs.frappe.io/framework/user/en/bench/bench-commands General syntax for running environment setup commands within the current bench context. ```zsh ➜ bench setup COMMAND [ARGS]... ``` -------------------------------- ### Install an app on a site Source: https://docs.frappe.io/framework/user/en/bench/frappe-commands Installs an application's meta, modules, and doctypes onto a specific site. ```bash bench --site {site} install-app {app} ``` -------------------------------- ### Initialize Frappe Bench Setup Source: https://docs.frappe.io/framework/user/en/basics/architecture Use this command to create a new Frappe-bench setup, which includes directory structures for sites and apps, a Python virtual environment, and configuration files. ```sh bench init frappe-bench ``` -------------------------------- ### Manage App Installation Lifecycle Source: https://docs.frappe.io/framework/user/en/python-api/hooks Define hooks to execute custom logic before or after app installation and synchronization. ```python # python module path before_install = "app.setup.install.before_install" after_install = "app.setup.install.after_install" after_sync = "app.setup.install.after_sync" ``` ```python # will run before app is installed on site def before_install(): pass # will run after app is installed on site def after_install(): pass # will run after app fixtures are synced def after_sync(): pass ``` -------------------------------- ### Install Python via UV Source: https://docs.frappe.io/framework/user/en/installation Installs the default Python version using UV. ```bash uv python install 3.14 --default ``` -------------------------------- ### Execute Install Commands Source: https://docs.frappe.io/framework/user/en/bench/bench-commands General syntax for installing system dependencies required for the Frappe environment. ```bash bench install COMMAND [ARGS]... ``` -------------------------------- ### Install Bench for Production Source: https://docs.frappe.io/framework/user/en/production-setup Use this command to install Bench with production configurations. Replace '[frappe-user]' with your desired user. ```bash sudo python install.py --production --user [frappe-user] ``` -------------------------------- ### Site Configuration Example Source: https://docs.frappe.io/framework/user/en/basics/site_config This is an example of a site_config.json file, which stores site-specific information like database credentials and admin passwords. ```json { "db_name": "frappe_database_name", "db_password": "frappe_database_password", "admin_password": "admin_password" } ``` -------------------------------- ### Start the Frappe Bench Server Source: https://docs.frappe.io/framework/user/en/bench/bench-commands Starts the bench server, making Frappe/ERPNext accessible via a web browser. Access the site at `localhost:8000`. ```zsh ➜ bench start ``` -------------------------------- ### Check Bench Installation Source: https://docs.frappe.io/framework/user/en/tutorial/install-and-setup-bench Verify that Bench has been installed correctly by checking its version. This command should be run after completing the initial installation. ```bash $ bench --version 5.1.0 ``` -------------------------------- ### Install NVM Source: https://docs.frappe.io/framework/user/en/installation Installs the Node Version Manager. ```bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.3/install.sh | bash ``` -------------------------------- ### Common Site Configuration Example Source: https://docs.frappe.io/framework/user/en/basics/site_config This example demonstrates a common_site_config.json file, used for bench-wide settings. It includes configurations for background workers, developer mode, Redis connections, and ports. ```json { "background_workers": 1, "developer_mode": true, "dns_multitenant": true, "file_watcher_port": 6789, "frappe_user": "frappe", "gunicorn_workers": 2, "maintenance_mode": 0, "pause_scheduler": 0, "redis_cache": "redis://localhost:13000", "redis_cache_sentinel_enabled": 1, "redis_cache_sentinels": [ "redis-cache-sentinel-1:26379", "redis-cache-sentinel-2:26379" ], "redis_cache_sentinel_password": "sentinelpassword", "redis_cache_master_service": "mymaster", "redis_cache_master_password": "masterpassword", "redis_queue": "redis://localhost:11000", "redis_queue_sentinel_enabled": 1, "redis_queue_sentinels": [ "redis-queue-sentinel-1:26379", "redis-queue-sentinel-2:26379" ], "redis_queue_sentinel_password": "sentinelpassword", "redis_queue_master_service": "mymaster", "redis_queue_master_password": "masterpassword", "redis_socketio": "redis://localhost:12000", "scheduler_tick_interval": 120, "serve_default_site": true, "socketio_port": 9000, "webserver_port": 8000, "root_password": "MARIADB_PASSWORD", "live_reload": true } ``` -------------------------------- ### Install Node.js via NVM Source: https://docs.frappe.io/framework/user/en/installation Installs the specified version of Node.js. ```bash nvm install 24 ``` -------------------------------- ### Start Frappe Development Server Source: https://docs.frappe.io/framework/user/en/tutorial/install-and-setup-bench Navigate into the 'frappe-bench' directory and start the Frappe web server. This command also initiates various background services like Redis, Socket.IO, and worker processes. ```bash cd frappe-bench bench start ``` -------------------------------- ### Start development environment with bench Source: https://docs.frappe.io/framework/user/en/debugging The bench start command initiates all processes defined in the Procfile, displaying their output in the terminal. ```bash ▶ bench start 14:55:17 system | redis_cache.1 started (pid=4085) 14:55:17 system | redis_socketio.1 started (pid=4086) 14:55:17 system | redis_queue.1 started (pid=4088) 14:55:17 system | web.1 started (pid=4089) 14:55:17 system | socketio.1 started (pid=4090) 14:55:17 system | watch.1 started (pid=4094) 14:55:17 system | worker_short.1 started (pid=4096) 14:55:17 system | schedule.1 started (pid=4095) 14:55:17 redis_queue.1 | 4088:C 22 May 14:55:17.257 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 14:55:17 redis_queue.1 | 4088:C 22 May 14:55:17.264 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=4088, just started 14:55:17 redis_queue.1 | 4088:C 22 May 14:55:17.264 # Configuration loaded 14:55:17 redis_queue.1 | 4088:M 22 May 14:55:17.265 * Increased maximum number of open files to 10032 (it was originally set to 4864). 14:55:17 redis_cache.1 | 4085:C 22 May 14:55:17.262 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 14:55:17 redis_cache.1 | 4085:C 22 May 14:55:17.268 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=4085, just started 14:55:17 redis_cache.1 | 4085:C 22 May 14:55:17.268 # Configuration loaded 14:55:17 redis_cache.1 | 4085:M 22 May 14:55:17.269 * Increased maximum number of open files to 10032 (it was originally set to 4864). 14:55:17 redis_socketio.1 | 4086:C 22 May 14:55:17.262 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 14:55:17 redis_socketio.1 | 4086:C 22 May 14:55:17.270 # Redis version=4.0.11, bits=64, commit=00000000, modified=0, pid=4086, just started 14:55:17 redis_socketio.1 | 4086:C 22 May 14:55:17.270 # Configuration loaded 14:55:17 redis_socketio.1 | 4086:M 22 May 14:55:17.272 * Increased maximum number of open files to 10032 (it was originally set to 4864). 14:55:17 redis_queue.1 | 4088:M 22 May 14:55:17.285 * Running mode=standalone, port=11002. 14:55:17 redis_queue.1 | 4088:M 22 May 14:55:17.285 # Server initialized 14:55:17 redis_queue.1 | 4088:M 22 May 14:55:17.286 * Ready to accept connections 14:55:17 redis_cache.1 | 4085:M 22 May 14:55:17.287 * Running mode=standalone, port=13002. 14:55:17 redis_cache.1 | 4085:M 22 May 14:55:17.292 # Server initialized 14:55:17 redis_cache.1 | 4085:M 22 May 14:55:17.292 * Ready to accept connections 14:55:17 redis_socketio.1 | 4086:M 22 May 14:55:17.294 * Running mode=standalone, port=12002. 14:55:17 redis_socketio.1 | 4086:M 22 May 14:55:17.294 # Server initialized 14:55:17 redis_socketio.1 | 4086:M 22 May 14:55:17.295 * Ready to accept connections 14:55:17 system | worker_long.1 started (pid=4098) 14:55:17 system | worker_default.1 started (pid=4100) 14:55:18 socketio.1 | listening on *: 9002 14:55:20 socketio.1 | { Error: connect ECONNREFUSED 0.0.0.0:8002 14:55:20 socketio.1 | at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1191:14) 14:55:20 socketio.1 | errno: 'ECONNREFUSED', 14:55:20 socketio.1 | code: 'ECONNREFUSED', 14:55:20 socketio.1 | syscall: 'connect', 14:55:20 socketio.1 | address: '0.0.0.0', 14:55:20 socketio.1 | port: 8002, 14:55:20 socketio.1 | response: undefined } 14:55:24 web.1 | * Running on http://0.0.0.0:8002/ (Press CTRL+C to quit) 14:55:24 web.1 | * Restarting with fsevents reloader 14:55:24 watch.1 | yarn run v1.10.1 14:55:24 watch.1 | $ node rollup/watch.js 14:55:25 web.1 | * Debugger is active! 14:55:25 web.1 | * Debugger PIN: 321-355-865 14:55:26 watch.1 | 14:55:26 watch.1 | Rollup Watcher Started 14:55:26 watch.1 | 14:55:26 watch.1 | Watching... 14:55:26 watch.1 | Rebuilding frappe-web.css 14:55:27 watch.1 | Rebuilding frappe-web-b4.css 14:55:27 watch.1 | Rebuilding chat.js 14:55:28 web.1 | 14:55:28 web.1 | test print ``` -------------------------------- ### List Installed Apps on a Site Source: https://docs.frappe.io/framework/user/en/basics/apps Verify that an app has been installed correctly by listing all apps associated with a site. ```bash $ bench --site site_name list-apps frappe custom_app ``` -------------------------------- ### Install wkhtmltopdf Package on Debian/Ubuntu Source: https://docs.frappe.io/framework/user/en/installation Installs the downloaded wkhtmltopdf .deb file. ```bash sudo dpkg -i wkhtmltox_file.deb ``` -------------------------------- ### Bench Configuration and Setup Source: https://docs.frappe.io/framework/user/en/bench/resources/bench-commands-cheatsheet Commands for configuring bench settings and setting up system components. ```APIDOC ## CLI: bench setup ### Description Setup various components for the bench environment. ### Subcommands - **auto-update** - Add cronjob for bench auto update. - **backups** - Add cronjob for bench backups. - **nginx** - Generate config for nginx. - **production** - Setup bench for production. - **redis** - Generate config for redis cache. - **supervisor** - Generate config for supervisor. - **requirements** - Update Python and Node packages. ``` -------------------------------- ### Install an App into a Frappe Site Source: https://docs.frappe.io/framework/user/en/basics/apps Run this command to install a Frappe app onto a specific site. This creates the app's models in the site's database. ```bash $ bench --site site_name install-app custom_app Installing custom_app... ``` -------------------------------- ### Install Debian/Ubuntu System Packages Source: https://docs.frappe.io/framework/user/en/installation Installs essential system packages including git, redis, and MariaDB. ```bash sudo apt install git redis-server libmariadb-dev mariadb-server mariadb-client pkg-config ``` -------------------------------- ### Example: Set User Limit for a Site Source: https://docs.frappe.io/framework/user/en/bench/guides/settings-limits This is a practical example of setting the maximum number of users allowed for a specific site using the bench set-limit command. ```bash bench --site site1.local set-limit users 5 ``` -------------------------------- ### Site configuration file Source: https://docs.frappe.io/framework/user/en/tutorial/create-a-site Example of the site_config.json file containing database credentials. ```json { "db_name": "_ad03fa1a016ca1c4", "db_password": "pz1d2gN5y35ydRO5", "db_type": "mariadb" } ``` -------------------------------- ### Install Development Dependencies Source: https://docs.frappe.io/framework/user/en/guides/app-development/how-enable-developer-mode-in-frappe Command to install additional dependencies required for development and testing. ```bash bench setup requirements --dev ``` -------------------------------- ### Install App After Restore Source: https://docs.frappe.io/framework/user/en/bench/reference/restore Specify an app to be installed automatically after the site restore process is complete. This is useful for setting up a site with specific applications. ```bash bench --site {site} restore {path/to/database/file} --install-app {app} ``` -------------------------------- ### Advanced Setup Commands Source: https://docs.frappe.io/framework/user/en/bench/bench-commands Commands for configuring NGINX, SSL, Redis, and site-specific settings. ```APIDOC ## bench [ADVANCED_COMMAND] ### Description Advanced configuration commands for setting up production environments and infrastructure settings. ### Commands - **set-nginx-port**: Set NGINX port for site. - **set-ssl-certificate**: Set SSL certificate path for site. - **set-ssl-key**: Set SSL certificate private key path for site. - **set-mariadb-host**: Set MariaDB host for bench. - **set-redis-cache-host**: Set Redis cache host for bench. - **use**: Set default site for bench. ``` -------------------------------- ### Define Translation Context Examples Source: https://docs.frappe.io/framework/user/en/guides/basics/translations Examples showing how to use context to differentiate between identical source strings with different meanings. ```text "charge","شحن","" "charge","رسوم","" ``` ```text "charge","شحن","mobile phone charge" "charge","رسوم","invoice line" ``` ```python _("charge") # here we don't know which meaning (context to use) _("charge", context="mobile phone charge") # here we mean شحن _("charge", context="invoice line") # here we mean رسوم ``` -------------------------------- ### Install an App on a Site Source: https://docs.frappe.io/framework/user/en/bench/bench-commands Installs a previously added Frappe app onto a specific site within the bench. This makes the app's features available on that site. ```zsh ➜ bench --site site1.local install-app erpnext ``` -------------------------------- ### Python Bearer Token Authentication Example Source: https://docs.frappe.io/framework/user/en/guides/integration/rest_api/token_based_authentication Example of making a GET request using Bearer token authentication in Python. Replace 'access_token' with your actual token. ```python import requests import base64 url = "http://frappe.local:8000**/api/method/frappe.auth.get_logged_user**" headers = { "Authorization": "Bearer %s" % access_token } response = requests.request("GET", url, headers=headers) ``` -------------------------------- ### Python Token Authentication Example Source: https://docs.frappe.io/framework/user/en/guides/integration/rest_api/token_based_authentication Example of making a GET request using token authentication in Python. Ensure you replace placeholders with your actual API key and secret. ```python import requests url = "http://frappe.local:8000/api/method/frappe.auth.get_logged_user" headers = { 'Authorization': "token :" } response = requests.request("GET", url, headers=headers) ``` -------------------------------- ### Python Basic Authentication Example Source: https://docs.frappe.io/framework/user/en/guides/integration/rest_api/token_based_authentication Example of making a GET request using Basic authentication in Python. The API key and secret are combined, base64 encoded, and then sent in the header. ```python import requests import base64 url = "http://frappe.local:8000**/api/method/frappe.auth.get_logged_user**" headers = { 'Authorization': "Basic %s" % base64.b64encode(:) } response = requests.request("GET", url, headers=headers) ``` -------------------------------- ### Create a new site Source: https://docs.frappe.io/framework/user/en/tutorial/create-a-site Initializes a new site database and sets up the administrator password. ```bash $ bench new-site library.localhost MySQL root password: Installing frappe... Updating DocTypes for frappe : [========================================] 100% Set Administrator password: *** Scheduler is disabled *** Current Site set to library.localhost ``` -------------------------------- ### Define DocType Unit Tests Source: https://docs.frappe.io/framework/user/en/guides/automated-testing/unit-testing Example implementation of a test suite for an Event DocType, including setup, teardown, and permission validation. ```python # Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors # MIT License. See license.txt import frappe import frappe.defaults from frappe.tests.utils import FrappeTestCase def create_events(): if frappe.flags.test_events_created: return frappe.set_user("Administrator") doc = frappe.get_doc({ "doctype": "Event", "subject":"_Test Event 1", "starts_on": "2014-01-01", "event_type": "Public" }).insert() doc = frappe.get_doc({ "doctype": "Event", "subject":"_Test Event 2", "starts_on": "2014-01-01", "event_type": "Private" }).insert() doc = frappe.get_doc({ "doctype": "Event", "subject":"_Test Event 3", "starts_on": "2014-01-01", "event_type": "Public" "event_individuals": [{ "person": "test1@example.com" }] }).insert() frappe.flags.test_events_created = True class TestEvent(FrappeTestCase): def setUp(self): create_events() def tearDown(self): frappe.set_user("Administrator") def test_allowed_public(self): frappe.set_user("test1@example.com") doc = frappe.get_doc("Event", frappe.db.get_value("Event", {"subject":"_Test Event 1"})) self.assertTrue(frappe.has_permission("Event", doc=doc)) def test_not_allowed_private(self): frappe.set_user("test1@example.com") doc = frappe.get_doc("Event", frappe.db.get_value("Event", {"subject":"_Test Event 2"})) self.assertFalse(frappe.has_permission("Event", doc=doc)) def test_allowed_private_if_in_event_user(self): doc = frappe.get_doc("Event", frappe.db.get_value("Event", {"subject":"_Test Event 3"})) frappe.set_user("test1@example.com") self.assertTrue(frappe.has_permission("Event", doc=doc)) def test_event_list(self): frappe.set_user("test1@example.com") res = frappe.get_list("Event", filters=[["Event", "subject", "like", "_Test Event%"]], fields=["name", "subject"]) self.assertEqual(len(res), 2) subjects = [r.subject for r in res] self.assertTrue("_Test Event 1" in subjects) self.assertTrue("_Test Event 3" in subjects) self.assertFalse("_Test Event 2" in subjects) ``` -------------------------------- ### Define a DocType test file Source: https://docs.frappe.io/framework/user/en/testing Example of a test file for an Event DocType, including setup and teardown methods to manage test data. ```python import frappe import unittest def create_events(): if frappe.flags.test_events_created: return frappe.set_user("Administrator") doc = frappe.get_doc({ "doctype": "Event", "subject":"_Test Event 1", "starts_on": "2014-01-01", "event_type": "Public" }).insert() doc = frappe.get_doc({ "doctype": "Event", "subject":"_Test Event 3", "starts_on": "2014-01-01", "event_type": "Public" "event_individuals": [{ "person": "test1@example.com" }] }).insert() frappe.flags.test_events_created = True class TestEvent(unittest.TestCase): def setUp(self): create_events() def tearDown(self): frappe.set_user("Administrator") def test_allowed_public(self): frappe.set_user("test1@example.com") doc = frappe.get_doc("Event", frappe.db.get_value("Event", {"subject":"_Test Event 1"})) self.assertTrue(frappe.has_permission("Event", doc=doc)) def test_not_allowed_private(self): frappe.set_user("test1@example.com") doc = frappe.get_doc("Event", frappe.db.get_value("Event", {"subject":"_Test Event 2"})) self.assertFalse(frappe.has_permission("Event", doc=doc)) ``` -------------------------------- ### Access Token Authentication Source: https://docs.frappe.io/framework/user/en/api/rest To access the API, you need to include an 'Authorization' header with your 'access_token'. Refer to the OAuth setup guide for details on obtaining a token. ```APIDOC ## Access Token Authentication Refer documentation for [How to setup OAuth](/framework/v14/user/en/guides/integration/how_to_set_up_oauth.md). Use the generated `access_token` in request header. ```javascript fetch('http:///api/method/frappe.auth.get_logged_user', { headers: { 'Authorization': 'Bearer access_token' } }) .then(r => r.json()) .then(r => { console.log(r); }) ``` ``` -------------------------------- ### Write a Cypress Integration Test for ToDo Insertion Source: https://docs.frappe.io/framework/user/en/guides/automated-testing/integration-testing This example demonstrates how to write an integration test for creating a new To Do item. It includes logging in, navigating to the new To Do page, filling a field, saving the item, and verifying its presence in the list. Ensure you have Cypress installed and configured. ```javascript context('ToDo', () => { before(() => { cy.login('Administrator', 'admin'); cy.visit('/desk'); }); it('creates a new todo', () => { cy.visit('/app/todo/new-todo-1'); cy.fill_field('description', 'this is a test todo', 'Text Editor').blur(); cy.get('.page-title').should('contain', 'Not Saved'); cy.get('.primary-action').click(); cy.visit('/desk#List/ToDo'); cy.location('hash').should('eq', '/app/todo'); cy.get('.list-row').should('contain', 'this is a test todo'); }); }); ``` -------------------------------- ### Initialize a new site with Postgres Source: https://docs.frappe.io/framework/user/en/guides/database-settings/postgres-database-setup Use this command to create a new site using PostgreSQL. Ensure PostgreSQL version 9 or greater is installed on the system. ```bash bench new-site --db-type postgres ``` -------------------------------- ### Code Instrumentation Example Source: https://docs.frappe.io/framework/user/en/ui-testing Comparison of code before and after instrumentation for coverage tracking. ```bash function foo(a, b) { if (a < b) return b - a; else return a - b; } ``` ```bash cov_1m1jljnmzu(); function foo(a, b) { cov_1m1jljnmzu().f[0]++; cov_1m1jljnmzu().s[0]++; if (a < b) { cov_1m1jljnmzu().b[0][0]++; cov_1m1jljnmzu().s[1]++; return b - a; } else { cov_1m1jljnmzu().b[0][1]++; cov_1m1jljnmzu().s[2]++; return a - b; } } ``` -------------------------------- ### Bench Init Command Help Source: https://docs.frappe.io/framework/user/en/bench/bench-commands Shows the help message for the `bench init` command, detailing its options for initializing a new bench instance. Use this to understand how to set up a new Frappe bench. ```zsh ➜ bench init --help Usage: bench init [OPTIONS] PATH Initialize a new bench instance in the specified path Options: --python TEXT Path to Python Executable. --ignore-exist Ignore if Bench instance exists. --apps_path TEXT path to json files with apps to install after init ``` -------------------------------- ### Create New App Source: https://docs.frappe.io/framework/user/en/tutorial/create-an-app Initialize a new application named library_management using the bench CLI. ```bash bench new-app library_management ``` -------------------------------- ### Serve a Specific Site with Bench Source: https://docs.frappe.io/framework/user/en/basics/sites Use this command to start the development server and serve a particular site. This is useful when working with multiple sites. ```bash bench --site mysite.localhost serve ``` -------------------------------- ### Install UV Source: https://docs.frappe.io/framework/user/en/installation Installs the UV package manager for Python. ```bash curl -LsSf https://astral.sh/uv/install.sh | sh ``` -------------------------------- ### Verify Bench Installation Source: https://docs.frappe.io/framework/user/en/installation Checks the installed version of the Bench CLI. ```bash bench --version ``` -------------------------------- ### Install Homebrew on macOS Source: https://docs.frappe.io/framework/user/en/installation Installs the Homebrew package manager for macOS. ```bash /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" ``` -------------------------------- ### Install Yarn Source: https://docs.frappe.io/framework/user/en/installation Installs the Yarn package manager globally using npm. ```bash npm install -g yarn ``` -------------------------------- ### Install wkhtmltopdf Dependencies on Debian/Ubuntu Source: https://docs.frappe.io/framework/user/en/installation Installs required system libraries for wkhtmltopdf. ```bash sudo apt install xvfb libfontconfig ``` -------------------------------- ### Basic bench new-site Usage Source: https://docs.frappe.io/framework/user/en/bench/reference/new-site This is the most basic command to create a new site. It will prompt for necessary information interactively. ```bash bench new-site {site} ``` -------------------------------- ### Install wkhtmltopdf on macOS Source: https://docs.frappe.io/framework/user/en/installation Downloads and installs the wkhtmltopdf package for PDF generation. ```bash curl -L https://github.com/wkhtmltopdf/packaging/releases/download/0.12.6-2/wkhtmltox-0.12.6-2.macos-cocoa.pkg -O installer -pkg wkhtmltox-0.12.6-2.macos-cocoa.pkg -target ~ ``` -------------------------------- ### Add a New Site Source: https://docs.frappe.io/framework/user/en/guides/basics/sites Execute this command in your bench instance to create a new site. ```bash bench new-site SITENAME ``` -------------------------------- ### Secure MariaDB Installation Source: https://docs.frappe.io/framework/user/en/installation Runs the security script for MariaDB if the root password was not set during installation. ```bash sudo mariadb-secure-installation ``` -------------------------------- ### App Creation Prompts and Output Source: https://docs.frappe.io/framework Example of prompts and output when creating a new Frappe app. Press Enter to accept default values. ```bash App Title (default: Library Management): App Description: Library Management System App Publisher: Faris Ansari App Email: faris@example.com App Icon (default 'octicon octicon-file-directory'): App Color (default 'grey'): App License (default 'MIT'): 'library_management' created at /home/frappe/frappe-bench/apps/library_management Installing library_management $ ./env/bin/pip install -q -U -e ./apps/library_management $ bench build --app library_management yarn run v1.22.4 $ FRAPPE_ENV=production node rollup/build.js --app library_management Production mode ✔ Built js/moment-bundle.min.js ✔ Built js/libs.min.js ✨ Done in 1.95s. ``` -------------------------------- ### Get absolute value Source: https://docs.frappe.io/framework/get_query Use ABS to get the absolute (non-negative) value of a numeric column. ```python query = frappe.qb.get_query( "Journal Entry Account", fields=[{"ABS": "debit_in_account_currency", "as": "abs_amount"}] ) ``` -------------------------------- ### Create a new Frappe app Source: https://docs.frappe.io/framework/user/en/guides/basics/apps Use the bench CLI to initialize a new application with an interactive prompt. ```bash % bench new-app sample_app App Name: sample_app App Title: Sample App App Description: This is a sample app. App Publisher: Acme Inc. App Icon: icon-linux App Color: #6DAFC9 App Email: info@example.com App URL: http://example.com App License: MIT ``` -------------------------------- ### Initialize and Execute a Basic Query Source: https://docs.frappe.io/framework/get_query Demonstrates how to instantiate a query builder for a DocType and execute it to retrieve results as a dictionary. ```python # Get a query builder instance for the 'User' DocType query = frappe.qb.get_query("User") # Execute the query and fetch results users = query.run(as_dict=True) ``` -------------------------------- ### Install GnuPG on MacOS Source: https://docs.frappe.io/framework/user/en/guides/basics/how-to-enable-backup-encryption Use this command to install GnuPG on MacOS systems, which is required for backup encryption. ```bash brew install gnupg ``` -------------------------------- ### Initialize Bench Source: https://docs.frappe.io/framework/user/en/installation Creates a new directory and initializes a new Frappe bench instance. ```bash mkdir ~/frappe cd ~/frappe bench init my-bench ``` -------------------------------- ### Initialize a New Frappe Bench Source: https://docs.frappe.io/framework/user/en/bench/bench-commands Creates a new bench directory with the Frappe framework installed and configured for periodic backups. Navigate into the created directory afterwards. ```zsh ➜ bench init frappe-bench && cd frappe-bench ``` -------------------------------- ### Install macOS System Packages Source: https://docs.frappe.io/framework/user/en/installation Installs core dependencies including git, redis, and MariaDB via Homebrew. ```bash brew install git redis mariadb@11.8 pkg-config mariadb-connector-c ``` -------------------------------- ### Initialize Frappe Bench Directory Source: https://docs.frappe.io/framework/user/en/tutorial/install-and-setup-bench Create the main project directory for Frappe, named 'frappe-bench'. This command sets up a Python virtual environment, installs the Frappe app, its Node modules, and builds static assets. ```bash $ bench init frappe-bench ``` -------------------------------- ### Install Xcode Command Line Tools on macOS Source: https://docs.frappe.io/framework/user/en/installation Installs the necessary command line tools for macOS development. ```bash xcode-select --install ``` -------------------------------- ### Set SSL Certificate and Key for Site Source: https://docs.frappe.io/framework/user/en/bench/guides/configuring-https Use bench commands to specify the paths to your SSL certificate bundle and private key for a specific site. ```bash bench set-ssl-certificate site1.local /etc/nginx/conf.d/ssl/certificate_bundle.crt bench set-ssl-key site1.local /etc/nginx/conf.d/ssl/private.key ``` -------------------------------- ### Bench Helper Program and Arguments Source: https://docs.frappe.io/framework/user/en/debugging This configuration snippet shows how the `program` and `args` in `launch.json` correspond to the command-line execution of `bench serve` with specific flags. ```bash cd sites ../env/bin/python ../apps/frappe/frappe/utils/bench_helper.py frappe serve --port 8000 --noreload --nothreading ``` -------------------------------- ### Create SSL Directory and Move Files Source: https://docs.frappe.io/framework/user/en/bench/guides/configuring-https Create a directory for SSL files and move your private key and certificate bundle into it. ```bash mkdir /etc/nginx/conf.d/ssl mv private.key /etc/nginx/conf.d/ssl/private.key mv certificate_bundle.crt /etc/nginx/conf.d/ssl/certificate_bundle.crt ``` -------------------------------- ### Example App Directory Structure Source: https://docs.frappe.io/framework Illustrates the typical directory structure generated for a new Frappe app, including key subdirectories and files. ```bash apps/library_management ├── README.md ├── library_management │ ├── hooks.py │ ├── library_management │ │ └── __init__.py │ ├── modules.txt │ ├── patches.txt │ ├── public │ │ ├── css │ │ └── js │ ├── templates │ │ ├── __init__.py │ │ ├── includes │ │ └── pages │ │ └── __init__.py │ └── www └── pyproject.toml ``` -------------------------------- ### List Apps on All Sites Source: https://docs.frappe.io/framework/user/en/bench/reference/list-apps Lists all Frappe Applications installed across all sites. This command is useful for a comprehensive overview of installed applications. ```bash bench --site all list-apps ``` -------------------------------- ### Sample Redis Configuration File Source: https://docs.frappe.io/framework/user/en/guides/caching Example configuration for the Redis cache server, including memory management and persistence settings. ```text dbfilename redis_cache.rdb dir /home/user/benches/develop/config/pids pidfile /home/user/benches/develop/config/pids/redis_cache.pid bind 127.0.0.1 port 13000 maxmemory 737mb maxmemory-policy allkeys-lru appendonly no save "" ``` -------------------------------- ### Setup Let's Encrypt SSL for Custom Domains Source: https://docs.frappe.io/framework/user/en/bench/guides/lets-encrypt-ssl-setup.html This command allows setting up Let's Encrypt for custom domains associated with your site. Ensure the custom domain is correctly configured. ```bash sudo -H bench setup lets-encrypt [site-name] --custom-domain [custom-domain] ``` -------------------------------- ### Get Currently Logged-in User Source: https://docs.frappe.io/framework/user/en/guides/integration/rest_api/simple_authentication This GET endpoint retrieves the username of the currently authenticated user. It requires an active session cookie. ```bash curl -X GET https://{your frappe instance}/api/method/frappe.auth.get_logged_user ``` -------------------------------- ### Example site_config.json Source: https://docs.frappe.io/framework/user/en/basics/sites This JSON file stores site-specific configuration. Ensure sensitive information like passwords is handled securely. ```json { "db_name": "test_frappe", "db_password": "test_frappe", "admin_password": "admin", } ``` -------------------------------- ### Whitelisted Server Method Example Source: https://docs.frappe.io/framework/user/en/guides/basics/frappe_ajax_call An example of a Python server-side method that can be called via `frappe.call`. It must be decorated with `@frappe.whitelist()` to be accessible from the client. ```python @frappe.whitelist() def get_all_roles(): // business logic return value ``` -------------------------------- ### Example Site Directory Structure Source: https://docs.frappe.io/framework/user/en/basics/sites This is a typical directory structure for a Frappe site, showing key subdirectories and configuration files. ```bash sites/mysite.localhost ├── locks ├── private │   ├── backups │   └── files ├── public │   └── files ├── site_config.json └── task-logs ``` -------------------------------- ### Make GET Request with frappe.make_get_request Source: https://docs.frappe.io/framework/user/en/desk/scripting/script-api Perform an HTTP GET request to an external URL. This is part of the API client utilities for interacting with external services. ```python frappe.make_get_request('https://example.com') ``` -------------------------------- ### Create Site with Non-Interactive Passwords Source: https://docs.frappe.io/framework/user/en/bench/reference/new-site This example demonstrates how to create a new site while providing the administrator and MariaDB root passwords directly, bypassing interactive prompts. ```bash bench new-site {site} --admin-password {admin-password} --db-root-password {mariadb-password} ``` -------------------------------- ### Setup Vue App and Mount Source: https://docs.frappe.io/framework/using-vue-inside-a-desk-page This JavaScript module provides a `setup_vue` function to create and mount a Vue application. It's designed to be imported and used within Frappe's page loading logic. The `createApp` function from Vue is used here. ```javascript import { createApp } from 'vue'; import TestVue from './TestVue.vue'; // A simple function to mount your Vue app function setup_vue(wrapper) { const app = createApp(TestVue); app.mount(wrapper.get(0)); return app; } // We'll call this function from the generated test_vue.js file frappe.ui.setup_vue = setup_vue; export default setup_vue; ``` -------------------------------- ### LDAP Search Filter Examples Source: https://docs.frappe.io/framework/user/en/integration/ldap-integration Examples of LDAP search filters that can be used in the LDAP Search String field, supporting placeholders and complex directory queries. ```text (uid={0}) ``` ```text (SamAccountName={0}) ``` ```text (&(description=*ACCESS:Frappe*)(uid={0}) ``` ```text (&(SamAccountName={0})(memberof=cn=Domain Users,ou=Groups,DC=example,dc=com)) ``` -------------------------------- ### Create Site with Custom Database Configuration Source: https://docs.frappe.io/framework/user/en/bench/reference/new-site This command creates a new site using custom configurations for database type, name, user, password, host, and port. ```bash bench new-site {site} --db-type {type} --db-name {name} --db-user {user} --db-password {pass} --db-host {host} --db-port {port} ``` -------------------------------- ### Create a New Frappe Site Source: https://docs.frappe.io/framework/user/en/production-setup Navigate to the bench directory and create a new site. Ensure you are in the 'frappe-bench' directory before running these commands. ```bash # change directory to frappe-bench cd frappe-bench # create a new site bench new-site example.com # download frappe apps or your custom-apps bench get-app erpnext bench get-app https://github.com/yourremote/yourapp.git # install apps onto your site bench --site example.com install-app erpnext yourapp ``` -------------------------------- ### Bench Initialization and General Usage Source: https://docs.frappe.io/framework/user/en/bench/resources/bench-commands-cheatsheet Commands for initializing a new bench and checking system versions. ```APIDOC ## CLI: bench init ### Description Creates a new bench instance. ### Parameters #### Arguments - **bench-name** (string) - Required - The name of the new bench. #### Options - **--python** (string) - Optional - Path to Python Executable. - **--ignore-exist** (boolean) - Optional - Ignore if Bench instance exists. - **--apps_path** (string) - Optional - Path to json files with apps to install after init. - **--frappe-path** (string) - Optional - Path to frappe repo. - **--frappe-branch** (string) - Optional - Clone a particular branch of frappe. - **--clone-from** (string) - Optional - Copy repos from path. - **--clone-without-update** (boolean) - Optional - Copy repos from path without update. - **--verbose** (boolean) - Optional - Verbose output during install. ``` -------------------------------- ### Create a New Frappe Site Source: https://docs.frappe.io/framework/user/en/basics/sites Use this command to create a new site within your Frappe bench. It initializes the site directory and installs the Frappe app. ```bash $ bench new-site mysite.localhost Installing frappe... Updating DocTypes for frappe : [========================================] Updating country info : [========================================] *** Scheduler is disabled *** ``` -------------------------------- ### Form Event: Setup Handler Source: https://docs.frappe.io/framework/user/en/api/form This snippet illustrates how to define a `setup` event handler for a form. The `frm` object is passed as the first parameter to all form event handlers. ```javascript frappe.ui.form.on('ToDo', { // frm passed as the first parameter setup(frm) { // write setup code } }) ``` -------------------------------- ### Execute Frappe get_site_info Function Source: https://docs.frappe.io/framework/user/en/bench/reference/execute This example shows how to retrieve site information by executing the `frappe.utils.get_site_info()` function using the `bench execute` command. The output of the function will be printed to the console. ```bash bench --site frappe.test execute frappe.utils.get_site_info ``` -------------------------------- ### Frappe API Get Logged User Response Source: https://docs.frappe.io/framework/user/en/guides/integration/rest_api/simple_authentication A successful request to get the logged-in user returns an HTTP 200 status code with the username in the 'message' field. ```json { "message": "Administrator" } ```