---
title: initialize (Python agent API)
source: https://docs.newrelic.com/docs/apm/agents/python-agent/python-agent-api/initialize-python-agent-api
---

## Syntax

```py
newrelic.agent.initialize(config_file=None, environment=None, ignore_errors=None, log_file=None, log_level=None)
```

Initializes the Python agent with a specified config file during a manual integration process.

## Description

This is called to initialize the Python agent with a specified [configuration file](https://docs.newrelic.com/docs/agents/python-agent/installation-configuration/python-agent-configuration#agent-configuration-file) when the agent is being [manually integrated with a Python application](https://docs.newrelic.com/docs/agents/python-agent/installation-configuration/python-agent-integration#manual-integration).

For best instrumentation results, make this call as early as possible in your app code. Unlike typical Python functionality, the order of import matters. For WSGI and application script files, place the `initialize` call before all imports, with the exception of the `sys` import and updates to the `sys.path`. If you call `initialize` multiple times, the agent ignores calls after the first if the configuration file and environment options are the same. If the options differ, an exception is raised.

If you call `initialize` with no arguments, you must have already specified your license key with the [`NEW_RELIC_LICENSE_KEY`](https://docs.newrelic.com/docs/agents/python-agent/installation-configuration/python-agent-configuration#license_key) environment variable. Alternatively, you can set `NEW_RELIC_CONFIG_FILE` and `NEW_RELIC_ENVIRONMENT`. The agent will then read those values in place of the missing arguments.

## Parameters

| Parameter                                              | Description                                                                                                                                                                                                                                                                                                                            |
| ------------------------------------------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `config_file` _string_                                 | Optional. The path to the agent config file. If you supply a configuration file, you can override elements of that config file with the optional `environment` parameter.                                                                                                                                                              |
| `environment` _string_                                 | Optional. Indicates the name of the environment. If you are using a configuration file, you can override the settings in that file with `environment`.                                                                                                                                                                                 |
| `ignore_errors` _boolean_                              | Optional. Indicates whether to ignore startup errors. Default is `True`.                                                                                                                                                                                                                                                               |
| `log_file` _string_                                    | Optional. Path to the agent log file. Also accepts `stdout` and `stderr` (same as the [`log_file`](https://docs.newrelic.com/docs/agents/python-agent/installation-configuration/python-agent-configuration#log_file) option in the config file).                                                                                      |
| `log_level` _int_ or applicable logging parameter type | Optional. Sets the logging level. The agent uses [Python's logging module](https://docs.python.org/3.12/library/logging.html#logging-levels). Options are the same as for the [`log_level`](https://docs.newrelic.com/docs/agents/python-agent/installation-configuration/python-agent-configuration#log_level) option in config file. |

## Return values

None.

## Examples

### Initializing with config file and environment [#init-example]

Here's an example of initializing the Python agent with a config file and an environment string:

```py
newrelic.agent.initialize('/etc/newrelic/newrelic.ini', 'production')
```

### Using all parameter values [#init-example-2]

Calling with all parameter values:

```py
newrelic.agent.initialize('/etc/newrelic/newrelic.ini', 'production', ignore_errors=False, log_file='/var/log/newrelic.log', log_level=logging.DEBUG)
```
