\r\n

51Degrees Pipeline Python  4.4

51Degrees Pipeline for Python

usagesharing/usagesharing.py

This Example shows how to configure the usage sharing feature of the Pipeline API. Usage sharing is a feature that allows you to share details of the requests you are processing with 51Degrees.

Usage sharing works by adding a 'ShareUsageElement' to the pipeline. This element will collect evidence values as they pass through, periodically sending them to 51Degrees for processing.

If you want to know more about usage sharing, and why you should consider using it, see the usage sharing feature page.

Usage sharing is enabled by default if using some 51Degrees pipeline builders such as the DeviceDetectionOnPremisePipelineBuilder. In this example, we show how to specifically add a usage sharing element to a Pipeline using configuration.

As with all flow elements, this can also be handled in code, using the constructor parameters. The commented section in the example demonstrates this.

The 51d.json file contains all the configuration options. These are all optional, so each can be omitted if the default for that option is sufficient:

{
"PipelineOptions": {
"Elements": [
{
"elementName": "ShareUsage",
"elementPath": "fiftyone_pipeline_engines_fiftyone.share_usage",
"elementParameters": {
"share_percentage": 100,
"interval": 1200,
"requested_package_size": 50,
"cookie": "",
"query_whitelist": [],
"header_blacklist": []
}
}
]
}
}

For details of what each setting does, see the constructor parameters in the reference documentation for the share usage element

This example is available in full on GitHub.

Expected output:

1 Constructing pipeline from configuration file.
2 
3 Pipeline created with share usage element. Evidence processed
4 with this pipeline will now be shared with 51Degrees using the
5 specified configuration.
1 # *********************************************************************
2 # This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3 # Copyright 2023 51 Degrees Mobile Experts Limited, Davidson House,
4 # Forbury Square, Reading, Berkshire, United Kingdom RG1 3EU.
5 #
6 # This Original Work is licensed under the European Union Public Licence
7 # (EUPL) v.1.2 and is subject to its terms as set out below.
8 #
9 # If a copy of the EUPL was not distributed with this file, You can obtain
10 # one at https://opensource.org/licenses/EUPL-1.2.
11 #
12 # The 'Compatible Licences' set out in the Appendix to the EUPL (as may be
13 # amended by the European Commission) shall be deemed incompatible for
14 # the purposes of the Work and the provisions of the compatibility
15 # clause in Article 5 of the EUPL shall not apply.
16 #
17 # If using the Work as, or as part of, a network application, by
18 # including the attribution notice(s) required under Article 5 of the EUPL
19 # in the end user terms of the application under an appropriate heading,
20 # such notice(s) shall fulfill the requirements of that article.
21 # *********************************************************************
22 
23 
56 
57 import os
58 import json
59 from fiftyone_pipeline_core.pipelinebuilder import PipelineBuilder
61 
62 print("Constructing pipeline from configuration file.")
63 print()
64 
65 # Create a new pipeline from the supplied config file.
66 dir = os.path.dirname(__file__)
67 with open(os.path.join(dir, '51d.json')) as json_file:
68  pipeline = PipelineBuilder().build_from_configuration(json.load(json_file))
69 
70 # Alternatively, the commented code below shows how to
71 # configure the ShareUsageElement in code, rather than
72 # using a configuration file.
73 #usageElement = ShareUsage(
74 # share_percentage = 0.1,
75 # requested_package_size = 2000
76 #)
77 #pipeline = PipelineBuilder().add(usageElement).build()
78 
79 print("""Pipeline created with share usage element. Evidence processed
80 with this pipeline will now be periodically shared with 51Degrees using
81 the specified configuration.""")