Skip to content

Commit 88b35cd

Browse files
committed
document the library
1 parent 5603ab5 commit 88b35cd

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,37 @@ pip install ipinfo
3333
'37.3861,-122.0840'
3434
```
3535

36+
#### Async/Await
37+
38+
An asynchronous handler is available as well, and can be accessed and used in
39+
almost the same exact way as the synchronous handler:
40+
41+
```python
42+
>>> import ipinfo
43+
>>> access_token = '123456789abc'
44+
>>> handler = ipinfo.getHandlerAsync(access_token)
45+
>>> ip_address = '216.239.36.21'
46+
>>> async def do_req():
47+
... details = await handler.getDetails(ip_address)
48+
... print(details.city)
49+
... print(details.loc)
50+
...
51+
>>>
52+
>>> import asyncio
53+
>>> loop = asyncio.get_event_loop()
54+
>>> loop.run_until_complete(do_req())
55+
Mountain View
56+
37.4056,-122.0775
57+
>>>
58+
>>> ip_address = '1.1.1.1'
59+
>>> loop.run_until_complete(do_req())
60+
New York City
61+
40.7143,-74.0060
62+
```
63+
64+
Internally the library uses `aiohttp`, but as long as you provide an event
65+
loop (as in this example via `asyncio`), it shouldn't matter.
66+
3667
### Usage
3768

3869
The `Handler.getDetails()` method accepts an IP address as an optional, positional argument. If no IP address is specified, the API will return data for the IP address from which it receives the request.
@@ -158,6 +189,9 @@ handler = ipinfo.getHandler(cache=MyCustomCache())
158189

159190
### Modifying request options
160191

192+
**Note**: the asynchronous handler currently only accepts the `timeout` option,
193+
input the same way as shown below.
194+
161195
Request behavior can be modified by setting the `request_options` keyword argument. `request_options` is a dictionary in which the keys are keyword arguments specified in the `requests` library. The nesting of keyword arguments is to prevent name collisions between this library and its dependencies.
162196

163197
- Default request timeout: 2 seconds

0 commit comments

Comments
 (0)