# Install APM Insight Python Agent To install APM Insight Python agent, follow the steps given below: > **Note:** Install the Applications Manager Data Exporter (for [Windows](https://www.manageengine.com/products/applications_manager/help/apm-insight-data-exporter-windows.html#install) or [Linux](https://www.manageengine.com/products/applications_manager/help/apm-insight-data-exporter-linux.html#install)) to enable communication with the Applications Manager server. 1. Navigate to the **APM** tab → **Add New Monitor** → **Python** in Applications Manager console. 2. Download the appropriate [APM Insight Python agent](https://www.manageengine.com/products/applications_manager/apm-insight-agent-installation.html#python) (**apm_insight_agent_python.zip**) file from the download page and extract it. 3. If you are using a virtual environment, activate it, navigate to the extracted Python agent directory and execute the following command to install the Python packages in your virtual environment: ```bash python -m pip install . ``` 4. Deploy the Python agent to your application using any of the following methods: - [Using command line](https://www.manageengine.com/products/applications_manager/help/apm-insight-python-agent-install.html#cmd) - [Using code snippet](https://www.manageengine.com/products/applications_manager/help/apm-insight-python-agent-install.html#code) ## Using command line To deploy the Python agent into your application, you need to run your application using the following command: ```bash $ apminsight-run --license_key "" ``` Following are the list of options that can be used in the place of `` argument in the command: | apm-options | Description | |---|---| | *--license_key* | To add the Applications Manager license key or device key | | *---apm_app_name "monitorname"* | To add the APM application name. | | *--apm_log_dir "log location"* | To add a custom log directory for storing APM logs. | | *--apm_debug "true/false"* | To enable debug mode. | | *--apm_exp_host "DataExporter_Host"* | To configure the Applications Manager DataExporter host. | | *--apm_exp_status_port "DataExporter_Status_Port"* | To configure the Applications Manager DataExporter status port. Default port is 20021. | | *--apm_exp_data_port "DataExporter_Data_Port"* | To configure the Applications Manager DataExporter data port. Default port is 20022. | **Examples:** If you want to configure the application name, use the below command: ```bash $ apminsight-run --apm_app_name "monitorname" sampleapp.py ``` If you want to configure the directory location, use the below command: ```bash $ apminsight-run --apm_app_name "monitorname" --apm_log_dir "logs location" sampleapp.py ``` If you want to configure the AppManagerDataExporter, use the below command: ```bash $ apminsight-run --apm_app_name "monitorname" --apm_exp_host "apm-exporter-host" --apm_exp_status_port "20021" --apm_exp_data_port "20022" sampleapp.py ``` > **Note:** The status port and data port configurations for AppManagerDataExporter are located in the **configuration.json** file, applicable to both [Windows](https://www.manageengine.com/products/applications_manager/help/apm-insight-data-exporter-windows.html#configure) and [Linux](https://www.manageengine.com/products/applications_manager/help/apm-insight-data-exporter-linux.html#configure) systems. ## Using code snippet To deploy the Python agent into your application, update the required configuration information in the following code snippet and place it at the top of your application route file or application start file: ```python from apminsight import initialize_agent initialize_agent({ "appname" : "", "license_key" : "", '''change if Applications Manager Data Exporter is not running in the default ports(20021, 20022):''' "exporter_status_port" : "", "exporter_data_port" : "", '''If you are running Applications Manager Data Exporter on a separate machine/server or as a Docker container:''' "exporter_host" : "" }) ``` > **Note:** If exporter is running is different machine or running other than default ports, then update the required configuration information in the following code snippet: ```python from apminsight import initialize_agent initialize_agent({ "appname" : "", '''Change if Applications Manager Data Exporter is not running in the default ports (20021, 20022):''' "exporter_status_port" : "", "exporter_data_port" : "", '''If you are running Applications Manager Data Exporter on a separate machine/server or as a Docker container:''' "exporter_host" : "" }) ``` **Example:** - For **Django** applications, add the code snippet at the top of the Django's **settings.py** file. The name of your Django application will be automatically detected by your **WSGI_APPLICATION** in the application’s **settings.py** file. ![Applications Manager Install APM Insight Python Agent: Deploying agent for Django applications](https://www.manageengine.com/products/applications_manager/help/images/apm-insight-python-agent-install-django.png) - For other applications and frameworks, such as **Flask**, add the code snippet at the top of the application start file. ![Applications Manager Install APM Insight Python Agent: Deploying agent for Flask applications](https://www.manageengine.com/products/applications_manager/help/images/apm-insight-python-agent-install-other-apps.png) You can also configure the agent using the required environment variables listed below: | **Configuration** | **Description** | |---|---| | *$ export APM_LICENSE_KEY=""* | To add the license name. | | *$ export APM_APP_NAME=""* | To add the application name. | | *$ export APM_LOGS_DIR=""* | To configure the log directory. | | *$ export APM_EXPORTER_STATUS_PORT=*
*$ export APM_EXPORTER_DATA_PORT=* | To change the Applications Manager Data Exporter's default running ports (20021, 20022). | | *$ APM_EXPORTER_HOST=* | To change the host of the Applications Manager Data Exporter to a different machine or server or as a Docker container. | 5. Upon implementing the above changes, save the file and restart your application. 6. Once the application is restarted, perform some transactions so that the agent can collect data. 7. Navigate to the **APM** tab and click on the required Python application to view application metrics. 8. You can view agent log files under the *apminsightdata/logs* directory, which will be present in the process-generated location. ![Applications Manager Install APM Insight Python Agent: Viewing agent log files](https://www.manageengine.com/products/applications_manager/help/images/apm-insight-python-agent-logs.png)