This example shows how to use 51Degrees on-premise device detection to determine details about a
device based on its User-Agent and User-Agent Client Hint HTTP header values.
This example requires a local data file. The free 'Lite' data file can be acquired by
pulling the git submodules under this repository (run `git submodule update --recursive`)
or from the device-detection-data
GitHub repository.
The Lite data file is only used for illustration, and has limited accuracy and capabilities.
Find out about the more capable data files that are available on our
pricing page
36 from fiftyone_devicedetection.devicedetection_pipelinebuilder
import DeviceDetectionPipelineBuilder
37 from fiftyone_devicedetection_examples.example_utils
import ExampleUtils
38 from fiftyone_pipeline_core.logger
import Logger
39 from fiftyone_devicedetection_shared.example_constants
import EVIDENCE_VALUES
40 from fiftyone_devicedetection_shared.example_constants
import LITE_DATAFILE_NAME
42 class GettingStartedConsole():
43 def run(self, data_file, logger, output):
49 pipeline = DeviceDetectionPipelineBuilder(
50 data_file_path = data_file,
57 performance_profile =
"LowMemory",
60 usage_sharing =
False,
63 licence_keys =
"").add_logger(logger).build()
65 ExampleUtils.check_data_file(pipeline, logger);
68 for values
in EVIDENCE_VALUES:
69 self.analyseEvidence(values, pipeline, output)
71 def analyseEvidence(self, evidence, pipeline, output):
80 data = pipeline.create_flowdata()
85 message.append(
"Input values:\n")
87 message.append(f
"\t{key}: {evidence[key]}\n")
89 output(
"".join(message))
92 data.evidence.add_from_dict(evidence)
98 message.append(
"Results:\n")
110 self.outputValue(
"Mobile Device", device.ismobile, message)
111 self.outputValue(
"Platform Name", device.platformname, message)
112 self.outputValue(
"Platform Version", device.platformversion, message)
113 self.outputValue(
"Browser Name", device.browsername, message)
114 self.outputValue(
"Browser Version", device.browserversion, message)
115 output(
"".join(message))
117 def outputValue(self, name, value, message):
126 f
"\t{name}: {value.value()}\n" if value.has_value()
127 else f
"\t{name}: {value.no_value_message()}\n")
139 data_file = argv[0]
if len(argv) > 0
else ExampleUtils.find_file(LITE_DATAFILE_NAME)
142 logger = Logger(min_level=
"info")
144 if (data_file !=
None):
145 GettingStartedConsole().run(data_file, logger,
print)
148 "Failed to find a device detection " +
149 "data file. Make sure the device-detection-data " +
150 "submodule has been updated by running " +
151 "`git submodule update --recursive`.")
153 if __name__ ==
"__main__":