# DeviceAtlas Device Identification API Config # There are multiple factors which might affect API behaviour and performance. ## Contents ## * [Config class](#config_class) * [How it works](#how_it_works) * [Configuration examples](#config_examples) * [General tips](#general_tips) * [Batch User-Agent processing](#batch_processing) * [Maximizing CPU utilization](#maximizing_cpu) * [Python 3.x over Python 2.x](#py3x_vs_py2x) <a name="config_class"></a> ### Config Class ### DeviceAtlas DeviceApi Config class provides options to customize the API behaviour in terms of memory use, caching, performance and device properties. * [Max cache entries](#max_cache_entries) * [Include User-Agent properties](#include_ua_props) * [Include language properties](#include_lang_props) * [Return None when there are no properties](#return_none_when_no_properties) * [Client-side cookie name](#cookie_name) <a name="max_cache_entries"></a> #### Cache Settings #### An internal cache can be used to gain performance. The number of entries can be changed. Note that if it set to zero, the cache is disabled. **Config property:** `Config.max_cache_entries` **Default Value:** 4096 <a name="include_ua_props"></a> #### Include User-Agent properties #### Boolean value to enable/disable the addition of User-Agent properties to the detection. They are also known as "dynamic" properties as they can be detected on the fly by directly parsing the User-Agent. Enabling this property will worsen API detection performance. If you don't need these properties, then set it to False. User-Agent/Dynamic properties: `browserName, browserVersion, browserRenderingEngine, osName, osVersion` **Config property:** `Config.include_ua_props` **Possible values:** True/False **Default Value:** True <a name="include_lang_props"></a> #### Include language properties #### Boolean value to enable/disable the addition of client's language and locale preferences to the device property set. If you don't need these properties, then set it to False. Language properties: `language, languageLocale` **Config property:** `Config.include_lang_props` **Possible values:** True/False **Default Value:** True <a name="return_none_when_no_properties"></a> #### Return None when there are no properties #### Boolean value to make the API either return `None` if the property set to return is empty, or a Properties object with no values inside. **Config property:** `Config.return_none_when_no_properties` **Possible values:** True/False **Default Value:** False <a name="cookie_name"></a> #### Client-side cookie name #### Name of the cookie where the Client-side properties will be saved in. When using get_properties() method in a web application (DeviceApi), the detection will automatically use the content of this cookie, if it exists. If you want the Client-side properties to be used add the DeviceAtlas client side component (JavaScript lib) to your web-site pages. When the User-Agent or HTTP headers are passed manually to get_properties(), the Client-side properties can be also manually passed to this method as a second parameter. Note that this config is only used as an argument of get_properties(). If you set the cookie name to None, then the Client-side properties cookie will be ignored. **Config property:** `Config.cookie_name` **Default Value:** "DAPROPS" <a name="how_it_works"></a> ### How it works ### Translating into code how the API settings are used, it is as simple as having an instance of the `Config` class into the `DeviceApi` object and the respective Config public methods to check the wished settings and make the API work according to them. <a name="use_default_settings"></a> #### Use of the default settings #### When a new instance of the `DeviceApi` class is created, internally another instance of the `Config` class is generated with the default settings. ```python from mobi.mtld.da.device.device_api import DeviceApi device_api = DeviceApi() ``` <a name="use_custom_settings"></a> #### Use of custom settings #### In order to use custom settings, it is required to explicitly create a `Config` object, set the settings and pass it to the `DeviceApi` instance. **Preferred method** ```python from mobi.mtld.da.device.device_api import DeviceApi from mobi.mtld.da.device.config import Config config = Config() config.include_ua_props = False config.max_cache_entries = 0 device_api = DeviceApi(config) ``` **Alternative method** ```python from mobi.mtld.da.device.device_api import DeviceApi from mobi.mtld.da.device.config import Config device_api = DeviceApi() config = Config() config.include_ua_props = False config.max_cache_entries = 0 device_api.set_config(config) ``` <a name="config_examples"></a> ### Configuration examples ### For the scenario your system works, it is highly recommended to configure the API with the most convenient settings in order to enhance performance, memory footprint and, in general, provide a better user experience. ```python from mobi.mtld.da.device.device_api import DeviceApi from mobi.mtld.da.device.config import Config # Reduce response time and memory footprint for a web application config = Config() # Set the number of maximum entries held in the internal cache. config.max_cache_entries = 256 # Boost API performance by ignoring dynamic properties if they are not part of # the property set you expect. config.include_ua_props = False # Ignore language and locale properties if they are not needed. config.include_lang_props = False # Finally set the config to our new instance of the DeviceAtlas API. device_api = DeviceApi(config) ``` <a name="general_tips"></a> ### General tips ### <a name="batch_processing"></a> #### Batch User-Agent processing #### When processing a list of unique User-Agents it is recommended to disable the internal cache (`config.max_cache_entries = 0`) for best performance. For a list with repeated User-Agents it is recommended to review cache size and set it according to your needs. Please read the "Config Class" section of this document for further details on how to use the Config class. <a name="maximizing_cpu"></a> #### Maximizing CPU utilization #### The latest version of the device API runs without problems in a multi-process environment, however custom code has to be created to access the API in a multi-process way to achieve the optimal hardware utilization. The following are general recommendations to obtain optimal results from the Hardware: * A single device API instance can serve multiple processes. * In a multi-process environment it is possible to use multiple CPU cores by using the Python's `multiprocessing.Process` class. * The recommended number of concurrent processes should not be greater than the number of cores in the system. <a name="py3x_vs_py2x"></a> #### Python 3.x over Python 2.x #### To obtain optimal performance it is recommended to use Python 3.x. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - _ Copyright (c) Afilias Technologies Limited 2021. All Rights Reserved. _ https://deviceatlas.com <!-- HTML+JS for document formatting when opened in browser --> <div class="btn-group" id="main-menu" style="float:right"><a class="btn dropdown-toggle" data-toggle="dropdown" href="#">Menu<span class="caret"></span></a><ul class="dropdown-menu"><li><a href="README.html">Main</a></li><li><a href="README.Installation.html">Enterprise API Installation</a></li><li><a href="README.DeviceApi.html">Device Identification API</a></li><li class="disabled"><a href="README.DeviceApi-Config.html">Device Identification API Config</a></li><li><a href="README.CarrierApi.html">Carrier Identification API</a></li><li><a href="README.Upgrade.html">API Upgrade</a></li><li class="divider"></li><li><a href="./ApiDocs/index.html">DeviceAtlas API Docs</a></li><li class="divider"></li><li><a href="README.ClientSide.html">Client-side Component</a></li><li class="divider"></li><li><a href="README.ConnectivityAnalyser.html">Connectivity Analyser</a></li></ul></div>