- Updating Device Data
- Useful Links
- Supported Versions
This tutorial illustrates the basic use of the 51Degrees API. It will show you how to create a provider, how to create a dataset and how to obtain a value for the IsMobile property.
Code and Explanation
Getting started example of using 51Degrees trie device detection. The example
shows how to:
dataFile = settings.V3_WRAPPER_TRIE_DATABASE
properties = settings.PROPERTIES
provider = fiftyone_degrees_mobile_detector_v3_trie_wrapper.Provider( dataFile, properties)
match = provider.getMatch(userAgent)
match.getValues('IsMobile')This example can be run in any directory, but assumes your settings file contains a valid dataFile location and has the IsMobile property selected. By comparing this to the gettingstarted.py example which uses the pattern method, you can see the differences are the module name, the data file, and it does not use a cache or pool, so these do not need to be set.
In this tutorial you have seen how to use the detector to retrieve the IsMobile property for a pre-defined User-Agent string. The example can easily be modified to retrieve the value of any other property. Premium and Enterprise data files provide considerably more properties such as IsCrawler , PriceBand , HardwareVendor and ScreenInchesWidth . For a full list of properties and the data file versions they exist in please see the Property Dictionary .