Skip to content

Commit 89cbd84

Browse files
committed
add population_density and average_income to location
1 parent 1ab8542 commit 89cbd84

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

geoip2/records.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,13 @@ class Location(Record):
255255
256256
Attributes:
257257
258+
.. attribute:: average_income
259+
260+
The average income in US dollars associated with the requested IP address
261+
This attribute is only available from the Insights end point.
262+
263+
:type: int
264+
258265
.. attribute:: accuracy_radius
259266
260267
The radius in kilometers around the
@@ -269,7 +276,6 @@ class Location(Record):
269276
270277
:type: float
271278
272-
273279
.. attribute:: longitude
274280
275281
The longitude of the location as a
@@ -286,6 +292,13 @@ class Location(Record):
286292
287293
:type: int
288294
295+
.. attribute:: population_density
296+
297+
The estimated population per square kilometer associated with the IP
298+
address. This attribute is only available from the Insights end point.
299+
300+
:type: int
301+
289302
.. attribute:: time_zone
290303
291304
The time zone associated with location, as
@@ -295,9 +308,9 @@ class Location(Record):
295308
:type: unicode
296309
297310
"""
298-
_valid_attributes = set(['accuracy_radius', 'latitude', 'longitude',
299-
'metro_code', 'postal_code', 'postal_confidence',
300-
'time_zone'])
311+
_valid_attributes = set(['average_income', 'accuracy_radius', 'latitude',
312+
'longitude', 'metro_code', 'population_density',
313+
'postal_code', 'postal_confidence', 'time_zone'])
301314

302315

303316
class MaxMind(Record):

tests/models_test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ def test_insights_full(self):
3939
'names': {'en': 'United States of America'},
4040
},
4141
'location': {
42+
'average_income': 24626,
4243
'accuracy_radius': 1500,
4344
'latitude': 44.98,
4445
'longitude': 93.2636,
4546
'metro_code': 765,
47+
'population_density': 1341,
4648
'time_zone': 'America/Chicago',
4749
},
4850
'postal': {
@@ -127,12 +129,16 @@ def test_insights_full(self):
127129
self.assertEqual(model.represented_country.type,
128130
'military',
129131
'represented_country type is correct')
132+
self.assertEqual(model.location.average_income, 24626,
133+
'correct average_income')
130134
self.assertEqual(model.location.latitude, 44.98,
131135
'correct latitude')
132136
self.assertEqual(model.location.longitude, 93.2636,
133137
'correct longitude')
134138
self.assertEqual(model.location.metro_code, 765,
135139
'correct metro_code')
140+
self.assertEqual(model.location.population_density, 1341,
141+
'correct population_density')
136142

137143
self.assertRegex(
138144
str(

0 commit comments

Comments
 (0)