You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
8
4
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)
9
9
10
-
###Getting Started
10
+
## Getting Started
11
11
12
12
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).
13
13
14
14
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)
15
15
16
-
####Installation
16
+
### Installation
17
17
18
-
```
18
+
```bash
19
19
pip install ipinfo
20
20
```
21
21
22
-
####Quick Start
22
+
### Quick Start
23
23
24
-
```
24
+
```python
25
25
>>>import ipinfo
26
26
>>> access_token ='123456789abc'
27
27
>>> handler = ipinfo.getHandler(access_token)
@@ -33,11 +33,11 @@ Emeryville
33
33
37.8342,-122.2900
34
34
```
35
35
36
-
####Usage
36
+
### Usage
37
37
38
38
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.
39
39
40
-
```
40
+
```python
41
41
>>>import ipinfo
42
42
>>> access_token ='123456789abc'
43
43
>>> handler = ipinfo.getHandler(access_token)
@@ -48,42 +48,40 @@ Emeryville
48
48
37.8342,-122.2900
49
49
```
50
50
51
-
####Authentication
51
+
### Authentication
52
52
53
53
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.
`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.
63
63
64
-
```
64
+
```python
65
65
>>> details.hostname
66
66
cpe-104-175-221-247.socal.res.rr.com
67
67
```
68
68
69
-
##### Country Name
70
-
69
+
#### Country Name
71
70
72
71
`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.
73
72
74
-
```
73
+
```python
75
74
>>> details.country
76
75
US
77
76
>>> details.country_name
78
77
United States
79
78
```
80
79
81
-
#### IP Address
82
-
80
+
### IP Address
83
81
84
82
`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.
85
83
86
-
```
84
+
```python
87
85
>>> details.ip
88
86
104.175.221.247
89
87
>>>type(details.ip)
@@ -94,12 +92,11 @@ United States
94
92
<class'ipaddress.IPv4Address'>
95
93
```
96
94
97
-
##### Longitude and Latitude
98
-
95
+
#### Longitude and Latitude
99
96
100
97
`details.latitude` and `details.longitude` will return latitude and longitude, respectively, as strings. `details.loc` will still return a composite string of both values.
101
98
102
-
```
99
+
```python
103
100
>>> details.loc
104
101
34.0293,-118.3570
105
102
>>> details.latitude
@@ -108,11 +105,11 @@ United States
108
105
-118.3570
109
106
```
110
107
111
-
#####Accessing all properties
108
+
#### Accessing all properties
112
109
113
110
`details.all` will return all details data as a dictionary.
114
111
115
-
```
112
+
```python
116
113
>>> details.all
117
114
{
118
115
'asn': { 'asn': 'AS20001',
@@ -138,61 +135,67 @@ United States
138
135
}
139
136
```
140
137
141
-
####Caching
138
+
### Caching
142
139
143
140
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.
144
141
145
-
#####Modifying cache options
142
+
#### Modifying cache options
146
143
147
144
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.
148
145
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)
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).
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.
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.
178
181
179
182
The file must be a `.json` file with the following structure:
180
183
181
-
```
184
+
```json
182
185
{
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
+
...
188
191
}
189
192
```
190
193
191
-
###Other Libraries
194
+
## Other Libraries
192
195
193
196
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.
194
197
195
-
###About IPinfo
198
+
## About IPinfo
196
199
197
200
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.
Copy file name to clipboardExpand all lines: setup.py
+7-1Lines changed: 7 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,12 @@
1
1
fromsetuptoolsimportsetup
2
2
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.
0 commit comments