Skip to content

Commit 25ec33b

Browse files
authored
Merge pull request #2 from UmanShahzad/uman/text
Improve `README.md`
2 parents c3166d0 + c5c3169 commit 25ec33b

File tree

2 files changed

+60
-51
lines changed

2 files changed

+60
-51
lines changed

README.md

Lines changed: 53 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
# [<img src="https://ipinfo.io/static/ipinfo-small.svg" alt="IPinfo" width="24"/>](https://ipinfo.io/) IPinfo Python Client Library
22

33
This is the official Python client library for the [IPinfo.io](https://ipinfo.io) IP address API, allowing you to lookup your own IP address, or get any of the following details for an IP:
4-
- IP geolocation (city, region, country, postal code, latitude and longitude)
5-
- ASN details (ISP or network operator, associated domain name, and type, such as business, hosting or company)
6-
- Company details (the name and domain of the business that uses the IP address)
7-
- Carrier details (the name of the mobile carrier and MNC and MCC for that carrier if the IP is used exclusively for mobile traffic)
84

5+
- IP geolocation (city, region, country, postal code, latitude and longitude)
6+
- ASN details (ISP or network operator, associated domain name, and type, such as business, hosting or company)
7+
- Company details (the name and domain of the business that uses the IP address)
8+
- Carrier details (the name of the mobile carrier and MNC and MCC for that carrier if the IP is used exclusively for mobile traffic)
99

10-
### Getting Started
10+
## Getting Started
1111

1212
You'll need an IPinfo API access token, which you can get by singing up for a free account at [https://ipinfo.io/signup](https://ipinfo.io/signup?ref=lib-Python).
1313

1414
The free plan is limited to 1,000 requests a day, 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?ref=lib-Python)
1515

16-
#### Installation
16+
### Installation
1717

18-
```
18+
```bash
1919
pip install ipinfo
2020
```
2121

22-
#### Quick Start
22+
### Quick Start
2323

24-
```
24+
```python
2525
>>> import ipinfo
2626
>>> access_token = '123456789abc'
2727
>>> handler = ipinfo.getHandler(access_token)
@@ -33,11 +33,11 @@ Emeryville
3333
37.8342,-122.2900
3434
```
3535

36-
#### Usage
36+
### Usage
3737

3838
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.
3939

40-
```
40+
```python
4141
>>> import ipinfo
4242
>>> access_token = '123456789abc'
4343
>>> handler = ipinfo.getHandler(access_token)
@@ -48,42 +48,40 @@ Emeryville
4848
37.8342,-122.2900
4949
```
5050

51-
#### Authentication
51+
### Authentication
5252

5353
The IPinfo library can be authenticated with your IPinfo API token, which is passed in as a positional argument. It also works without an authentication token, but in a more limited capacity.
5454

55-
```
56-
>>> access_token = '123456789abc'
57-
>>> handler = ipinfo.getHandler(access_token)
55+
```python
56+
>>> import ipinfo
57+
>>> handler = ipinfo.getHandler(access_token='123456789abc')
5858
```
5959

60-
#### Details Data
60+
### Details Data
6161

6262
`handler.getDetails()` will return a `Details` object that contains all fields listed in the [IPinfo developer docs](https://ipinfo.io/developers/responses#full-response) with a few minor additions. Properties can be accessed directly.
6363

64-
```
64+
```python
6565
>>> details.hostname
6666
cpe-104-175-221-247.socal.res.rr.com
6767
```
6868

69-
##### Country Name
70-
69+
#### Country Name
7170

7271
`details.country_name` will return the country name, as supplied by the `countries.json` file. See below for instructions on changing that file for use with non-English languages. `details.country` will still return country code.
7372

74-
```
73+
```python
7574
>>> details.country
7675
US
7776
>>> details.country_name
7877
United States
7978
```
8079

81-
#### IP Address
82-
80+
### IP Address
8381

8482
`details.ip_address` will return the an `ipaddress` object from the [Python Standard Library](https://docs.python.org/3/library/ipaddress.html). `details.ip` will still return a string.
8583

86-
```
84+
```python
8785
>>> details.ip
8886
104.175.221.247
8987
>>> type(details.ip)
@@ -94,12 +92,11 @@ United States
9492
<class 'ipaddress.IPv4Address'>
9593
```
9694

97-
##### Longitude and Latitude
98-
95+
#### Longitude and Latitude
9996

10097
`details.latitude` and `details.longitude` will return latitude and longitude, respectively, as strings. `details.loc` will still return a composite string of both values.
10198

102-
```
99+
```python
103100
>>> details.loc
104101
34.0293,-118.3570
105102
>>> details.latitude
@@ -108,11 +105,11 @@ United States
108105
-118.3570
109106
```
110107

111-
##### Accessing all properties
108+
#### Accessing all properties
112109

113110
`details.all` will return all details data as a dictionary.
114111

115-
```
112+
```python
116113
>>> details.all
117114
{
118115
'asn': { 'asn': 'AS20001',
@@ -138,61 +135,67 @@ United States
138135
}
139136
```
140137

141-
#### Caching
138+
### Caching
142139

143140
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.
144141

145-
##### Modifying cache options
142+
#### Modifying cache options
146143

147144
Cache behavior can be modified by setting the `cache_options` keyword argument. `cache_options` is a dictionary in which the keys are keyword arguments specified in the `cachetools` library. The nesting of keyword arguments is to prevent name collisions between this library and its dependencies.
148145

149-
* Default maximum cache size: 4096 (multiples of 2 are recommended to increase efficiency)
150-
* Default TTL: 24 hours (in seconds)
146+
- Default maximum cache size: 4096 (multiples of 2 are recommended to increase efficiency)
147+
- Default TTL: 24 hours (in seconds)
151148

152-
```
149+
```python
150+
>>> import ipinfo
153151
>>> handler = ipinfo.getHandler(cache_options={'ttl':30, 'maxsize': 128})
154152
```
155153

156-
##### Using a different cache
154+
#### Using a different cache
157155

158-
It's possible to use a custom cache by creating a child class of the [CacheInterface](https://github.com/ipinfo/python/blob/master/ipinfo_wrapper/cache/interface.py) class and passing this into the handler object with the `cache` keyword argument. FYI this is known as [the Strategy Pattern](https://sourcemaking.com/design_patterns/strategy).
156+
It's possible to use a custom cache by creating a child class of the [CacheInterface](https://github.com/ipinfo/python/blob/master/ipinfo/cache/interface.py) class and passing this into the handler object with the `cache` keyword argument. FYI this is known as [the Strategy Pattern](https://sourcemaking.com/design_patterns/strategy).
159157

160-
```
161-
>>> handler = ipinfo.getHandler(cache=my_fancy_custom_class)
158+
```python
159+
import ipinfo
160+
from ipinfo.cache.interface import CacheInterface
161+
162+
class MyCustomCache(CacheInterface):
163+
...
164+
165+
handler = ipinfo.getHandler(cache=MyCustomCache())
162166
```
163167

164-
#### Modifying request options
168+
### Modifying request options
165169

166170
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.
167171

168-
* Default request timeout: 2 seconds
172+
- Default request timeout: 2 seconds
169173

170-
```
174+
```python
171175
>>> handler = ipinfo.getHandler(request_options={'timeout': 4})
172176
```
173177

174-
175-
#### Internationalization
178+
### Internationalization
176179

177180
When looking up an IP address, the response object includes a `details.country_name` attribute which includes the country name based on American English. It is possible to return the country name in other languages by setting the `countries_file` keyword argument when creating the `IPinfo` object.
178181

179182
The file must be a `.json` file with the following structure:
180183

181-
```
184+
```json
182185
{
183-
"BD": "Bangladesh",
184-
"BE": "Belgium",
185-
"BF": "Burkina Faso",
186-
"BG": "Bulgaria"
187-
...
186+
"BD": "Bangladesh",
187+
"BE": "Belgium",
188+
"BF": "Burkina Faso",
189+
"BG": "Bulgaria",
190+
...
188191
}
189192
```
190193

191-
### Other Libraries
194+
## Other Libraries
192195

193196
There are official IPinfo client libraries available for many languages including PHP, Go, Java, Ruby, and many popular frameworks such as Django, Rails and Laravel. There are also many third party libraries and integrations available for our API.
194197

195-
### About IPinfo
198+
## About IPinfo
196199

197200
Founded in 2013, IPinfo prides itself on being the most reliable, accurate, and in-depth source of IP address data available anywhere. We process terabytes of data to produce our custom IP geolocation, company, carrier and IP type data sets. Our API handles over 12 billion requests a month for 100,000 businesses and developers.
198201

setup.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
from setuptools import setup
22

3-
long_description = 'The official Python library for IPinfo. IPinfo prides itself on being the most reliable, accurate, and in-depth source of IP address data available anywhere. We process terabytes of data to produce our custom IP geolocation, company, carrier and IP type data sets. You can visit our developer docs at https://ipinfo.io/developers.'
3+
long_description = """
4+
The official Python library for IPinfo.
5+
6+
IPinfo prides itself on being the most reliable, accurate, and in-depth source of IP address data available anywhere.
7+
We process terabytes of data to produce our custom IP geolocation, company, carrier and IP type data sets.
8+
You can visit our developer docs at https://ipinfo.io/developers.
9+
"""
410

511
setup(name='ipinfo',
612
version='1.1.0',

0 commit comments

Comments
 (0)