Changelog and version changes made with each release.
- A
PetfinderInvalidCredentials
error will now be raised when initializing the Petfinder API if passing invalid credentials. - Removed the rate limit decorator for daily number of calls.
- Now correctly returns the response from the API when only requesting one animal ID.
- Another hotfix for correctly incrementing re-tries in the event of a 500 error.
- Hotfix to correct issue with change released in 2.4.0 that would return a sparse JSON result if an animal ID couldn't be found.
- There seems to be some intermittent issues with the Petfinder API (at the time of this writing November 7th, 2024)
where an increased volume of
500
errors are being raised, at least according to my own testing. A change has been made to attempt an API call three times in the event of a500
error rather than immediately raising a500
status code. If a non-authentication request reaches the three count retry, a sparse JSON dictionary is returned with the response code.- If anyone else has experienced this, please let me know.
- Implemented rate-limiting for API calls that could potentially exceed the quotas set by Petfinder (50 calls/second, 1,000/day). An exponential backoff strategy is employed when rates exceed the given limits and tries ten more times before giving up and returning the collected results.
- Access token that is generated on first initialization of Petfinder should now refresh automatically after expiring.
- Removed the
max_page_warning
that would be displayed when there were fewer total pages in the Petfinder API results to those requested in thepages
parameter. - A
response
key has been added to the returned animal or organization object. If an ID isn't found, theresponse
value will be 404. - Type annotations have been added to the
Petfinder
methods.
- Added several additional search filters to the
animals()
function.declawed
: Filters results by animals that are marked as declawed.house_trained
: Filters results by animals that are house trained.special_needs
: Filters results by animals that have special needs
- Search filters that can take multiple values in the
animals()
function, includingage
,gender
,status
,animal_type
,size
, andcoat
, should now correctly accept both comma-delimited strings, such asage='baby,young'
and lists or tuples. - The required version for
pandas
has been updated to at least version1.0.0
Very small maintenance patch to update several setup.py
settings. There is no need to update to this version.
- Support for Python 3.5 has been discontinued.
- The
animals()
method has been updated to include new parameters provided by Petfinder'sanimal
endpoint. These parameters include:good_with_cats
: Boolean for filtering animals that are designated as good with cats.good_with_children
: Boolean for filtering animals that are designated as good with children.good_with_dogs
: Boolean for filtering animals that are designated as good with dogs.before_date
: Returns results published before the specified time.after_date
: Returns results published after the specified time.
organization_id
parameter in theanimals
method should now only return animals from specified organization IDs.
New release includes a bug fix and some additional changes for checking total usage against the Petfinder API.
animal_type
parameter used in theanimals()
endpoint has been corrected and should be working properly.- New methods for checking the usage of the supplied API key against the limits defined by the Petfinder API have been
implemented to better help warn users when they are approaching their API request limit.
- If the
max_pages
parameter exceeds 10,000, a warning will be issued to give the user the opportunity to continue or limit their results to 10,000 pages. - When the API limits are exceeded, a
RuntimeError
will be issued.
- If the
Thank you to contributor ma755 for submitting the pull request.
Small update release to fix the distance
parameter logic when searching for pets using the animals()
or
organizations()
methods. Thank you to contributor ljlevins for submitting the pull
request.
The 2.1.0
release of petpy
implements several user-defined exceptions to help users debug any
errors that may occur. Although the petpy
library attempts to find any invalid passed parameter values and raise the
appropriate error before the call to the Petfinder API is made to reduce the number of calls made to the API; however,
some errors cannot be caught until after the API call is made. This update introduces these custom, user-defined
exceptions for debugging error responses from the Petfinder API. For more information on the Petfinder API error
definitions, please see the Petfinder API documentation.
The following is a list of the new user-defined exceptions.
PetfinderInvalidCredentials
- Raised when a user enters invalid API key and secret key credentials.
PetfinderInsufficientAccess
- Raised when a status code 403 occurs. This error would typically be raised when the current authentication token to the Petfinder API has expired and requires the connnection to be re-authenticated.
PetfinderResourceNotFound
- Raised when a status code 404 occurs.
PetfinderUnexpectedError
- Raised when a status code 500 occurs.
PetfinderInvalidParameters
- Raised when a 400 status code occurs. The exception will include the invalid
parameters detected by the Petfinder API and include those parameters as part of the error output as a JSON object.
For more information on this error, please see the
Petfinder API documentation.
- Please note the
petpy
library will attempt to catch any invalid parameters before the API call is made to avoid extraneous issuage of the API, but if an invalid parameter does get through then this error should help provide the necessary information for users to debug any errors related to their chosen parameters.
- Please note the
- Raised when a 400 status code occurs. The exception will include the invalid
parameters detected by the Petfinder API and include those parameters as part of the error output as a JSON object.
For more information on this error, please see the
Petfinder API documentation.
The following other changes have been made in the 2.1.0
release.
- The
host
andauth
attributes of thePetfinder
class are now private (to the extent that Python allows private attributes, denoted with an underscore in front of the attribute).
Minor bug fix release with following:
breeds()
method now correctly returns data when a single animal type is supplied.animals()
method now properly displays the correct error message when thedistance
parameter is 0 <= distance <= 500.
- Fixes the
animals()
andorganizations()
method to return all matching search results when thepages
parameter is set toNone
. - The resulting JSON (dictionary) from the
breeds()
method when the parameterreturn_df=False
will now consistently havetypes
as the key. Prior to this change, if thebreeds()
method was called with a single animal type, the resulting key name in the returned object would be namedtype
, whereas if more than one animal type is specified the key name would betypes
. - The
distance
parameter for theanimals()
andorganizations()
parameters will now raise aValueError
if it is less than 0.
New major release coinciding with the release of v2.0 of the Petfinder API!
The legacy version of the Petfinder API, v1.0, will be retired in January 2020, therefore, the petpy
library has
been updated almost from the ground up to be compatible as possible with the new version of the Petfinder API! The
new version of the Petfinder API is a huge improvement over the legacy version, with many changes and additions to
the design of the API itself.
Below is a summary of all the changes made in the release of petpy 2.0
.
petpy
now supports the latest release of Python 3.7- Support for Python 2.7 is discontinued as Python 2.7 will be officially discontinued in January 2020.
- The following methods have been added to
petpy
to make it compatible with v2.0 of the Petfinder API.animal_types()
is used to getting animal types (or type) available from the Petfinder API. The release of v2.0 of the Petfinder API added several endpoints for accessing animal types in the Petfinder database. This method wraps both Petfinder API endpoints for getting animal types. More information on the animal type endpoints in the Petfinder API can be found in its documentation:breeds()
is the new method for getting available animal breeds from the Petfinder database. The API endpoint documentation is available on the Petfinder API documentation page.animals()
is the method for extracting animal data available on the Petfinder API and deprecates thepets()
related methods. The method wraps both theanimals
andanimal/{id}
endpoints of the Petfinder API. The documentation for these endpoints can be found in the Petfinder API documentation:organizations()
is now the method for extracting animal welfare organization data available on Petfinder and deprecates previousshelter()
related methods and endpoints. Theorganizations()
method wraps both the Petfinder APIorganizations
andorganizations/{id}
endpoints. The Petfinder API documentation for these two endpoints can be found below:
- The following methods have been removed as they are no longer valid endpoints with the release of v2.0 of the
PetFinder API.
pet_get_random()
shelter_list_by_breed()
shelter_get_pets()
- General refactoring and code clean-up.
- Add
pandas
back as an installation requirement as it is included in top-level imports.pandas
is still not necessary to use the primary functionality ofpetpy
.
- Implement check to make sure
count
parameter is not larger than 1,000 records (per the Petfinder API limits). Ifcount
exceeds 1,000 aValueError
is raised. - Add check for ensuring the number of total records to return does not exceed 2,000 when paging results with
the
pages
andcount
parameters. If the desired amount of records is higher than 2,000, aValueError
is raised. - Remove Python 3.3 support. Although
petpy
should work fine for those still using Python 3.3, testing for 3.3 has been discontinued.
- General refactoring of the
petpy
library to remove unneeded methods from being exposed when importing the library. The best way to import and begin usingpetpy
isfrom petpy import Petfinder
or, less optimally,import petpy
, then calling thePetfinder
class bypetpy.Petfinder
.
- There is now a proper message when the daily API call limit is exceeded. Before the change, methods would
return a
JSONDecodeError
. - The Python 2 to 3 compatibility package
six
, has been added as a requirement for package installation. Thesix
library is lightweight and ensures thepetpy
package works properly for Python 2 and 3. - Numpy is no longer required for installing the package. Numpy's
nan
was initially used to denoted shelters animals that were not found in the Petfinder database. The value returned when a shelter or animal is not found is now 'na'.
- Fix to the
shelter_get()
method for handling empty responses when no shelters returned for when the parameterreturn_df = True
. - Fix to getting pets available at a shelter with
shelter_get_pets()
when the parameterreturn_df = True
when the given shelter does not return any available animals.
- Refactoring of the library to clean up code files.
- Fixed a bug with the
shelter_get_pets()
method that caused an error to be thrown when there is only one pet record and the parameterreturn_df = True
. - Many changes to simplify expressions and internal code within methods.
- The
Petfinder
class method names and parameters have been renamed to be PEP8 compatible. I apologize as this will cause backward compatibility issues upon updating for anyone using previous versions. The original intention of the naming was to reflect the Petfinder API's method names as closely as possible, but after further consideration and given the relatively short life of the library, I think the change is necessary for the future growth and maturity of the package. - How the methods interact with the Petfinder API is unchanged. Thus there is no immediate need to update your version of petpy if it will break any current code.
- The Github repo README has been updated with the new API methods.
- Below is a table detailing the changed method names:
Previous Method Name | New Method Name |
---|---|
pet_getRandom() | pet_get_random() |
shelter_getPets() | shelter_get_pets() |
shelter_listByBreed() | shelter_list_by_breed() |
- The following lists the method parameter names that have changed with the release:
Previous Parameter Name | New Parameter Name |
---|---|
petId | pet_id |
shelterId | shelter_id |
- This release removes pandas as an installation requirement for the package. Although pandas is required to convert the API results into a DataFrame, this is optional and not necessary to the building or use of the package itself.
- Calls that return JSON results when using the
pet_find()
method whenreturn_df=True
are now adequately handled and an empty pandas DataFrame is returned. This result can happen when searching for a particular breed of animal that is currently not available in the Petfinder database.
- The paged results should now cap at Petfinder's 2,000 search limit consistently.
- The methods
shelter_get()
andshelters_get()
now handle shelters that have opted-out of having their information available in the Petfinder API.
- Paged results will now reach Petfinder's 2,000 records per search limit. Before, if the next paged result would
equal or exceed 2,000 results the call would end, and the results would be returned. For example, if the parameters
pages
is 10 andcount
is 200, 2,000 records will now be returned, whereas previously 1,800 would be returned.
- Paging results that exceed Petfinder's limit of 2,000 records returned per search with
return_df = True
will now correctly exit the loop and return the results as a DataFrame.
- The fix to returning a DataFrame when paging results is now implemented in this release. Apologies for the oversight, the code change was not made before releasing the previous version.
- The contact information returned with a DataFrame when
return_df = True
now has the prefix 'contact.' removed to make the results cleaner.
- Paging results now returns the stated number of pages in the
pages
parameter. Before,pages + 1
results were returned. - Returning pandas DataFrames with methods
pet_find()
andshelter_find()
should no longer throwValueError
(duplicate column name was causing an error in concatenating a list of results into a DataFrame).
shelter_getPets()
method now returns a complete flattened pandas DataFrame when the parameterreturn_df = True
.
- Slight fix to
pet_getRandom()
method. Before, if the method parameterreturn_df = True
, but the parameteroutput
was not one of 'basic' or 'full', thereturn_df
parameter was overridden and set asFalse
. Now, ifreturn_df = True
andoutput
None
, thenoutput
is set to 'full' to return the complete DataFrame. - Added
records
parameter topet_getRandom()
to allow multiple random results to be returned in the same method call. Please note each record returned counts as one call made to the Petfinder API. - Added API convenience methods
pets_get()
andshelters_get()
for pulling multiple results given a list or tuple of IDs. These methods are essentially wrappers of the API methodspet_get()
andshelter_get()
. - More code cleanup, formatting, and simplification.
- Add option to convert returned results into a pandas DataFrame.
- Formatting and code cleanup.
- Updated docstrings
First major release.