ebird-api 3.0.6__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ebird/api/__init__.py +51 -0
- ebird/api/checklists.py +97 -0
- ebird/api/client.py +338 -0
- ebird/api/constants.py +93 -0
- ebird/api/hotspots.py +143 -0
- ebird/api/observations.py +629 -0
- ebird/api/regions.py +109 -0
- ebird/api/statistics.py +86 -0
- ebird/api/taxonomy.py +181 -0
- ebird/api/utils.py +165 -0
- ebird/api/validation.py +329 -0
- ebird_api-3.0.6.dist-info/LICENSE.txt +21 -0
- ebird_api-3.0.6.dist-info/METADATA +321 -0
- ebird_api-3.0.6.dist-info/RECORD +16 -0
- ebird_api-3.0.6.dist-info/WHEEL +6 -0
- ebird_api-3.0.6.dist-info/top_level.txt +1 -0
ebird/api/validation.py
ADDED
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
# pylint: disable=C0111
|
|
2
|
+
|
|
3
|
+
"""Functions for validation."""
|
|
4
|
+
|
|
5
|
+
import re
|
|
6
|
+
|
|
7
|
+
from datetime import date, datetime
|
|
8
|
+
from enum import Enum
|
|
9
|
+
|
|
10
|
+
from ebird.api import constants
|
|
11
|
+
|
|
12
|
+
_locales = constants.LOCALES.values()
|
|
13
|
+
_region_types = ', '.join(constants.REGION_TYPES)
|
|
14
|
+
_sort_list = ', '.join(constants.SPECIES_SORT)
|
|
15
|
+
_species_categories = ', '.join(constants.SPECIES_CATEGORIES)
|
|
16
|
+
_species_ordering = ', '.join(constants.SPECIES_ORDERING)
|
|
17
|
+
_top_100_rank = ', '.join(constants.TOP_100_RANK)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
class Transform(Enum):
|
|
21
|
+
NONE = 1
|
|
22
|
+
LOWER = 2
|
|
23
|
+
UPPER = 3
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def is_country(value):
|
|
27
|
+
return re.match(r'^\w{2}$', value)
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def is_subnational1(value):
|
|
31
|
+
return re.match(r'^\w{2}-\w{1,}$', value)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def is_subnational2(value):
|
|
35
|
+
return re.match(r'^\w{2}-\w{1,}-\w{1,}$', value)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def is_region(value):
|
|
39
|
+
return (
|
|
40
|
+
re.match(r'^\w{2}$', value) or
|
|
41
|
+
re.match(r'^\w{2}-\w{1,}$', value) or
|
|
42
|
+
re.match(r'^\w{2}-\w{1,}-\w{1,}$', value)
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def is_location(value):
|
|
47
|
+
return re.match(r'^L\d+$', value.upper())
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def get_location_type(value):
|
|
51
|
+
if not value or not isinstance(value, str):
|
|
52
|
+
raise ValueError('Location type must be a string.')
|
|
53
|
+
if is_country(value):
|
|
54
|
+
result = 'country'
|
|
55
|
+
elif is_subnational1(value):
|
|
56
|
+
result = 'subnational1'
|
|
57
|
+
elif is_subnational2(value):
|
|
58
|
+
result = 'subnational2'
|
|
59
|
+
elif is_location(value):
|
|
60
|
+
result = 'location'
|
|
61
|
+
else:
|
|
62
|
+
result = None
|
|
63
|
+
return result
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def get_location_types(items):
|
|
67
|
+
results = set()
|
|
68
|
+
for item in items:
|
|
69
|
+
results.add(get_location_type(item))
|
|
70
|
+
return list(results)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def clean_code(value, transform=Transform.NONE):
|
|
74
|
+
if not value or not isinstance(value, str):
|
|
75
|
+
raise ValueError('Code must be a string.')
|
|
76
|
+
if transform == Transform.LOWER:
|
|
77
|
+
value = value.lower()
|
|
78
|
+
elif transform == Transform.UPPER:
|
|
79
|
+
value = value.upper()
|
|
80
|
+
return value.strip()
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def clean_codes(value, transform=Transform.NONE):
|
|
84
|
+
if isinstance(value, str):
|
|
85
|
+
items = value.split(',')
|
|
86
|
+
elif isinstance(value, list):
|
|
87
|
+
items = value
|
|
88
|
+
else:
|
|
89
|
+
raise ValueError('Must be a comma-separated string or list of names')
|
|
90
|
+
|
|
91
|
+
return [clean_code(code, transform=transform) for code in items]
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
def clean_lat(value):
|
|
95
|
+
try:
|
|
96
|
+
cleaned = float(value)
|
|
97
|
+
if not -90 <= cleaned <= 90:
|
|
98
|
+
raise ValueError()
|
|
99
|
+
cleaned = "%.2f" % round(cleaned, 2)
|
|
100
|
+
except ValueError as err:
|
|
101
|
+
err.message = "Value for 'lat', %s, must be a decimal number" \
|
|
102
|
+
" in the range -90.00 to 90.00" % value
|
|
103
|
+
raise
|
|
104
|
+
|
|
105
|
+
return cleaned
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def clean_lng(value):
|
|
109
|
+
try:
|
|
110
|
+
cleaned = float(value)
|
|
111
|
+
if not -180 <= cleaned <= 180:
|
|
112
|
+
raise ValueError()
|
|
113
|
+
cleaned = "%.2f" % round(cleaned, 2)
|
|
114
|
+
except ValueError as err:
|
|
115
|
+
err.message = "Value for 'lon', %s, must be a decimal number" \
|
|
116
|
+
" in the range -180.00 to 180.00" % value
|
|
117
|
+
raise
|
|
118
|
+
|
|
119
|
+
return cleaned
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def clean_dist(value):
|
|
123
|
+
try:
|
|
124
|
+
cleaned = int(value)
|
|
125
|
+
if not 0 <= cleaned <= 50:
|
|
126
|
+
raise ValueError()
|
|
127
|
+
except ValueError as err:
|
|
128
|
+
err.message = "Value for 'dist', %s is not an integer in the" \
|
|
129
|
+
" range 0..50" % value
|
|
130
|
+
raise
|
|
131
|
+
|
|
132
|
+
return cleaned
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
def clean_back(value):
|
|
136
|
+
try:
|
|
137
|
+
cleaned = int(value)
|
|
138
|
+
if not 1 <= cleaned <= 30:
|
|
139
|
+
raise ValueError()
|
|
140
|
+
except ValueError as err:
|
|
141
|
+
err.message = "Value for 'back', %s, is not an integer in the" \
|
|
142
|
+
" range 1..30" % value
|
|
143
|
+
raise
|
|
144
|
+
|
|
145
|
+
return cleaned
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def clean_max_results(value, limit):
|
|
149
|
+
try:
|
|
150
|
+
cleaned = None if value is None else int(value)
|
|
151
|
+
if cleaned is not None:
|
|
152
|
+
if not 1 <= cleaned <= limit:
|
|
153
|
+
raise ValueError()
|
|
154
|
+
except ValueError as err:
|
|
155
|
+
err.message = "Value for 'max_results', %s, is not None or an" \
|
|
156
|
+
" integer in the range 1..%d" % (value, limit)
|
|
157
|
+
raise
|
|
158
|
+
|
|
159
|
+
return cleaned
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def clean_max_observations(value):
|
|
163
|
+
return clean_max_results(value, 10000)
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
def clean_max_observers(value):
|
|
167
|
+
return clean_max_results(value, 100)
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
def clean_max_checklists(value):
|
|
171
|
+
return clean_max_results(value, 200)
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def clean_locale(value):
|
|
175
|
+
cleaned = str(value).strip()
|
|
176
|
+
if re.match(r'^[a-zA-Z]{2}$', cleaned):
|
|
177
|
+
cleaned = cleaned.lower()
|
|
178
|
+
elif re.match(r'^[a-zA-Z]{2}_[a-zA-Z]{2,3}$', cleaned):
|
|
179
|
+
cleaned = cleaned[:2].lower() + '_' + cleaned[3:].upper()
|
|
180
|
+
|
|
181
|
+
if cleaned not in _locales:
|
|
182
|
+
raise ValueError("eBird does not support this locale: %s" % cleaned)
|
|
183
|
+
|
|
184
|
+
return cleaned
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def clean_detail(value):
|
|
188
|
+
cleaned = clean_code(value, transform=Transform.LOWER)
|
|
189
|
+
if cleaned not in ('simple', 'full'):
|
|
190
|
+
raise ValueError(
|
|
191
|
+
"Value for 'detail', %s, must be either 'simple' or 'full'" % value)
|
|
192
|
+
return cleaned
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def clean_provisional(value):
|
|
196
|
+
return 'true' if bool(value) else 'false'
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
def clean_hotspot(value):
|
|
200
|
+
return 'true' if bool(value) else 'false'
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def clean_location(value):
|
|
204
|
+
cleaned = clean_code(value, transform=Transform.UPPER)
|
|
205
|
+
if not is_location(cleaned):
|
|
206
|
+
raise ValueError('Invalid location identifier: %s' % cleaned)
|
|
207
|
+
return cleaned
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
def clean_locations(values):
|
|
211
|
+
cleaned = clean_codes(values, transform=Transform.UPPER)
|
|
212
|
+
|
|
213
|
+
if len(cleaned) > 10:
|
|
214
|
+
raise ValueError("List of locations cannot be longer than 10")
|
|
215
|
+
|
|
216
|
+
for code in cleaned:
|
|
217
|
+
if not is_location(code):
|
|
218
|
+
raise ValueError("%s is not a location code" % code)
|
|
219
|
+
|
|
220
|
+
return cleaned
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def clean_region(value):
|
|
224
|
+
cleaned = clean_code(value)
|
|
225
|
+
if cleaned == 'WORLD':
|
|
226
|
+
cleaned = cleaned.lower()
|
|
227
|
+
elif cleaned != 'world':
|
|
228
|
+
cleaned = cleaned.upper()
|
|
229
|
+
if not is_region(cleaned):
|
|
230
|
+
raise ValueError("Value for 'region', %s, must be a country, e.g. 'US',"
|
|
231
|
+
"subnational1, e.g. 'US-NV' or subnational2, e.g. 'US-NV-211'")
|
|
232
|
+
return cleaned
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
def clean_region_type(value):
|
|
236
|
+
cleaned = clean_code(value, transform=Transform.LOWER)
|
|
237
|
+
if cleaned not in constants.REGION_TYPES:
|
|
238
|
+
raise ValueError(
|
|
239
|
+
"Region type, %s, must be one or more of : %s" % (value, _region_types))
|
|
240
|
+
return cleaned
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
def clean_area(value):
|
|
244
|
+
cleaned = clean_code(value, transform=Transform.UPPER)
|
|
245
|
+
area_type = get_location_type(cleaned)
|
|
246
|
+
|
|
247
|
+
if area_type not in ['country', 'subnational1', 'subnational2', 'location']:
|
|
248
|
+
raise ValueError('Unknown type of area: %s' % area_type)
|
|
249
|
+
|
|
250
|
+
return cleaned
|
|
251
|
+
|
|
252
|
+
|
|
253
|
+
def clean_areas(values):
|
|
254
|
+
cleaned = clean_codes(values, transform=Transform.UPPER)
|
|
255
|
+
types = get_location_types(cleaned)
|
|
256
|
+
|
|
257
|
+
if len(types) > 1:
|
|
258
|
+
raise ValueError('You cannot mix different types of area together')
|
|
259
|
+
else:
|
|
260
|
+
if types[0] not in ['country', 'subnational1', 'subnational2', 'location']:
|
|
261
|
+
raise ValueError('Unknown type of area')
|
|
262
|
+
|
|
263
|
+
if len(cleaned) > 10:
|
|
264
|
+
raise ValueError("List of areas cannot be longer than 10")
|
|
265
|
+
|
|
266
|
+
return cleaned
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
def clean_categories(value):
|
|
270
|
+
cleaned = clean_codes(value, transform=Transform.LOWER)
|
|
271
|
+
for entry in cleaned:
|
|
272
|
+
if entry not in constants.SPECIES_CATEGORIES:
|
|
273
|
+
raise ValueError(
|
|
274
|
+
"Species category, %s, must be one or more of : %s" % (
|
|
275
|
+
entry, _species_categories))
|
|
276
|
+
return cleaned
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
def clean_ordering(value):
|
|
280
|
+
cleaned = clean_code(value, transform=Transform.LOWER)
|
|
281
|
+
if cleaned not in constants.SPECIES_ORDERING:
|
|
282
|
+
raise ValueError(
|
|
283
|
+
"Species ordering, %s, must be one or more of : %s" % (value, _species_ordering))
|
|
284
|
+
return cleaned
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def clean_sort(value):
|
|
288
|
+
cleaned = clean_code(value, transform=Transform.LOWER)
|
|
289
|
+
if cleaned not in constants.SPECIES_SORT:
|
|
290
|
+
raise ValueError(
|
|
291
|
+
"Species sort, %s, must be one or more of : %s" % (value, _sort_list))
|
|
292
|
+
return cleaned
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
def clean_species_code(value):
|
|
296
|
+
cleaned = clean_code(value, transform=Transform.LOWER)
|
|
297
|
+
if re.match(r'^\w{6}$', cleaned):
|
|
298
|
+
return cleaned
|
|
299
|
+
|
|
300
|
+
raise ValueError(
|
|
301
|
+
"Value for 'species code', %s, must be 6 letters, e.g. 'cangoo'" % value)
|
|
302
|
+
|
|
303
|
+
|
|
304
|
+
def clean_date(value):
|
|
305
|
+
if isinstance(value, str):
|
|
306
|
+
cleaned = datetime.strptime(value, '%Y-%m-%d').date()
|
|
307
|
+
elif isinstance(value, datetime):
|
|
308
|
+
cleaned = value.date()
|
|
309
|
+
elif isinstance(value, date):
|
|
310
|
+
cleaned = value
|
|
311
|
+
else:
|
|
312
|
+
raise ValueError("Date must be a string ('YYYY-mm-dd'),"
|
|
313
|
+
" a date or a datetime: %s" % str(value))
|
|
314
|
+
|
|
315
|
+
if cleaned.year < 1800:
|
|
316
|
+
raise ValueError('Dates cannot be earlier than Jan 1st 1800')
|
|
317
|
+
|
|
318
|
+
if cleaned > date.today():
|
|
319
|
+
raise ValueError('Date is in the future: %s' % cleaned.strftime('%Y-%m-%d'))
|
|
320
|
+
|
|
321
|
+
return cleaned.strftime('%Y/%m/%d')
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def clean_rank(value):
|
|
325
|
+
cleaned = clean_code(value, transform=Transform.LOWER)
|
|
326
|
+
if cleaned not in constants.TOP_100_RANK:
|
|
327
|
+
raise ValueError(
|
|
328
|
+
"Top 100 rank, %s, must be one or more of : %s" % (value, _top_100_rank))
|
|
329
|
+
return cleaned
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 ProjectBabbler
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: ebird-api
|
|
3
|
+
Version: 3.0.6
|
|
4
|
+
Summary: Wrapper for accessing the eBird API
|
|
5
|
+
Home-page: http://pypi.python.org/pypi/ebird-api/
|
|
6
|
+
Author: ProjectBabbler
|
|
7
|
+
Author-email: projectbabbler@gmail.com
|
|
8
|
+
License: GPL
|
|
9
|
+
Keywords: eBird API client
|
|
10
|
+
Platform: UNKNOWN
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Science/Research
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.5
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
21
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
22
|
+
Classifier: Natural Language :: English
|
|
23
|
+
Classifier: Topic :: Utilities
|
|
24
|
+
Classifier: Topic :: Internet
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
|
|
27
|
+
[](https://travis-ci.org/ProjectBabbler/ebird-api)
|
|
28
|
+
[](https://badge.fury.io/py/ebird-api)
|
|
29
|
+
[](https://img.shields.io/pypi/pyversions/ebird-api)
|
|
30
|
+
|
|
31
|
+
# eBird API
|
|
32
|
+
|
|
33
|
+
eBird API provides a set of wrapper functions for accessing the end-points
|
|
34
|
+
in the eBird API 2.0.
|
|
35
|
+
|
|
36
|
+
## Install
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
pip install ebird-api
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Usage
|
|
43
|
+
|
|
44
|
+
Each of the functions map to a specific end-point in the API - with one or
|
|
45
|
+
two exceptions where API calls are essentially identical. The functions can
|
|
46
|
+
be grouped into five activities: fetching observations, getting information
|
|
47
|
+
on hotspots, getting information on regions, getting lists of species and
|
|
48
|
+
getting statistics.
|
|
49
|
+
|
|
50
|
+
All functions support arguments (with sensible defaults) for all the query
|
|
51
|
+
parameters supported by the eBird API. Check the docstring for each function
|
|
52
|
+
for more details. There you will also find a link to the documentation for
|
|
53
|
+
each end-point.
|
|
54
|
+
|
|
55
|
+
To use the API you will need to register for an API key. All you need to do is
|
|
56
|
+
fill out this [form](https://ebird.org/api/keygen) and the API key is generated
|
|
57
|
+
automatically.
|
|
58
|
+
|
|
59
|
+
NOTE: Use the API with some restraint. Data costs money so don't go downloading
|
|
60
|
+
all the checklists for the world or other excessive behaviour or your account will
|
|
61
|
+
get banned. If you have a project in mind get in touch with eBird and tell them
|
|
62
|
+
what you want to do - they will be interested to hear it.
|
|
63
|
+
|
|
64
|
+
### Observations
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from ebird.api import get_observations
|
|
68
|
+
|
|
69
|
+
# Get observations from Woodman Pond, Madison county, New York for the past week.
|
|
70
|
+
records = get_observations(api_key, 'L227544', back=7)
|
|
71
|
+
|
|
72
|
+
# Get observations from Madison county, New York
|
|
73
|
+
records = get_observations(api_key, 'US-NY-053')
|
|
74
|
+
|
|
75
|
+
# Get observations from New York
|
|
76
|
+
records = get_observations(api_key, 'US-NY')
|
|
77
|
+
|
|
78
|
+
# Get observations from the USA - don't overdo the data downloads
|
|
79
|
+
records = get_observations(api_key, 'US')
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
Any where you pass in single location or region you can also pass in a
|
|
83
|
+
list or a comma-separated string. You can specify up to 10 locations or
|
|
84
|
+
regions:
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
from ebird.api import get_observations
|
|
88
|
+
|
|
89
|
+
# Get the observations for the most visited locations in Madison county, New York:
|
|
90
|
+
# Woodman Pond, Ditch Bank Rd., Cornell Biological Field Station and
|
|
91
|
+
# Anne V Pickard Memorial Wildlife Overlook.
|
|
92
|
+
locations = ['L227544', 'L273783', 'L677871', 'L2313391']
|
|
93
|
+
get_observations(api_key, locations, provisional=True, detail='full')
|
|
94
|
+
|
|
95
|
+
# Get the observations for Suffolk, Nassau and Queens counties in New York state.
|
|
96
|
+
counties = 'US-NY-103,US-NY-059,US-NY-81'
|
|
97
|
+
records = get_observations(api_key, locations, hotspot=False, category='species')
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
The functions that return observations, checklists or taxonomy support allow
|
|
101
|
+
the common name for species to be returned in different languages:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from ebird.api import get_observations
|
|
105
|
+
|
|
106
|
+
records = get_observations(api_key, 'CA-QC', locale='fr')
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
In addition to getting all the observations for a given location or in
|
|
110
|
+
an area you can also get the latest observation of each species in a
|
|
111
|
+
geographical area - useful for finding the nearest place to see a given
|
|
112
|
+
species:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from ebird.api import get_nearby_observations
|
|
116
|
+
|
|
117
|
+
# Get the most recent sightings of all species seen in the last week within
|
|
118
|
+
# 10km of Point Reyes National Seashore.
|
|
119
|
+
records = get_nearby_observations(api_key, 38.05, -122.94, dist=10, back=7)
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
The calls to get_observations() and get_nearby_observation() return all the
|
|
123
|
+
available records. You can limit the set of records returned to only include
|
|
124
|
+
notable ones (locally or nationally rare species) or limit the records to
|
|
125
|
+
a small number of species:
|
|
126
|
+
|
|
127
|
+
```python
|
|
128
|
+
from ebird.api import get_notable_observations, get_nearby_notable, \
|
|
129
|
+
get_species_observations, get_nearby_species
|
|
130
|
+
|
|
131
|
+
# Get the interesting birds seen in New York state.
|
|
132
|
+
records = get_notable_observations(api_key, 'US-NY')
|
|
133
|
+
|
|
134
|
+
# Get the observations of Horned Lark (Eremophila alpestris) in New York state.
|
|
135
|
+
records = get_species_observations(api_key, 'horlar', 'US-NY')
|
|
136
|
+
|
|
137
|
+
# Get the interesting birds within 50kn of Point Reyes
|
|
138
|
+
records = get_nearby_notable(api_key, 38.05, -122.94, dist=50)
|
|
139
|
+
|
|
140
|
+
# Find out if Barn Swallows have been seen in the area in the past 10 days
|
|
141
|
+
records = get_nearby_species(api_key, 'barswa', 38.05, -122.94, back=10)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
For the more travel-minded you can also find out where is th e nearest place
|
|
145
|
+
to see a given species:
|
|
146
|
+
|
|
147
|
+
```python
|
|
148
|
+
from ebird.api import get_nearest_species
|
|
149
|
+
|
|
150
|
+
# Where is the closest place to Cornell Lab of Ornithology to see
|
|
151
|
+
# Tennessee Warbler.
|
|
152
|
+
locations = get_nearest_species('tenwar', 42.48, -76.45)
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Depending on what time of year you try this, you might have a long way to go.
|
|
156
|
+
|
|
157
|
+
### Checklists
|
|
158
|
+
|
|
159
|
+
There are two functions for finding out what has been seen at a given location.
|
|
160
|
+
First you can get the list of checklists for a given country, region or location
|
|
161
|
+
using get_visits(). Each result returned has the unique identifier for the
|
|
162
|
+
checklist. You can then call get_checklist() to get the list of observations.
|
|
163
|
+
|
|
164
|
+
```python
|
|
165
|
+
from ebird.api import get_visits, get_checklist
|
|
166
|
+
|
|
167
|
+
# Get visits made recently to locations in New York state:
|
|
168
|
+
records = get_visits(api_key, 'US-NY')
|
|
169
|
+
|
|
170
|
+
# Get visits made recently to locations in New York state on Jan 1st 2010
|
|
171
|
+
records = get_visits(api_key, 'US-NY', '2010-01-01')
|
|
172
|
+
|
|
173
|
+
# Get the details of a checklist
|
|
174
|
+
checklist = get_checklist(api_key, 'S22536787')
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
### Hotspots
|
|
178
|
+
|
|
179
|
+
There are two functions for discovering hotspots. get_hotspots() list all
|
|
180
|
+
the locations in a given area. You can find all the hotspots visited recently
|
|
181
|
+
by given a value for the back argument. get_nearby_hotspots() is used to find
|
|
182
|
+
hotspots within a given radius. get_hotspot() can be used to get information
|
|
183
|
+
on the location of a given hotspot.
|
|
184
|
+
|
|
185
|
+
```python
|
|
186
|
+
from ebird.api import get_hotspots, get_nearby_hotspots, get_hotspot
|
|
187
|
+
|
|
188
|
+
# List all the hotspots in New York state.
|
|
189
|
+
hotspots = get_hotspots(api_key, 'US-NY')
|
|
190
|
+
|
|
191
|
+
# List all the hotspots in New York state visited in the past week.
|
|
192
|
+
recent = get_hotspots(api_key, 'US-NY', back=7)
|
|
193
|
+
|
|
194
|
+
# List all the hotspots in New York state visited in the past week.
|
|
195
|
+
recent = get_hotspots(api_key, 'US-NY', back=7)
|
|
196
|
+
|
|
197
|
+
# List all the hotspots in within 50kn of Point Reyes
|
|
198
|
+
nearby = get_nearby_hotspots(api_key, 38.05, -122.94, dist=50)
|
|
199
|
+
|
|
200
|
+
# Get the details of Anne V Pickard Memorial Wildlife Overlook in New York state.
|
|
201
|
+
details = get_hotspot(api_key, 'L2313391')
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Regions
|
|
205
|
+
|
|
206
|
+
eBird divides the world into countries, subnational1 regions (states) or
|
|
207
|
+
subnational2 regions (counties). You can use get_regions() to get the
|
|
208
|
+
list of sub-regions for a given region. For the approximate area covered
|
|
209
|
+
by a region use get_region().
|
|
210
|
+
|
|
211
|
+
```python
|
|
212
|
+
from ebird.api import get_regions, get_adjacent_regions, get_region
|
|
213
|
+
|
|
214
|
+
# Get the list of countries in the world.
|
|
215
|
+
countries = get_regions(api_key, 'country', 'world')
|
|
216
|
+
|
|
217
|
+
# Get the list of states in the US.
|
|
218
|
+
states = get_regions(api_key, 'subnational1', 'US')
|
|
219
|
+
|
|
220
|
+
# Get the list of counties in New York state.
|
|
221
|
+
counties = get_regions(api_key, 'subnational2', 'US-NY')
|
|
222
|
+
|
|
223
|
+
# Get the list of states which border New York state.
|
|
224
|
+
nearby = get_adjacent_regions(api_key, 'US-NY')
|
|
225
|
+
|
|
226
|
+
# Get the approximate area covered by New York state.
|
|
227
|
+
bounds = get_region(api_key, 'US-NY')
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
### Taxonomy
|
|
231
|
+
|
|
232
|
+
You can get details of all the species, subspecies, forms
|
|
233
|
+
etc. in the taxonomy used by eBird. It's the easiest way
|
|
234
|
+
of getting the codes for each species or subspecies,
|
|
235
|
+
e.g. horlar (Horned Lark), cangoo (Canada Goose), etc.,
|
|
236
|
+
that are used in the other API calls.1
|
|
237
|
+
|
|
238
|
+
```python
|
|
239
|
+
from ebird.api import get_taxonomy, get_taxonomy_forms, get_taxonomy_versions
|
|
240
|
+
|
|
241
|
+
# Get all the species in the eBird taxonomy.
|
|
242
|
+
taxonomy = get_taxonomy(api_key)
|
|
243
|
+
|
|
244
|
+
# Get all the species in the eBird taxonomy with common names in Spanish
|
|
245
|
+
names = get_taxonomy(api_key, locale='es')
|
|
246
|
+
|
|
247
|
+
# Get all the taxonomy for Horned Lark
|
|
248
|
+
species = get_taxonomy(api_key, species='horlar')
|
|
249
|
+
|
|
250
|
+
# Get the codes for all the subspecies and froms recognised for Barn Swallow.
|
|
251
|
+
forms = get_taxonomy_forms(api_key, 'barswa')
|
|
252
|
+
|
|
253
|
+
# Get information on all the taxonomy revisions, i.e. versions.
|
|
254
|
+
# Usually only the latest is important.
|
|
255
|
+
versions = get_taxonomy_versions(api_key)
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### Statistics
|
|
259
|
+
|
|
260
|
+
You can also get some statistics from the eBird data. The most interesting
|
|
261
|
+
is probably get_top_100() which return the list of observers who have seen
|
|
262
|
+
the most species or submitted the largest number of checklists. The list is
|
|
263
|
+
just for a specific day so it is really only useful for "Big Days" when
|
|
264
|
+
lots of people are out trying to get the greatest number of species.
|
|
265
|
+
|
|
266
|
+
```python
|
|
267
|
+
from datetime import date
|
|
268
|
+
from ebird.api import get_top_100, get_totals
|
|
269
|
+
|
|
270
|
+
# Get the winner of the Global Big Day in New York, on 5th May 2018
|
|
271
|
+
winners = get_top_100(api_key, 'US-NY', '2018-05-05')
|
|
272
|
+
|
|
273
|
+
# Get the number of contributors, checklist submitted and species seen today
|
|
274
|
+
totals = get_totals(api_key, 'US-NY', date.today())
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Client
|
|
278
|
+
|
|
279
|
+
There is a simple Client class which wraps the various functions from the API.
|
|
280
|
+
You can set the API key and locale when creating a Client instance so you don't
|
|
281
|
+
have to keep passing them as arguments.
|
|
282
|
+
|
|
283
|
+
```python
|
|
284
|
+
from ebird.api import Client
|
|
285
|
+
|
|
286
|
+
api_key = 'abc123'
|
|
287
|
+
locale = 'es'
|
|
288
|
+
|
|
289
|
+
client = Client(api_key, locale)
|
|
290
|
+
|
|
291
|
+
client.get_observations('MX-OAX')
|
|
292
|
+
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
The client supports all the API functions.
|
|
296
|
+
|
|
297
|
+
## Formats
|
|
298
|
+
|
|
299
|
+
Most of the eBird API calls return JSON. Some of the calls such as getting
|
|
300
|
+
the hotspots for a region or getting the taxonomy also support CSV. Since
|
|
301
|
+
converting JSON to CSV is simple this library is opinionated in that it
|
|
302
|
+
only returns JSON.
|
|
303
|
+
|
|
304
|
+
## Compatibility
|
|
305
|
+
|
|
306
|
+
ebird-api works with Python 3.5+.
|
|
307
|
+
|
|
308
|
+
## Links
|
|
309
|
+
|
|
310
|
+
Documentation for the eBird API: https://documenter.getpostman.com/view/664302/S1ENwy59?version=latest#intro
|
|
311
|
+
though it could do with a little love and attention.
|
|
312
|
+
|
|
313
|
+
Available translations for species names: http://help.ebird.org/customer/portal/articles/1596582
|
|
314
|
+
|
|
315
|
+
Information on the taxonomy used by eBird: http://help.ebird.org/customer/portal/articles/1006825-the-ebird-taxonomy
|
|
316
|
+
|
|
317
|
+
## License
|
|
318
|
+
|
|
319
|
+
eBird API is available under the terms of the [MIT](https://opensource.org/licenses/MIT) licence.
|
|
320
|
+
|
|
321
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
ebird/api/__init__.py,sha256=F1a37QvMy17duL-pXa3CWD0ikK4X5CGG8VqHIkyP3pM,905
|
|
2
|
+
ebird/api/checklists.py,sha256=Ksk0mSfUTpwXVXGE_HwmnIVItpxU_27L7Vh0uNgcrgg,3270
|
|
3
|
+
ebird/api/client.py,sha256=vQnQaQG3BdpMS4mdl2t1ldC-j11c0RtRsxuv2abfZJ8,12019
|
|
4
|
+
ebird/api/constants.py,sha256=KgXaTWXH_u1KQisdCz9-ztbivYxBgwv5ChYQ3zgUZRo,2516
|
|
5
|
+
ebird/api/hotspots.py,sha256=9mGq19cqBZ3DkbdRi21oi-HLTin5O9k4bb9u82xvLEo,4503
|
|
6
|
+
ebird/api/observations.py,sha256=F93saViXP1WD5XToXICvObqHREB3eY6c1uBIdshuv_s,24130
|
|
7
|
+
ebird/api/regions.py,sha256=CJEnAAyD862LOPcoWHrwfRJWUSpgK6k0pcMwn1dRh7o,3460
|
|
8
|
+
ebird/api/statistics.py,sha256=ACFOINSkS1FZeMdjTeNzkTlYtun75A74XZ1QC67UXiA,2550
|
|
9
|
+
ebird/api/taxonomy.py,sha256=aM3bbrKuj0JrjvOmSrs2R7Cq3bHrhv1wOPVJqI5hpaE,5505
|
|
10
|
+
ebird/api/utils.py,sha256=LTeJZJE-z4L3Ahz5KIwRKdsI-eGs5AMvX4j9Ml6X7EA,4277
|
|
11
|
+
ebird/api/validation.py,sha256=OEBqNzU-tDo7_r8T6MwW2TnnDF88FlMSg37W2GG8W5c,9096
|
|
12
|
+
ebird_api-3.0.6.dist-info/LICENSE.txt,sha256=uo6fUmANlZysvF9UcI7nE9NbuqCZbfo8L3bJpFG3XTI,1081
|
|
13
|
+
ebird_api-3.0.6.dist-info/METADATA,sha256=-LwGzOh9CyOGf3VMD8Y78lCjXfb8pozSVIC1Dg081U4,11227
|
|
14
|
+
ebird_api-3.0.6.dist-info/WHEEL,sha256=h_aVn5OB2IERUjMbi2pucmR_zzWJtk303YXvhh60NJ8,110
|
|
15
|
+
ebird_api-3.0.6.dist-info/top_level.txt,sha256=lBp3I23K75tsPJn7Jdz7d4Tk7JeRhbVkcuGthNk7LaM,6
|
|
16
|
+
ebird_api-3.0.6.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ebird
|