Skip to content

Commit de7fceb

Browse files
committed
Document how to use the GeoLite2 web service
1 parent 1f6df9a commit de7fceb

File tree

2 files changed

+35
-22
lines changed

2 files changed

+35
-22
lines changed

README.rst

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,14 @@ should not be used to identify a particular address or household.
4545
Web Service Usage
4646
-----------------
4747

48-
To use this API, you first create either a web service object with your
49-
MaxMind ``account_id`` and ``license_key`` or a database reader object with the
50-
path to your database file. After doing this, you may call the method
51-
corresponding to request type (e.g., ``city`` or ``country``), passing it the
52-
IP address you want to look up.
48+
To use this API, you first construct either a ``geoip2.webservice.Client`` or
49+
``geoip2.webservice.AsyncClient``, passing your MaxMind ``account_id`` and
50+
``license_key`` to the constructor. To use the GeoLite2 web service instead of
51+
GeoIP2 Precision, set the optional ``host`` keyword argument to
52+
``geolite.info``.
53+
54+
After doing this, you may call the method corresponding to request type
55+
(e.g., ``city`` or ``country``), passing it the IP address you want to look up.
5356

5457
If the request succeeds, the method call will return a model class for the
5558
end point you called. This model in turn contains multiple record classes,
@@ -66,12 +69,14 @@ Sync Web Service Example
6669
>>>
6770
>>> # This creates a Client object that can be reused across requests.
6871
>>> # Replace "42" with your account ID and "license_key" with your license
69-
>>> # key.
72+
>>> # key. Set the "host" keyword argument to "geolite.info" to use the
73+
>>> # GeoLite2 web service instead of GeoIP2 Precision.
7074
>>> with geoip2.webservice.Client(42, 'license_key') as client:
7175
>>>
72-
>>> # Replace "insights" with the method corresponding to the web service
73-
>>> # that you are using, e.g., "country", "city".
74-
>>> response = client.insights('203.0.113.0')
76+
>>> # Replace "city" with the method corresponding to the web service
77+
>>> # that you are using, i.e., "country", "city", or "insights". Please
78+
>>> # note that Insights is not supported by the GeoLite2 web service.
79+
>>> response = client.city('203.0.113.0')
7580
>>>
7681
>>> response.country.iso_code
7782
'US'
@@ -114,12 +119,14 @@ Async Web Service Example
114119
>>> # loops, you must ensure the object is not used on another loop.
115120
>>> #
116121
>>> # Replace "42" with your account ID and "license_key" with your license
117-
>>> # key.
122+
>>> # key. Set the "host" keyword argument to "geolite.info" to use the
123+
>>> # GeoLite2 web service instead of GeoIP2 Precision.
118124
>>> async with geoip2.webservice.AsyncClient(42, 'license_key') as client:
119125
>>>
120-
>>> # Replace "insights" with the method corresponding to the web service
121-
>>> # that you are using, e.g., "country", "city".
122-
>>> response = await client.insights('203.0.113.0')
126+
>>> # Replace "city" with the method corresponding to the web service
127+
>>> # that you are using, i.e., "country", "city", or "insights". Please
128+
>>> # note that Insights is not supported by the GeoLite2 web service.
129+
>>> response = await client.city('203.0.113.0')
123130
>>>
124131
>>> response.country.iso_code
125132
'US'

geoip2/webservice.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
SSL
2222
---
2323
24-
Requests to the GeoIP2 Precision web service are always made with SSL.
24+
Requests to the web service are always made with SSL.
2525
2626
"""
2727

@@ -219,8 +219,8 @@ class AsyncClient(BaseClient):
219219
The following keyword arguments are also accepted:
220220
221221
:param host: The hostname to make a request against. This defaults to
222-
"geoip.maxmind.com". In most cases, you should not need to set this
223-
explicitly.
222+
"geoip.maxmind.com". To use the GeoLite2 web service instead of GeoIP2
223+
Precision, set this to "geolite.info".
224224
:param locales: This is list of locale codes. This argument will be
225225
passed on to record classes to use when their name properties are
226226
called. The default value is ['en'].
@@ -276,7 +276,7 @@ def __init__( # pylint: disable=too-many-arguments
276276
self._proxy = proxy
277277

278278
async def city(self, ip_address: IPAddress = "me") -> City:
279-
"""Call GeoIP2 Precision City endpoint with the specified IP.
279+
"""Call City endpoint with the specified IP.
280280
281281
:param ip_address: IPv4 or IPv6 address as a string. If no
282282
address is provided, the address that the web service is
@@ -305,7 +305,10 @@ async def country(self, ip_address: IPAddress = "me") -> Country:
305305
)
306306

307307
async def insights(self, ip_address: IPAddress = "me") -> Insights:
308-
"""Call the GeoIP2 Precision: Insights endpoint with the specified IP.
308+
"""Call the Insights endpoint with the specified IP.
309+
310+
Insights is only supported by GeoIP2 Precision. The GeoLite2 web
311+
service does not support it.
309312
310313
:param ip_address: IPv4 or IPv6 address as a string. If no address
311314
is provided, the address that the web service is called from will
@@ -375,8 +378,8 @@ class Client(BaseClient):
375378
The following keyword arguments are also accepted:
376379
377380
:param host: The hostname to make a request against. This defaults to
378-
"geoip.maxmind.com". In most cases, you should not need to set this
379-
explicitly.
381+
"geoip.maxmind.com". To use the GeoLite2 web service instead of GeoIP2
382+
Precision, set this to "geolite.info".
380383
:param locales: This is list of locale codes. This argument will be
381384
passed on to record classes to use when their name properties are
382385
called. The default value is ['en'].
@@ -434,7 +437,7 @@ def __init__( # pylint: disable=too-many-arguments
434437
self._proxies = {"https": proxy}
435438

436439
def city(self, ip_address: IPAddress = "me") -> City:
437-
"""Call GeoIP2 Precision City endpoint with the specified IP.
440+
"""Call City endpoint with the specified IP.
438441
439442
:param ip_address: IPv4 or IPv6 address as a string. If no
440443
address is provided, the address that the web service is
@@ -460,7 +463,10 @@ def country(self, ip_address: IPAddress = "me") -> Country:
460463
)
461464

462465
def insights(self, ip_address: IPAddress = "me") -> Insights:
463-
"""Call the GeoIP2 Precision: Insights endpoint with the specified IP.
466+
"""Call the Insights endpoint with the specified IP.
467+
468+
Insights is only supported by GeoIP2 Precision. The GeoLite2 web
469+
service does not support it.
464470
465471
:param ip_address: IPv4 or IPv6 address as a string. If no address
466472
is provided, the address that the web service is called from will

0 commit comments

Comments
 (0)