Skip to content

Commit 9fdfc6a

Browse files
Add function to IpregistryConfig to simplify usage of eu base URL
1 parent fbeb100 commit 9fdfc6a

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,18 @@ from ipregistry import IpregistryClient, NoCache
114114
client = IpregistryClient("YOUR_API_KEY", cache=NoCache())
115115
```
116116

117+
### European Union Base URL
118+
119+
With the ever-increasing concerns about data privacy and security, we recognize the importance of providing our European users with a dedicated API base URL:
120+
121+
```python
122+
from ipregistry import IpregistryClient, NoCache
123+
124+
client = IpregistryClient(IpregistryConfig("YOUR_API_KEY").with_eu_base_url())
125+
```
126+
127+
Using this base URL your requests are handled by the closest cluster of nodes in the European Union.
128+
117129
### Errors
118130

119131
All Ipregistry exceptions inherit `IpregistryError` class.

ipregistry/core.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ def __init__(self, key, base_url="https://api.ipregistry.co", timeout=5):
169169
self.base_url = base_url
170170
self.timeout = timeout
171171

172+
def with_eu_base_url(self):
173+
self.base_url = 'https://eu.api.ipregistry.co'
174+
return self
175+
172176
def __str__(self):
173177
"""
174178
Return a string representation of the IpregistryConfig instance.

tests/test_client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,16 @@ def test_lookup_ip(self):
117117
self.assertIsNotNone(response.data.company.domain)
118118
self.assertEqual('US', response.data.location.country.code)
119119

120+
def test_lookup_ip_with_eu_base_url(self):
121+
"""
122+
Test a simple IP lookup with the EU base URL
123+
"""
124+
client = IpregistryClient(IpregistryConfig(os.getenv('IPREGISTRY_API_KEY')).with_eu_base_url())
125+
response = client.lookup_ip('8.8.8.8')
126+
self.assertIsNotNone(response.data.ip)
127+
self.assertIsNotNone(response.data.company.domain)
128+
self.assertEqual('US', response.data.location.country.code)
129+
120130
def test_lookup_ip_invalid_input(self):
121131
"""
122132
Test that an IP lookup with an invalid input fails with an ApiError

0 commit comments

Comments
 (0)