petfinder-api Documentation

Similar documents
Python Project Example Documentation

chatterbot-weather Documentation

EVE Market Data Structures Documentation

scieloapi.py Documentation

Yampy Documentation. Release 1.0. Yammer

e24paymentpipe Documentation

withenv Documentation

bottle-rest Release 0.5.0

TPS Documentation. Release Thomas Roten

Python wrapper for Viscosity.app Documentation

sainsmart Documentation

Signals Documentation

Python State Machine Documentation

Google Domain Shared Contacts Client Documentation

Gearthonic Documentation

Python State Machine Documentation

I2C LCD Documentation

contribution-guide.org Release

Roman Numeral Converter Documentation

RiotWatcher Documentation

Release Nicholas A. Del Grosso

Archan. Release 2.0.1

Redis Timeseries Documentation

API Wrapper Documentation

dota2api Documentation

flask-dynamo Documentation

google-search Documentation

thingspeak Documentation

f5-icontrol-rest Documentation

streamio Documentation

Release Fulfil.IO Inc.

picrawler Documentation

Poetaster. Release 0.1.1

Python Finite State Machine. Release 0.1.5

pybtsync Documentation

Game Server Manager Documentation

yagmail Documentation

py-couchdb Documentation

Pulp Python Support Documentation

eventbrite-sdk-python Documentation

django simple pagination Documentation

tapioca-wrapper Documentation

Python simple arp table reader Documentation

Pykemon Documentation

Connexion Sqlalchemy Utils Documentation

goose3 Documentation Release maintainers

solrq Documentation Release Michał Jaworski

linkgrabber Documentation

django-embed-video Documentation

Python AutoTask Web Services Documentation

spacetrack Documentation

lazy-object-proxy Release 1.3.1

django-dynamic-db-router Documentation

OTX to MISP. Release 1.4.2

BlenderPanda Documentation. Release 0.1.0

pytest-benchmark Release 2.5.0

I hate money. Release 1.0

keepassx Release 0.1.0

PrettyPandas Documentation

Archer Documentation. Release 0.1. Praekelt Dev

scrapekit Documentation

Django Wordpress API Documentation

pyshk Documentation Release Jeremy Low

Python Overpass API Documentation

Python data pipelines similar to R Documentation

cwmon-mysql Release 0.5.0

smartfilesorter Documentation

Flask-Cors Documentation

maya-cmds-help Documentation

StackAPI Documentation

TwitterAds Documentation

Infoblox Client Documentation

MyAnimeList Scraper. Release 0.3.0

PyCRC Documentation. Release 1.0

Job Submitter Documentation

Torndb Release 0.3 Aug 30, 2017

tld Documentation Release 0.9 Artur Barseghyan

django CMS Export Objects Documentation

g-pypi Documentation Release 0.3 Domen Kožar

SendCloud OpenCart 2 Extension Documentation

Wifiphisher Documentation

mri Documentation Release Nate Harada

pydrill Documentation

Django-frontend-notification Documentation

oemof.db Documentation

django-gollum Documentation

Django-CSP Documentation

retask Documentation Release 1.0 Kushal Das

Aircrack-ng python bindings Documentation

Inflow Documentation. Release Jaap Broekhuizen

nacelle Documentation

SQLAlchemy-ORM-tree Documentation

edeposit.amqp.calibre Release 1.1.4

Python Schema Generator Documentation

pysharedutils Documentation

Simple libtorrent streaming module Documentation

syslog-ng Apache Kafka destination

Airoscript-ng Documentation

Flask-Twilio Documentation

ProxySQL Tools Documentation

Transcription:

petfinder-api Documentation Release 0.1 Greg Taylor Jun 01, 2017

Contents 1 Assorted Info 3 2 User Guide 5 2.1 Installation................................................ 5 2.1.1 Distribute & Pip......................................... 5 2.1.2 Get the source.......................................... 5 2.2 Quickstart................................................ 6 2.2.1 Petfinder.com credentials.................................... 6 2.2.2 Instantiate the API client.................................... 6 2.2.3 How to determine kwargs for API methods.......................... 6 2.2.4 Many calls return generators.................................. 7 2.2.5 Auto-pagination of results................................... 7 2.3 API Reference.............................................. 7 2.3.1 petfinder.petfinderclient.................................... 7 2.3.2 petfinder.exceptions....................................... 9 3 Indices and tables 11 Python Module Index 13 i

ii

petfinder-api is a BSD licensed Python wrapper around the Petfinder API. The module handles preparing and sending API requests, parsing the response, and returning Python objects for usage in your application. import petfinder # Instantiate the client with your credentials. api = petfinder.petfinderclient(api_key='yourkey', api_secret='yoursecret') # Query away! for shelter in api.shelter_find(location='30127', count=500): print(shelter['name']) # Search for pets. for pet in api.pet_find( animal="dog", location="29678", output="basic", breed="treeing Walker Coonhound", count=200, ): print("%s - %s" % (pet['id'], pet['name'])) # TODO: Find homes for these guys. Contents 1

2 Contents

CHAPTER 1 Assorted Info Issue tracker - Report bugs here. GitHub project - Source code lives here. @gctaylor Twitter - Tweets from the maintainer. 3

4 Chapter 1. Assorted Info

CHAPTER 2 User Guide The user guide covers topics such as installation and general use of the module. Content is largely step-by-step instructions for getting started with, and using petfinder-api. Installation This part of the documentation covers the installation process. There are a few different ways to retrieve and install petfinder-api. Distribute & Pip Installing petfinder-api is simple with pip: pip install petfinder easy_install works, too: easy_install petfinder Get the source petfinder-api is developed on GitHub in the petfinder-api project. You can either clone the repository: git clone git://github.com/gtaylor/petfinder-api.git Download the tarball: curl -OL https://github.com/gtaylor/petfinder-api/tarball/master 5

Or download the zip: curl -OL https://github.com/gtaylor/petfinder-api/zipball/master Quickstart This section goes over how to get up and running quickly. We ll assume that you have already followed the Installation instructions, and are ready to go. Petfinder.com credentials Before you can make your first query to Petfinder, you ll need to obtain a set of API credentials. You can get them from the Petfinder API page. You ll need to register first. Jot down your API Key and API Secret for use in the next step. Instantiate the API client Next, you ll want to import the module: >>> import petfinder Then instantiate the API client with your Petfinder.com API credentials: >>> api = petfinder.petfinderclient(api_key='yourkey', api_secret='yoursecret') You are now ready to query against the Petfinder API: >>> breeds = api.breed_list(animal="dog") See API Reference for a full list of methods. We support all of the query methods on the Petfinder API. Please do continue reading the next few sections in this quickstart for some important tidbits. How to determine kwargs for API methods petfinder-api is a very thin wrapper around the Petfinder API. We point developers to the Petfinder API docs for all of the required/optional keywords, instead of duplicating it all here. For example, look at the pet.find method on the Petfinder API docs. This maps to our petfinder. PetFinderClient.pet_find() method. You can ignore any of the key arguments, since petfinder-api sets that for you. The only required parameter for pet.find is location. Here s a minimal example: for pet in api.pet_find(location="29678"): # This will be a pet record in the form of a dict. print(pet) To outline a process for this, first determine which method in API Reference you ll want to use: 1. Reference the beginning of the docstring for which Petfinder API call it wraps. For example, petfinder. PetFinderClient.pet_find() wraps pet.find. 2. Refer to the Petfinder API docs for the required kwargs. 6 Chapter 2. User Guide

Many calls return generators An extremely important thing to note is that many of the calls return Python generators. This is the most efficient way for us to paginate through multiple pages of results (behind the scenes). Make sure to note the return types for whatever API client method you re calling. More details can be found in API Reference. Auto-pagination of results Another thing to keep in mind is that the petfinder-api client auto-paginates through results. The count parameter in the Petfinder API determines how many results are returned per page. petfinder-api will happily continue to make additional API requests if you continue to iterate over the generators it returns. This will often continue until you see the infamous petfinder.exceptions.limitexceeded exception, which you will hit on pretty much any *_find call, and some *_list calls. The important thing to consider is that a higher count will result in larger, but fewer HTTP requests to the Petfinder API, whereas smaller values will result in more frequent, but smaller requests from the API. API Reference This page serves as a complete reference to all public classes and exceptions. This is probably only useful after you have read Quickstart. petfinder.petfinderclient class petfinder.petfinderclient(api_key, api_secret, endpoint= http://api.petfinder.com/ ) Simple client for the Petfinder API. You ll want to pull your API details from http://www.petfinder.com/ developers/api-key and instantiate this class with said credentials. Refer to http://www.petfinder.com/developers/api-docs for the required kwargs for each method. It is safe to ignore the key argument, as this client handles setting that for you. breed_list PetFinderClient.breed_list(**kwargs) breed.list wrapper. Returns a list of breed name strings. Return type list Returns A list of breed names. pet_get PetFinderClient.pet_get(**kwargs) pet.get wrapper. Returns a record dict for the requested pet. Return type dict Returns The pet s record dict. 2.3. API Reference 7

pet_getrandom PetFinderClient.pet_getrandom(**kwargs) pet.getrandom wrapper. Returns a record dict or Petfinder ID for a random pet. Return type dict or str Returns A dict of pet data if output is 'basic' or 'full', and a string if output is 'id'. pet_find PetFinderClient.pet_find(**kwargs) pet.find wrapper. Returns a generator of pet record dicts matching your search criteria. Return type generator Returns A generator of pet record dicts. Raises petfinder.exceptions.limitexceeded once you have reached the maximum number of records your credentials allow you to receive. shelter_find PetFinderClient.shelter_find(**kwargs) shelter.find wrapper. Returns a generator of shelter record dicts matching your search criteria. Return type generator Returns A generator of shelter record dicts. Raises petfinder.exceptions.limitexceeded once you have reached the maximum number of records your credentials allow you to receive. shelter_get PetFinderClient.shelter_get(**kwargs) shelter.get wrapper. Given a shelter ID, retrieve its details in dict form. Return type dict Returns The shelter s details. shelter_getpets PetFinderClient.shelter_getpets(**kwargs) shelter.getpets wrapper. Given a shelter ID, retrieve either a list of pet IDs (if output is 'id'), or a generator of pet record dicts (if output is 'full' or 'basic'). Return type generator Returns Either a generator of pet ID strings or pet record dicts, depending on the value of the output keyword. Raises petfinder.exceptions.limitexceeded once you have reached the maximum number of records your credentials allow you to receive. 8 Chapter 2. User Guide

shelter_listbybreed PetFinderClient.shelter_listbybreed(**kwargs) shelter.listbybreed wrapper. Given a breed and an animal type, list the shelter IDs with pets of said breed. Return type generator Returns A generator of shelter IDs that have breed matches. petfinder.exceptions Petfinder API exceptions. exception petfinder.exceptions.authenticationfailure Raised when an authentication failure occurs. exception petfinder.exceptions.genericinternalerror Your guess is as good as mine. exception petfinder.exceptions.invalidgeographicallocationerror Raised when an invalid geographical location is specified. exception petfinder.exceptions.invalidrequesterror Raised when an invalid or mal-formed request is sent. exception petfinder.exceptions.limitexceeded Raised when usage limits are exceeded. exception petfinder.exceptions.petfinderapierror Base class for all Petfinder API exceptions. Mostly here to allow end users to catch all Petfinder exceptions. exception petfinder.exceptions.recorddoesnotexisterror Raised when querying for a record that does not exist. exception petfinder.exceptions.requestisunauthorizederror Raised when attempting to call a method that the user is unauthorized for. exception petfinder.exceptions.unrecognizederror This is raised if the API returns a status code that we don t have a matching exception for. This is more for future-proofing, in case they add extra status codes. 2.3. API Reference 9

10 Chapter 2. User Guide

CHAPTER 3 Indices and tables genindex modindex search 11

12 Chapter 3. Indices and tables

Python Module Index p petfinder.exceptions, 9 13

14 Python Module Index

Index A AuthenticationFailure, 9 B breed_list() (petfinder.petfinderclient method), 7 G GenericInternalError, 9 I InvalidGeographicalLocationError, 9 InvalidRequestError, 9 L LimitExceeded, 9 P pet_find() (petfinder.petfinderclient method), 8 pet_get() (petfinder.petfinderclient method), 7 pet_getrandom() (petfinder.petfinderclient method), 8 petfinder.exceptions (module), 9 PetfinderAPIError, 9 PetFinderClient (class in petfinder), 7 R RecordDoesNotExistError, 9 RequestIsUnauthorizedError, 9 S shelter_find() (petfinder.petfinderclient method), 8 shelter_get() (petfinder.petfinderclient method), 8 shelter_getpets() (petfinder.petfinderclient method), 8 shelter_listbybreed() (petfinder.petfinderclient method), 9 U UnrecognizedError, 9 15