Skip to content

Commit 2176bcb

Browse files
authored
Merge pull request #38 from ipinfo/lite-api-readme-update
Update `README.md` with instruction for Lite API middlewares
2 parents 657489d + 154ae58 commit 2176bcb

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

README.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ You'll need an IPinfo API access token, which you can get by signing up for a fr
1515

1616
The free plan is limited to 50,000 requests per month, and doesn't include some of the data fields such as IP type and company data. To enable all the data fields and additional request volumes see [https://ipinfo.io/pricing](https://ipinfo.io/pricing)
1717

18-
⚠️ Note: This library does not currently support our newest free API https://ipinfo.io/lite. If you’d like to use IPinfo Lite, you can call the [endpoint directly](https://ipinfo.io/developers/lite-api) using your preferred HTTP client. Developers are also welcome to contribute support for Lite by submitting a pull request.
18+
The library also supports the Lite API, see the [Lite API section](#lite-api) for more info.
1919

2020
#### Installation
2121

@@ -48,6 +48,7 @@ will return the following as an `HttpResponse` object:
4848
```
4949

5050
To get the details of a user-defined IP, we will import the ipinfo package directly to the `view.py` file:
51+
5152
```python
5253
from django.shortcuts import render
5354
from django.http import HttpResponse
@@ -207,7 +208,7 @@ IPINFO_TOKEN = '123456789abc'
207208

208209
### Caching
209210

210-
In-memory caching of `details` data is provided by default via the `cachetools <https://cachetools.readthedocs.io/en/latest/>`_ library. This uses an LRU (least recently used) cache with a TTL (time to live) by default. This means that values will be cached for the specified duration; if the cache's max size is reached, cache values will be invalidated as necessary, starting with the oldest cached value.
211+
In-memory caching of `details` data is provided by default via the `cachetools <https://cachetools.readthedocs.io/en/latest/>`\_ library. This uses an LRU (least recently used) cache with a TTL (time to live) by default. This means that values will be cached for the specified duration; if the cache's max size is reached, cache values will be invalidated as necessary, starting with the oldest cached value.
211212

212213
#### Modifying cache options
213214

@@ -269,10 +270,10 @@ To turn off filtering:
269270
IPINFO_FILTER = None
270271
```
271272

272-
To set your own filtering rules, *thereby replacing the default filter*, you can set `settings.IPINFO_FILTER` to your own, custom callable function which satisfies the following rules:
273+
To set your own filtering rules, _thereby replacing the default filter_, you can set `settings.IPINFO_FILTER` to your own, custom callable function which satisfies the following rules:
273274

274275
- Accepts one request.
275-
- Returns *True to filter out, False to allow lookup*
276+
- Returns _True to filter out, False to allow lookup_
276277

277278
To use your own filter rules:
278279

@@ -331,6 +332,25 @@ If there's an error while making a request to IPinfo (e.g. your token was rate
331332
limited, there was a network issue, etc.), then the traceback will be logged
332333
using the built-in Python logger, and `HttpRequest.ipinfo` will be `None`.
333334

335+
### Lite API
336+
337+
The library gives the possibility to use the [Lite API](https://ipinfo.io/developers/lite-api) too, authentication with your token is still required.
338+
339+
The IP details returned are slightly different from the Core API middleware, though the arguments are identical.
340+
341+
To use it add `'ipinfo_django.middleware.IPinfoLiteMiddleware'` to `settings.MIDDLEWARE` in `settings.py`:
342+
343+
```python
344+
MIDDLEWARE = [
345+
'django.middleware.security.SecurityMiddleware',
346+
'django.contrib.sessions.middleware.SessionMiddleware',
347+
...
348+
'ipinfo_django.middleware.IPinfoLiteMiddleware',
349+
]
350+
```
351+
352+
We also provide an async Lite API middleware to be used under ASGI. Use `'ipinfo_django.middleware.IPinfoAsyncLiteMiddleware` in that case.
353+
334354
### Local development and testing
335355

336356
To test the project locally, install Tox in your Python virtual environment:

0 commit comments

Comments
 (0)