# Configuration
When using Nominatim through the library, it can be configured in exactly
-the same way as when running as a service. This means that you should have
-created a [project directory](../admin/Import.md#creating-the-project-directory)
-which contains all files belonging to the Nominatim instance. It can also contain
-an `.env` file with configuration options. Setting configuration parameters
-via environment variables works as well.
+the same way as when running as a service. You may instantiate the library
+against the [project directory](../admin/Import.md#creating-the-project-directory)
+of your Nominatim installation. It contains all files belonging to the
+Nominatim instance. This may include an `.env` file with configuration options.
+Setting configuration parameters via environment variables works as well.
+Alternatively to using the operating system's environment, a set of
+configuration parameters may also be passed to the Nomiantim API object.
Configuration options are resolved in the following order:
Usually you would want to run this in a virtual environment.
-### A simple search example
+## A simple search example
To query the Nominatim database you need to first set up a connection. This
is done by creating an Nominatim API object. This object exposes all the
available only for the synchronous or asynchronous version, this will be
explicitly mentioned.
-### Defining which database to use
+## Defining which database to use
The [Configuration](../admin/Import.md#configuration-setup-in-env)
section explains how Nominatim is configured using the
which stores the various configuration and customization files that Nominatim
needs. You may pass the location of the project directory to your
'Nominatim API class' constructor and it will read the .env file in the
-directory and set the configuration accordingly.
+directory and set the configuration accordingly. Here is the simple search
+example, using the configuration from a pre-defined project directory in
+`/srv/nominatim-project`:
+
+!!! example
+ === "NominatimAPIAsync"
+ ``` python
+ import asyncio
+
+ import nominatim_api as napi
+
+ async def search(query):
+ async with napi.NominatimAPIAsync('/srv/nominatim-project') as api:
+ return await api.search(query)
+
+ results = asyncio.run(search('Brugge'))
+ if not results:
+ print('Cannot find Brugge')
+ else:
+ print(f'Found a place at {results[0].centroid.x},{results[0].centroid.y}')
+ ```
+
+ === "NominatimAPI"
+ ``` python
+ import nominatim_api as napi
+
+ with napi.NominatimAPI('/srv/nominatim-project') as api:
+ results = api.search('Brugge')
+
+ if not results:
+ print('Cannot find Brugge')
+ else:
+ print(f'Found a place at {results[0].centroid.x},{results[0].centroid.y}')
+ ```
+
You may also configure Nominatim by setting environment variables.
Normally Nominatim will check the operating system environment. Lets
```
When the `environ` parameter is given, then only configuration variables
-from this dictionary will be used.
+from this dictionary will be used. The operating system's environment
+variables will be ignored.
-### Presenting results to humans
+## Presenting results to humans
All search functions return full result objects from the database. Such a
result object contains lots of details: names, address information, OSM tags etc.