Skip to content

Commit c5c3169

Browse files
author
Uman Shahzad
committed
Undo certain changes, fix markup.
1 parent af24f61 commit c5c3169

File tree

1 file changed

+51
-53
lines changed

1 file changed

+51
-53
lines changed

README.md

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,87 @@
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

1818
```bash
1919
pip install ipinfo
2020
```
2121

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

2424
```python
25-
import ipinfo
26-
27-
handler = ipinfo.getHandler(access_token='123456789abc')
28-
details = handler.getDetails(ip_address='216.239.36.21')
29-
print(details.city) # Emeryville
30-
print(details.loc) # 37.8342,-122.2900
25+
>>> import ipinfo
26+
>>> access_token = '123456789abc'
27+
>>> handler = ipinfo.getHandler(access_token)
28+
>>> ip_address = '216.239.36.21'
29+
>>> details = handler.getDetails(ip_address)
30+
>>> details.city
31+
Emeryville
32+
>>> details.loc
33+
37.8342,-122.2900
3134
```
3235

33-
#### Usage
36+
### Usage
3437

3538
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.
3639

3740
```python
38-
import ipinfo
39-
40-
access_token = '123456789abc'
41-
handler = ipinfo.getHandler(access_token)
42-
details = handler.getDetails()
43-
print(details.city) # Emeryville
44-
print(details.loc) # 37.8342,-122.2900
41+
>>> import ipinfo
42+
>>> access_token = '123456789abc'
43+
>>> handler = ipinfo.getHandler(access_token)
44+
>>> details = handler.getDetails()
45+
>>> details.city
46+
Emeryville
47+
>>> details.loc
48+
37.8342,-122.2900
4549
```
4650

47-
#### Authentication
51+
### Authentication
4852

4953
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.
5054

5155
```python
52-
import ipinfo
53-
54-
handler = ipinfo.getHandler(access_token='123456789abc')
56+
>>> import ipinfo
57+
>>> handler = ipinfo.getHandler(access_token='123456789abc')
5558
```
5659

57-
#### Details Data
60+
### Details Data
5861

5962
`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.
6063

61-
```
64+
```python
6265
>>> details.hostname
6366
cpe-104-175-221-247.socal.res.rr.com
6467
```
6568

66-
##### Country Name
67-
69+
#### Country Name
6870

6971
`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.
7072

71-
```
73+
```python
7274
>>> details.country
7375
US
7476
>>> details.country_name
7577
United States
7678
```
7779

78-
#### IP Address
79-
80+
### IP Address
8081

8182
`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.
8283

83-
```
84+
```python
8485
>>> details.ip
8586
104.175.221.247
8687
>>> type(details.ip)
@@ -91,12 +92,11 @@ United States
9192
<class 'ipaddress.IPv4Address'>
9293
```
9394

94-
##### Longitude and Latitude
95-
95+
#### Longitude and Latitude
9696

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

99-
```
99+
```python
100100
>>> details.loc
101101
34.0293,-118.3570
102102
>>> details.latitude
@@ -105,11 +105,11 @@ United States
105105
-118.3570
106106
```
107107

108-
##### Accessing all properties
108+
#### Accessing all properties
109109

110110
`details.all` will return all details data as a dictionary.
111111

112-
```
112+
```python
113113
>>> details.all
114114
{
115115
'asn': { 'asn': 'AS20001',
@@ -135,24 +135,23 @@ United States
135135
}
136136
```
137137

138-
#### Caching
138+
### Caching
139139

140140
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.
141141

142-
##### Modifying cache options
142+
#### Modifying cache options
143143

144144
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.
145145

146-
* Default maximum cache size: 4096 (multiples of 2 are recommended to increase efficiency)
147-
* 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)
148148

149149
```python
150-
import ipinfo
151-
152-
handler = ipinfo.getHandler(cache_options={'ttl':30, 'maxsize': 128})
150+
>>> import ipinfo
151+
>>> handler = ipinfo.getHandler(cache_options={'ttl':30, 'maxsize': 128})
153152
```
154153

155-
##### Using a different cache
154+
#### Using a different cache
156155

157156
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).
158157

@@ -166,18 +165,17 @@ class MyCustomCache(CacheInterface):
166165
handler = ipinfo.getHandler(cache=MyCustomCache())
167166
```
168167

169-
#### Modifying request options
168+
### Modifying request options
170169

171170
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.
172171

173-
* Default request timeout: 2 seconds
172+
- Default request timeout: 2 seconds
174173

175-
```
174+
```python
176175
>>> handler = ipinfo.getHandler(request_options={'timeout': 4})
177176
```
178177

179-
180-
#### Internationalization
178+
### Internationalization
181179

182180
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.
183181

@@ -193,11 +191,11 @@ The file must be a `.json` file with the following structure:
193191
}
194192
```
195193

196-
### Other Libraries
194+
## Other Libraries
197195

198196
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.
199197

200-
### About IPinfo
198+
## About IPinfo
201199

202200
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.
203201

0 commit comments

Comments
 (0)