The cloud service exposes meta data that can provide additional information about the various properties that might be returned. This example shows how to access this data and display the values available.
A list of the properties will be displayed, along with some additional information about each property. Note that this is the list of properties used by the supplied resource key, rather than all properties that can be returned by the cloud service.
In addition, the evidence keys that are accepted by the service are listed. These are the keys that, when added to the evidence collection in flow data, could have some impact on the result that is returned.
Bear in mind that this is a list of ALL evidence keys accepted by all products offered by the cloud. If you are only using a single product (for example - device detection) then not all of these keys will be relevant.
This example is available in full on GitHub.
To run this example, you will need to create a resource key.
The resource key is used as shorthand to store the particular set of
properties you are interested in as well as any associated license keys
that entitle you to increased request limits and/or paid-for properties.
You can create a resource key using the 51Degrees
Configurator.
Required PyPi Dependencies:
49 from pathlib
import Path
52 from fiftyone_pipeline_core.logger
import Logger
53 from fiftyone_pipeline_core.basiclist_evidence_keyfilter
import BasicListEvidenceKeyFilter
55 from ..example_utils
import ExampleUtils
58 fgWhite =
"\u001b[37;1m" 59 colReset =
"\u001b[0m" 61 class MetaDataConsole():
62 def run(self, resource_key, logger, output):
64 pipeline = DeviceDetectionPipelineBuilder(
65 resource_key = resource_key).add_logger(logger).
build()
67 self.outputProperties(pipeline.get_element(
"device"), output)
75 self.outputEvidenceKeyDetails(pipeline.get_element(
"cloud"), output)
78 def outputEvidenceKeyDetails(self, engine, output):
79 if (issubclass(type(engine.get_evidence_key_filter()), BasicListEvidenceKeyFilter)):
83 filter = engine.get_evidence_key_filter()
84 output(
"Accepted evidence keys:")
85 for key
in filter.list:
88 output(
"The evidence key filter has type " +
89 f
"{type(engine.get_evidence_key_filter())}. As this does not extend " +
90 "BasicListEvidenceKeyFilter, a list of accepted values cannot be " +
91 "displayed. As an alternative, you can pass evidence keys to " +
92 "filter.filter_evidence_key(string) to see if a particular key will be included " +
94 output(
"For example, header.user-agent is " +
95 (
"" if engine.get_evidence_key_filter().filter_evidence_key(
"header.user-agent")
else "not ") +
99 def outputProperties(self, engine, output):
100 for propertyName, property
in engine.get_properties().items():
104 output(f
"{bgRed}{fgWhite}Property - {propertyName}{colReset}" +
105 f
"[Category: {property['category']}] ({property['type']})")
110 resource_key = argv[0]
if len(argv) > 0
else ExampleUtils.get_resource_key()
113 logger = Logger(min_level=
"info")
116 MetaDataConsole().
run(resource_key, logger,
print)
120 "No resource key specified in environment variable " +
121 f
"'{ExampleUtils.RESOURCE_KEY_ENV_VAR}'. The 51Degrees " +
122 "cloud service is accessed using a 'ResourceKey'. " +
123 "For more detail see " +
124 "http://51degrees.com/documentation/4.3/_info__resource_keys.html. " +
125 "A resource key with the properties required by this " +
126 "example can be created for free at " +
127 "https://configure.51degrees.com/1QWJwHxl. " +
128 "Once complete, populate the environment variable " +
129 "mentioned at the start of this message with the key.")
131 if __name__ ==
"__main__":