fiftyone-ipintelligence-cloud 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -0,0 +1,91 @@
1
+ # *********************************************************************
2
+ # This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3
+ # Copyright 2026 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
+ from __future__ import absolute_import
24
+ from fiftyone_pipeline_cloudrequestengine.cloudengine import CloudEngine
25
+ from fiftyone_pipeline_core.aspectproperty_value import AspectPropertyValue
26
+
27
+ # The cloud sends weighted values with a raw 16-bit weighting ("rawweighting",
28
+ # 0-65535, the same field ip-intelligence-dotnet reads into IWeightedValue.
29
+ # RawWeighting). The rest of this SDK - and the on-premise engine's getWeight()
30
+ # - expresses weighting as a 0.0-1.0 proportion, so normalise by the maximum.
31
+ _RAW_WEIGHTING_MAX = 65535
32
+
33
+
34
+ class IpIntelligenceCloud(CloudEngine):
35
+ """!
36
+ The IP Intelligence cloud engine requires the 51Degrees
37
+ cloudRequestEngine to be placed in a pipeline before it.
38
+ It takes that raw JSON response and parses it to extract the
39
+ IP intelligence part. It also uses this data to generate a list
40
+ of properties. Weighted properties (e.g. Mcc) are returned as
41
+ lists of {"value": ..., "weighting": ...} dictionaries, where the
42
+ cloud's raw 0-65535 weighting is normalised to a 0.0-1.0 proportion
43
+ so it matches the on-premise engine.
44
+ """
45
+ def __init__(self):
46
+
47
+ super(IpIntelligenceCloud, self).__init__()
48
+
49
+ self.datakey = "ip"
50
+
51
+ def process_internal(self, flowdata):
52
+
53
+ """!
54
+ Parse the cloud response via the base engine, then normalise the
55
+ weighted values so their shape matches the on-premise engine
56
+ ({"value", "weighting"} with weighting as a 0.0-1.0 proportion).
57
+ """
58
+
59
+ super(IpIntelligenceCloud, self).process_internal(flowdata)
60
+
61
+ element_data = flowdata.get(self.datakey)
62
+
63
+ weighted_keys = {
64
+ name.lower()
65
+ for name, meta in self.properties.items()
66
+ if "weighted" in str(meta.get("type", "")).lower()
67
+ }
68
+
69
+ for key in weighted_keys:
70
+ value = element_data.contents.get(key)
71
+ if value is None or not value.has_value():
72
+ continue
73
+ items = value.value()
74
+ if not isinstance(items, list):
75
+ continue
76
+ element_data.contents[key] = AspectPropertyValue(
77
+ value=[self._normalise_weighting(item) for item in items])
78
+
79
+ @staticmethod
80
+ def _normalise_weighting(item):
81
+
82
+ """Convert a single cloud weighted entry, turning the raw 0-65535
83
+ "rawweighting" field into a 0.0-1.0 "weighting". Entries that already
84
+ use "weighting" (or are not dictionaries) are left untouched."""
85
+
86
+ if not isinstance(item, dict) or "rawweighting" not in item:
87
+ return item
88
+ normalised = dict(item)
89
+ normalised["weighting"] = (
90
+ normalised.pop("rawweighting") / float(_RAW_WEIGHTING_MAX))
91
+ return normalised
@@ -0,0 +1,87 @@
1
+ # *********************************************************************
2
+ # This Original Work is copyright of 51 Degrees Mobile Experts Limited.
3
+ # Copyright 2026 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
+ from __future__ import absolute_import
24
+ from fiftyone_pipeline_core.pipelinebuilder import PipelineBuilder
25
+ from fiftyone_pipeline_cloudrequestengine.cloudrequestengine import CloudRequestEngine
26
+ from .ipintelligence_cloud import IpIntelligenceCloud
27
+ from fiftyone_ipintelligence_shared.utils import merge_two_dicts
28
+
29
+ class IpIntelligenceCloudPipelineBuilder(PipelineBuilder):
30
+ """!
31
+ The IP Intelligence Cloud Pipeline Builder allows you to easily
32
+ construct a pipeline containing the IP intelligence cloud engine.
33
+ """
34
+ def __init__(self, settings = None, **kwargs):
35
+
36
+ """!
37
+
38
+ Constructor for the IP Intelligence Cloud Pipeline Builder
39
+
40
+ General pipeline settings:
41
+
42
+ @type javascript_builder_settings: dict
43
+ @param javascript_builder_settings: parameters for the pipeline's JavaScript builder to populate additional evidence from the clientside.
44
+ - obj_name: the name of the client side object
45
+ with the JavaScript properties in it ('fod' by default)
46
+ - protocol: The protocol ("http" or "https") used by
47
+ the client side callback url. This can be overridden
48
+ with header.protocol evidence
49
+ - host The host of the client side callback url.
50
+ This can be overridden with header.host evidence.
51
+ - endpoint The endpoint of the client side callback url
52
+ * enable_cookies - whether cookies should be enabled
53
+ * minify: Whether to minify the JavaScript
54
+ @type cache: Cache
55
+ @param cache: An instance of the fiftyone.pipeline.engines.cache
56
+ class
57
+
58
+ Cloud Engine Settings:
59
+
60
+ @type resource_key: string
61
+ @param resource_key: the 51Degrees cloud resource key
62
+ @type cloud_endpoint: string
63
+ @param cloud_endpoint: the 51Degrees cloud service endpoint to use. Defaults to https://cloud.51degrees.com/api/v4/
64
+ @type cloud_request_origin: string
65
+ @param cloud_request_origin: The value to set the Origin header to when making requests to the cloud service
66
+
67
+ """
68
+ if settings is None:
69
+ settings = {}
70
+
71
+ settings = merge_two_dicts(dict(**kwargs), locals())
72
+
73
+ settings = merge_two_dicts(settings, settings["settings"])
74
+
75
+ del settings["self"]
76
+
77
+ super(IpIntelligenceCloudPipelineBuilder, self).__init__(settings)
78
+
79
+ # Add specific engines
80
+
81
+ self.add(CloudRequestEngine(settings))
82
+ ip_engine = IpIntelligenceCloud()
83
+
84
+ if "cache" in settings:
85
+ ip_engine.set_cache(settings["cache"])
86
+
87
+ self.add(ip_engine)
@@ -0,0 +1,63 @@
1
+ Metadata-Version: 2.4
2
+ Name: fiftyone_ipintelligence_cloud
3
+ Version: 0.0.1
4
+ Summary: 51Degrees IP Intelligence resolves an IP address to detailed location, network and registration information. This package retrieves IP intelligence results by consuming the 51Degrees cloud service.
5
+ Home-page: https://51degrees.com/
6
+ Author: 51Degrees Engineering
7
+ Author-email: engineering@51degrees.com
8
+ License: EUPL-1.2
9
+ Classifier: Development Status :: 5 - Production/Stable
10
+ Classifier: Programming Language :: Python
11
+ Classifier: License :: OSI Approved :: European Union Public Licence 1.2 (EUPL 1.2)
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
14
+ Requires-Python: >=3.8
15
+ Description-Content-Type: text/markdown
16
+ Requires-Dist: fiftyone_ipintelligence_shared
17
+ Dynamic: author
18
+ Dynamic: author-email
19
+ Dynamic: classifier
20
+ Dynamic: description
21
+ Dynamic: description-content-type
22
+ Dynamic: home-page
23
+ Dynamic: license
24
+ Dynamic: requires-dist
25
+ Dynamic: requires-python
26
+ Dynamic: summary
27
+
28
+ # 51Degrees IP Intelligence Engines - Cloud
29
+
30
+ ![51Degrees](https://51degrees.com/img/logo.png?utm_source=github&utm_medium=repository&utm_content=readme_main&utm_campaign=python-open-source "Data rewards the curious") **Python IP Intelligence**
31
+
32
+ [Developer Documentation](https://51degrees.com/ip-intelligence-python/index.html?utm_source=github&utm_medium=repository&utm_content=documentation&utm_campaign=python-open-source "developer documentation")
33
+
34
+ ## Introduction
35
+
36
+ This package uses the 51Degrees cloud service to resolve IP addresses to
37
+ location, network and registration information using the
38
+ [51Degrees Pipeline API](https://51degrees.com/documentation/index.html).
39
+
40
+ To use the cloud service you will need a resource key. You can obtain one
41
+ from the [51Degrees Configurator](https://configure.51degrees.com/).
42
+
43
+ ## Usage
44
+
45
+ ```python
46
+ from fiftyone_ipintelligence_cloud.ipintelligence_cloud_pipelinebuilder import IpIntelligenceCloudPipelineBuilder
47
+
48
+ pipeline = IpIntelligenceCloudPipelineBuilder(resource_key="YOUR_RESOURCE_KEY").build()
49
+
50
+ flowdata = pipeline.create_flowdata()
51
+ flowdata.evidence.add("query.client-ip-51d", "185.28.167.78")
52
+ flowdata.process()
53
+
54
+ print(flowdata.ip.registeredname.value())
55
+ ```
56
+
57
+ ## Folders
58
+
59
+ - `fiftyone_ipintelligence_cloud` - the IP intelligence cloud engine and
60
+ pipeline builder.
61
+ - `tests` - unit tests. These mock the cloud service so no resource key is
62
+ required; set the `resource_key` environment variable to also run the live
63
+ cloud integration test.
@@ -0,0 +1,7 @@
1
+ fiftyone_ipintelligence_cloud/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ fiftyone_ipintelligence_cloud/ipintelligence_cloud.py,sha256=ItQiK5i3Z7yVaPkuLmxiX1KBPG7QKKgHfqBDVIf1ytw,3884
3
+ fiftyone_ipintelligence_cloud/ipintelligence_cloud_pipelinebuilder.py,sha256=AJ-OfWiBwvrdM3NI5xxh8C_cYdY8_09dJjVD4S1NqXY,3762
4
+ fiftyone_ipintelligence_cloud-0.0.1.dist-info/METADATA,sha256=XNNRQ0whXB4KIo6PimEB6aJ7YqxBDjmaRjIuA8_c8qw,2522
5
+ fiftyone_ipintelligence_cloud-0.0.1.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
6
+ fiftyone_ipintelligence_cloud-0.0.1.dist-info/top_level.txt,sha256=suslTymgtuK22xc4T5Yl9nUUOQzXCnKGx9-hiwS4q9o,30
7
+ fiftyone_ipintelligence_cloud-0.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ fiftyone_ipintelligence_cloud