Wrapper for the Petfinder API
Project description
Petpy - Python Wrapper for the Petfinder API
:cat2: :dog2: :rooster: :rabbit2: :racehorse:
Installation
petpy
is easily installed through pip
.
pip install petpy
The library can also be cloned or downloaded into a location of your choosing and then installed using the setup.py
file per the following:
git clone git@github.com:aschleg/petpy.git
cd petpy
python setup.py install
Examples and usage
An account must first be created with Petfinder to receive an API and secret
key. The API and secret key will be used to grant access to the Petfinder API, which lasts for 3600 seconds, or one
hour. After the authentication period ends, you must re-authenticate with the Petfinder API. The following are some
quick examples for using petpy
to get started. More in-depth tutorials for petpy
and some examples of what
can be done with the library, please see the More Examples and Tutorials section below.
Authenticating with the Petfinder API
Authenticating the connection with the Petfinder API is done at the same time the Petfinder
class is initialized.
pf = Petfinder(key=key, secret=secret)
The following are some quick examples for getting started with petpy
and the Petfinder API.
Finding animal types
# All animal types and their relevant data.
all_types = pf.animal_types()
# Returning data for a single animal type
dogs = pf.animal_types('dog')
# Getting multiple animal types at once
cat_dog_rabbit_types = pf.animal_types(['cat', 'dog', 'rabbit'])
Getting animal breeds for available animal types
cat_breeds = pf.breeds('cat')
dog_breeds = pf.breeds('dog')
# All available breeds or multiple breeds can also be returned.
all_breeds = pf.breeds()
cat_dog_rabbit = pf.breeds(types=['cat', 'dog', 'rabbit'])
The breeds
method can also be set to coerce the returned JSON results into a pandas DataFrame by setting
the parameter return_df = True
.
cat_breeds_df = pf.breeds('cat', return_df = True)
all_breeds_df = pf.breeds(return_df = True)
Finding available animals on Petfinder
The animals()
method returns animals based on specified criteria that are listed in the Petfinder database. Specific
animals can be searched using the animal_id
parameter, or a search of the database can be performed by entering
the desired search criteria.
# Getting first 20 results without any search criteria
animals = pf.animals()
# Extracting data on specific animals with animal_ids
animal_ids = []
for i in animals['animals'][0:3]:
animal_ids.append(i['id'])
animal_data = pf.animals(animal_id=animal_ids)
# Returning a pandas DataFrame of the first 150 animal results
animals = pf.animals(results_per_page=50, pages=3, return_df=True)
Getting animal welfare organizations in the Petfinder database
Similar to the animals()
method described above, the organizations()
method returns data on animal welfare
organizations listed in the Petfinder database based on specific criteria, if any. In addition to a general search
of animal welfare organizations, specific organizational data can be extracted by supplying the organizations()
method with organization IDs.
# Return the first 1,000 animal welfare organizations as a pandas DataFrame
organizations = pf.organizations(results_per_page=100, pages=10, return_df=True)
# Get organizations in the state of Washington
wa_organizations = pf.organizations(state='WA')
More Examples and Tutorials
A series of IPython notebooks that introduce and explore some of the functionality and possible uses of the
petpy
library. The notebooks can also be launched interactively with binder by clicking the
"launch binder" badge.
- 01 -Introduction to petpy
- 02 - Download 45,000 Adoptable Cat Images using petpy and multiprocessing
- Please note the following notebook is still based on the legacy version of Petfinder and thus are not fully
representative of the functionality and methods of the most recent version of
petpy
and the Petfinder API. These are currently being updated to reflect the new version ofpetpy
.
- Please note the following notebook is still based on the legacy version of Petfinder and thus are not fully
representative of the functionality and methods of the most recent version of
- 03 - Download Pure Breeds Cat Images with petpy for Deep Neural Network training
- Provided by contributor ma755
Other
The following are longer usage examples and tutorials that have been posted to external media websites such as Medium.com:
Documentation
Requirements
- Python >= 3.6
- requests >= 2.18.4
- Although not strictly required to use
petpy
, the pandas library is needed for returning the results as a DataFrame.
About Petfinder.com
Petfinder.com is one of the largest online, searchable databases for finding a new pet online. The database contains information on over 14,000 animal shelters and adoption organizations across North America with nearly 300,000 animals available for adoption. Not only does this make it a great resource for those looking to adopt their new best friend, but the data and information provided in Petfinder's database makes it ideal for analysis.
Contributors
- ma755 - Fixed several functions that use an
animal
parameter and implementing checks for exceeding the Petfinder API limit. - ljlevins - Found and fixed an error with the
distance
parameter used in theorganizations
API endpoint.
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file petpy-2.4.1.tar.gz
.
File metadata
- Download URL: petpy-2.4.1.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e32e34ecb5288a389274c04b464d4705ad035ecf09abe09ffd8e472f7bb6507 |
|
MD5 | bd80906c4ce1a498b05592884382420d |
|
BLAKE2b-256 | 0d7abf9cb527b6ffe5e6716b74cb6b6c32ddc41bd2ad39d18e041d888e9267e0 |
File details
Details for the file petpy-2.4.1-py2.py3-none-any.whl
.
File metadata
- Download URL: petpy-2.4.1-py2.py3-none-any.whl
- Upload date:
- Size: 15.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7d6bacecc3f8de5e1c3b113c269053573b3689cba60f3da27a7f7e9ab13bb628 |
|
MD5 | 1d971cd037370dac5de0ee7809d22437 |
|
BLAKE2b-256 | 6aab08814a798682e7b75c08477b796c2a74c3eae442f446f15bb5ba8b0384ef |