ebird-api-requests 4.0.0__tar.gz
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_requests-4.0.0/LICENSE.txt +21 -0
- ebird_api_requests-4.0.0/PKG-INFO +389 -0
- ebird_api_requests-4.0.0/README.md +359 -0
- ebird_api_requests-4.0.0/pyproject.toml +126 -0
- ebird_api_requests-4.0.0/setup.cfg +4 -0
- ebird_api_requests-4.0.0/setup.py +3 -0
- ebird_api_requests-4.0.0/src/ebird/api/requests/__init__.py +39 -0
- ebird_api_requests-4.0.0/src/ebird/api/requests/checklists.py +101 -0
- ebird_api_requests-4.0.0/src/ebird/api/requests/client.py +410 -0
- ebird_api_requests-4.0.0/src/ebird/api/requests/constants.py +108 -0
- ebird_api_requests-4.0.0/src/ebird/api/requests/hotspots.py +239 -0
- ebird_api_requests-4.0.0/src/ebird/api/requests/observations.py +707 -0
- ebird_api_requests-4.0.0/src/ebird/api/requests/regions.py +110 -0
- ebird_api_requests-4.0.0/src/ebird/api/requests/species.py +37 -0
- ebird_api_requests-4.0.0/src/ebird/api/requests/statistics.py +90 -0
- ebird_api_requests-4.0.0/src/ebird/api/requests/taxonomy.py +213 -0
- ebird_api_requests-4.0.0/src/ebird/api/requests/utils.py +164 -0
- ebird_api_requests-4.0.0/src/ebird/api/requests/validation.py +348 -0
- ebird_api_requests-4.0.0/src/ebird_api_requests.egg-info/PKG-INFO +389 -0
- ebird_api_requests-4.0.0/src/ebird_api_requests.egg-info/SOURCES.txt +20 -0
- ebird_api_requests-4.0.0/src/ebird_api_requests.egg-info/dependency_links.txt +1 -0
- ebird_api_requests-4.0.0/src/ebird_api_requests.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019-2024 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,389 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ebird-api-requests
|
|
3
|
+
Version: 4.0.0
|
|
4
|
+
Summary: A python library for accessing the eBird API, version 2.0
|
|
5
|
+
Author-email: Stuart MacKay <smackay@flagstonesoftware.com>
|
|
6
|
+
License: MIT License
|
|
7
|
+
Project-URL: Repository, https://github.com/StuartMacKay/ebird-api-requests.git
|
|
8
|
+
Project-URL: Issues, https://github.com/StuartMacKay/ebird-api-requests/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/StuartMacKay/ebird-api-requests/blob/master/CHANGELOG.md
|
|
10
|
+
Keywords: eBird,API,client
|
|
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.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
23
|
+
Classifier: Natural Language :: English
|
|
24
|
+
Classifier: Topic :: Utilities
|
|
25
|
+
Classifier: Topic :: Internet
|
|
26
|
+
Requires-Python: >=3.10
|
|
27
|
+
Description-Content-Type: text/markdown
|
|
28
|
+
License-File: LICENSE.txt
|
|
29
|
+
Dynamic: license-file
|
|
30
|
+
|
|
31
|
+
[](https://badge.fury.io/py/ebird-api)
|
|
32
|
+
[](https://img.shields.io/pypi/pyversions/ebird-api)
|
|
33
|
+
|
|
34
|
+
# eBird API
|
|
35
|
+
|
|
36
|
+
eBird API Requests provides a set of wrapper functions for accessing the
|
|
37
|
+
end-points in the eBird API 2.0.
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
```sh
|
|
42
|
+
pip install ebird-api
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Usage
|
|
46
|
+
|
|
47
|
+
Each of the functions map to a specific end-point in the API - with one or
|
|
48
|
+
two exceptions where API calls are essentially identical. The functions can
|
|
49
|
+
be grouped into five activities: fetching observations, getting information
|
|
50
|
+
on hotspots, getting information on regions, getting lists of species and
|
|
51
|
+
getting statistics.
|
|
52
|
+
|
|
53
|
+
All functions support arguments (with sensible defaults) for all the query
|
|
54
|
+
parameters supported by the eBird API. Check the docstring for each function
|
|
55
|
+
for more details. There you will also find a link to the documentation for
|
|
56
|
+
each end-point.
|
|
57
|
+
|
|
58
|
+
To use the API you will need to register for an API key. All you need to do is
|
|
59
|
+
fill out this [form](https://ebird.org/api/keygen) and the API key is generated
|
|
60
|
+
automatically.
|
|
61
|
+
|
|
62
|
+
NOTE: Use the API with some restraint. Data costs money so don't go downloading
|
|
63
|
+
all the checklists for the world or other excessive behaviour or your account will
|
|
64
|
+
get banned. If you have a project in mind get in touch with eBird and tell them
|
|
65
|
+
what you want to do - they will be interested to hear it.
|
|
66
|
+
|
|
67
|
+
### Observations
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
import os
|
|
71
|
+
|
|
72
|
+
from ebird.api.requests import get_observations
|
|
73
|
+
|
|
74
|
+
# Always store secrets outside the code, so you don't accidentally
|
|
75
|
+
# commit them. Environment variables are ideal for this.
|
|
76
|
+
api_key = os.environ["EBIRD_API_KEY"]
|
|
77
|
+
|
|
78
|
+
# Get observations from Woodman Pond, Madison county, New York for the past week.
|
|
79
|
+
this_week = get_observations(api_key, 'L227544', back=7)
|
|
80
|
+
|
|
81
|
+
# Get observations from Madison county, New York
|
|
82
|
+
country_records = get_observations(api_key, 'US-NY-053')
|
|
83
|
+
|
|
84
|
+
# Get observations from New York
|
|
85
|
+
state_records = get_observations(api_key, 'US-NY')
|
|
86
|
+
|
|
87
|
+
# Get observations from the USA - don't overdo the data downloads
|
|
88
|
+
national_records = get_observations(api_key, 'US')
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
Any where you pass in single location or region you can also pass in a
|
|
92
|
+
list or a comma-separated string. You can specify up to 10 locations or
|
|
93
|
+
regions:
|
|
94
|
+
|
|
95
|
+
```python
|
|
96
|
+
import os
|
|
97
|
+
|
|
98
|
+
from ebird.api.requests import get_observations
|
|
99
|
+
|
|
100
|
+
api_key = os.environ["EBIRD_API_KEY"]
|
|
101
|
+
|
|
102
|
+
# Get the observations for the most visited locations in Madison county, New York:
|
|
103
|
+
# Woodman Pond, Ditch Bank Rd., Cornell Biological Field Station and
|
|
104
|
+
# Anne V Pickard Memorial Wildlife Overlook.
|
|
105
|
+
locations = ['L227544', 'L273783', 'L677871', 'L2313391']
|
|
106
|
+
get_observations(api_key, locations, provisional=True, detail='full')
|
|
107
|
+
|
|
108
|
+
# Get the observations for Suffolk, Nassau and Queens counties in New York state.
|
|
109
|
+
counties = 'US-NY-103,US-NY-059,US-NY-81'
|
|
110
|
+
records = get_observations(api_key, locations, hotspot=False, category='species')
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
The common name for species can be returned in different languages by
|
|
114
|
+
specifying locale in the functions that return observations, checklists
|
|
115
|
+
or taxonomy:
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
import os
|
|
119
|
+
|
|
120
|
+
from ebird.api.requests import get_observations
|
|
121
|
+
|
|
122
|
+
api_key = os.environ["EBIRD_API_KEY"]
|
|
123
|
+
|
|
124
|
+
records = get_observations(api_key, 'CA-QC', locale='fr')
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
In addition to getting all the observations for a given location or in
|
|
128
|
+
an area you can also get the latest observation of each species in a
|
|
129
|
+
geographical area - useful for finding the nearest place to see a given
|
|
130
|
+
species:
|
|
131
|
+
|
|
132
|
+
```python
|
|
133
|
+
import os
|
|
134
|
+
|
|
135
|
+
from ebird.api.requests import get_nearby_observations
|
|
136
|
+
|
|
137
|
+
api_key = os.environ["EBIRD_API_KEY"]
|
|
138
|
+
|
|
139
|
+
# Get the most recent sightings of all species seen in the last week within
|
|
140
|
+
# 10km of Point Reyes National Seashore.
|
|
141
|
+
records = get_nearby_observations(api_key, 38.05, -122.94, dist=10, back=7)
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
The calls to get_observations() and get_nearby_observation() return all the
|
|
145
|
+
available records. You can limit the set of records returned to only include
|
|
146
|
+
notable ones (locally or nationally rare species) or limit the records to
|
|
147
|
+
a small number of species:
|
|
148
|
+
|
|
149
|
+
```python
|
|
150
|
+
import os
|
|
151
|
+
|
|
152
|
+
from ebird.api.requests import (
|
|
153
|
+
get_notable_observations,
|
|
154
|
+
get_nearby_notable,
|
|
155
|
+
get_species_observations,
|
|
156
|
+
get_nearby_species,
|
|
157
|
+
)
|
|
158
|
+
|
|
159
|
+
api_key = os.environ["EBIRD_API_KEY"]
|
|
160
|
+
|
|
161
|
+
# Get the interesting birds seen in New York state.
|
|
162
|
+
notables = get_notable_observations(api_key, 'US-NY')
|
|
163
|
+
|
|
164
|
+
# Get the observations of Horned Lark (Eremophila alpestris) in New York state.
|
|
165
|
+
records = get_species_observations(api_key, 'horlar', 'US-NY')
|
|
166
|
+
|
|
167
|
+
# Get the interesting birds within 50kn of Point Reyes
|
|
168
|
+
nearby_notables = get_nearby_notable(api_key, 38.05, -122.94, dist=50)
|
|
169
|
+
|
|
170
|
+
# Find out if Barn Swallows have been seen in the area in the past 10 days
|
|
171
|
+
nearby_species = get_nearby_species(api_key, 'barswa', 38.05, -122.94, back=10)
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
For the more travel-minded you can also find out the nearest place to see a given species:
|
|
175
|
+
|
|
176
|
+
```python
|
|
177
|
+
import os
|
|
178
|
+
|
|
179
|
+
from ebird.api.requests import get_nearest_species
|
|
180
|
+
|
|
181
|
+
api_key = os.environ["EBIRD_API_KEY"]
|
|
182
|
+
|
|
183
|
+
# Where is the closest place to Cornell Lab of Ornithology to see
|
|
184
|
+
# Tennessee Warbler.
|
|
185
|
+
locations = get_nearest_species(api_key, 'tenwar', 42.48, -76.45)
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Depending on what time of year you try this, you might have a long way to go.
|
|
189
|
+
|
|
190
|
+
### Checklists
|
|
191
|
+
|
|
192
|
+
There are two functions for finding out what has been seen at a given location.
|
|
193
|
+
First you can get the list of checklists for a given country, region or location
|
|
194
|
+
using get_visits(). Each result returned has the unique identifier for the
|
|
195
|
+
checklist. You can then call get_checklist() to get the list of observations.
|
|
196
|
+
|
|
197
|
+
```python
|
|
198
|
+
import os
|
|
199
|
+
|
|
200
|
+
from ebird.api.requests import get_visits, get_checklist
|
|
201
|
+
|
|
202
|
+
api_key = os.environ["EBIRD_API_KEY"]
|
|
203
|
+
|
|
204
|
+
# Get visits made recently to locations in New York state:
|
|
205
|
+
visits = get_visits(api_key, 'US-NY')
|
|
206
|
+
|
|
207
|
+
# Get visits made recently to locations in New York state on Jan 1st 2010
|
|
208
|
+
recent_visits = get_visits(api_key, 'US-NY', '2010-01-01')
|
|
209
|
+
|
|
210
|
+
# Get the details of a checklist
|
|
211
|
+
checklist = get_checklist(api_key, 'S22536787')
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Hotspots
|
|
215
|
+
|
|
216
|
+
There are two functions for discovering hotspots. get_hotspots() list all
|
|
217
|
+
the locations in a given area. You can find all the hotspots visited recently
|
|
218
|
+
by given a value for the back argument. get_nearby_hotspots() is used to find
|
|
219
|
+
hotspots within a given radius. get_hotspot() can be used to get information
|
|
220
|
+
on the location of a given hotspot.
|
|
221
|
+
|
|
222
|
+
```python
|
|
223
|
+
import os
|
|
224
|
+
|
|
225
|
+
from ebird.api.requests import get_hotspots, get_nearby_hotspots, get_hotspot
|
|
226
|
+
|
|
227
|
+
api_key = os.environ["EBIRD_API_KEY"]
|
|
228
|
+
|
|
229
|
+
# List all the hotspots in New York state.
|
|
230
|
+
hotspots = get_hotspots(api_key, 'US-NY')
|
|
231
|
+
|
|
232
|
+
# List all the hotspots in New York state visited in the past week.
|
|
233
|
+
recent = get_hotspots(api_key, 'US-NY', back=7)
|
|
234
|
+
|
|
235
|
+
# List all the hotspots in within 50kn of Point Reyes
|
|
236
|
+
nearby = get_nearby_hotspots(api_key, 38.05, -122.94, dist=50)
|
|
237
|
+
|
|
238
|
+
# Get the details of Anne V Pickard Memorial Wildlife Overlook in New York state.
|
|
239
|
+
details = get_hotspot(api_key, 'L2313391')
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### Regions
|
|
243
|
+
|
|
244
|
+
eBird divides the world into countries, subnational1 regions (states) or
|
|
245
|
+
subnational2 regions (counties). You can use get_regions() to get the
|
|
246
|
+
list of sub-regions for a given region. For the approximate area covered
|
|
247
|
+
by a region use get_region().
|
|
248
|
+
|
|
249
|
+
```python
|
|
250
|
+
import os
|
|
251
|
+
|
|
252
|
+
from ebird.api.requests import get_regions, get_adjacent_regions, get_region
|
|
253
|
+
|
|
254
|
+
api_key = os.environ["EBIRD_API_KEY"]
|
|
255
|
+
|
|
256
|
+
# Get the list of countries in the world.
|
|
257
|
+
countries = get_regions(api_key, 'country', 'world')
|
|
258
|
+
|
|
259
|
+
# Get the list of states in the US.
|
|
260
|
+
states = get_regions(api_key, 'subnational1', 'US')
|
|
261
|
+
|
|
262
|
+
# Get the list of counties in New York state.
|
|
263
|
+
counties = get_regions(api_key, 'subnational2', 'US-NY')
|
|
264
|
+
|
|
265
|
+
# Get the list of states which border New York state.
|
|
266
|
+
nearby = get_adjacent_regions(api_key, 'US-NY')
|
|
267
|
+
|
|
268
|
+
# Get the approximate area covered by New York state.
|
|
269
|
+
bounds = get_region(api_key, 'US-NY')
|
|
270
|
+
```
|
|
271
|
+
|
|
272
|
+
### Taxonomy
|
|
273
|
+
|
|
274
|
+
You can get details of all the species, subspecies, forms
|
|
275
|
+
etc. in the taxonomy used by eBird. It's the easiest way
|
|
276
|
+
of getting the codes for each species or subspecies,
|
|
277
|
+
e.g. horlar (Horned Lark), cangoo (Canada Goose), etc.,
|
|
278
|
+
that are used in the other API calls.
|
|
279
|
+
|
|
280
|
+
```python
|
|
281
|
+
import os
|
|
282
|
+
|
|
283
|
+
from ebird.api.requests import get_taxonomy, get_taxonomy_forms, get_taxonomy_versions
|
|
284
|
+
|
|
285
|
+
api_key = os.environ["EBIRD_API_KEY"]
|
|
286
|
+
|
|
287
|
+
# Get all the species in the eBird taxonomy.
|
|
288
|
+
taxonomy = get_taxonomy(api_key)
|
|
289
|
+
|
|
290
|
+
# Get all the species in the eBird taxonomy with common names in Spanish
|
|
291
|
+
names = get_taxonomy(api_key, locale='es')
|
|
292
|
+
|
|
293
|
+
# Get all the taxonomy for Horned Lark
|
|
294
|
+
species = get_taxonomy(api_key, species='horlar')
|
|
295
|
+
|
|
296
|
+
# Get the codes for all the subspecies and froms recognised for Barn Swallow.
|
|
297
|
+
forms = get_taxonomy_forms(api_key, 'barswa')
|
|
298
|
+
|
|
299
|
+
# Get information on all the taxonomy revisions, i.e. versions.
|
|
300
|
+
# Usually only the latest is important.
|
|
301
|
+
versions = get_taxonomy_versions(api_key)
|
|
302
|
+
```
|
|
303
|
+
|
|
304
|
+
### Statistics
|
|
305
|
+
|
|
306
|
+
You can also get some statistics from the eBird data. The most interesting
|
|
307
|
+
is probably get_top_100() which returns the list of observers who have seen
|
|
308
|
+
the most species or submitted the largest number of checklists. The list is
|
|
309
|
+
just for a specific day so it is really only useful for "Big Days" when
|
|
310
|
+
lots of people are out trying to get the greatest number of species.
|
|
311
|
+
|
|
312
|
+
```python
|
|
313
|
+
import os
|
|
314
|
+
|
|
315
|
+
from datetime import date
|
|
316
|
+
from ebird.api.requests import get_top_100, get_totals
|
|
317
|
+
|
|
318
|
+
api_key = os.environ["EBIRD_API_KEY"]
|
|
319
|
+
|
|
320
|
+
# Get the winner of the Global Big Day in New York, on 5th May 2018
|
|
321
|
+
winners = get_top_100(api_key, 'US-NY', '2018-05-05')
|
|
322
|
+
|
|
323
|
+
# Get the number of contributors, checklist submitted and species seen today
|
|
324
|
+
totals = get_totals(api_key, 'US-NY', date.today())
|
|
325
|
+
```
|
|
326
|
+
|
|
327
|
+
### Client
|
|
328
|
+
|
|
329
|
+
There is a simple Client class which wraps the various functions from the API.
|
|
330
|
+
You can set the API key and locale when creating a Client instance so you don't
|
|
331
|
+
have to keep passing them as arguments.
|
|
332
|
+
|
|
333
|
+
```python
|
|
334
|
+
import os
|
|
335
|
+
|
|
336
|
+
from ebird.api.requests import Client
|
|
337
|
+
|
|
338
|
+
api_key = os.environ["EBIRD_API_KEY"]
|
|
339
|
+
locale = 'es'
|
|
340
|
+
|
|
341
|
+
client = Client(api_key, locale)
|
|
342
|
+
|
|
343
|
+
client.get_observations('MX-OAX')
|
|
344
|
+
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
The client supports all the API functions.
|
|
348
|
+
|
|
349
|
+
## Formats
|
|
350
|
+
|
|
351
|
+
Most of the eBird API calls return JSON. Some of the calls such as getting
|
|
352
|
+
the hotspots for a region or getting the taxonomy also support CSV. Since
|
|
353
|
+
converting JSON to CSV is simple this library is opinionated in that it
|
|
354
|
+
only returns JSON.
|
|
355
|
+
|
|
356
|
+
## Compatibility
|
|
357
|
+
|
|
358
|
+
ebird-api works with currently supported versions of Python, 3.10+. However,
|
|
359
|
+
it is known to work with earlier versions, at least 3.5 - 3.8, without any
|
|
360
|
+
problems.
|
|
361
|
+
|
|
362
|
+
## Troubleshooting
|
|
363
|
+
|
|
364
|
+
Just occasionally (rarely in fact), the connection to eBird will freeze. The
|
|
365
|
+
client will raise an error but if you use the API functions directly then your
|
|
366
|
+
program will sit there forever. To fix this set a default timeout all connections
|
|
367
|
+
using:
|
|
368
|
+
|
|
369
|
+
```python
|
|
370
|
+
import socket
|
|
371
|
+
|
|
372
|
+
socket.setdefaulttimeout(30)
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
Thirty seconds is a reasonable figure, however you might change it if your
|
|
376
|
+
internet connection is slow or the eBird servers are busy.
|
|
377
|
+
|
|
378
|
+
## Links
|
|
379
|
+
|
|
380
|
+
Documentation for the eBird API: https://documenter.getpostman.com/view/664302/S1ENwy59?version=latest#intro
|
|
381
|
+
though it could do with a little love and attention.
|
|
382
|
+
|
|
383
|
+
Available translations for species names: http://help.ebird.org/customer/portal/articles/1596582
|
|
384
|
+
|
|
385
|
+
Information on the taxonomy used by eBird: http://help.ebird.org/customer/portal/articles/1006825-the-ebird-taxonomy
|
|
386
|
+
|
|
387
|
+
## License
|
|
388
|
+
|
|
389
|
+
eBird API is available under the terms of the [MIT](https://opensource.org/licenses/MIT) licence.
|