petfinder api的包装器
petp的Python项目详细描述
Petpy-Petfinder API的Python包装器
:cat2::dog2::公鸡::兔子2::赛马:
petpy是用于Petfinder API的易于使用和方便的python包装器。
安装
petpy
很容易通过pip
安装。
pipinstallpetpy
库也可以克隆或下载到您选择的位置,然后使用setup.py
安装
按以下方式归档:
gitclonegit@github.com:aschleg/petpy.gitcdpetpypythonsetup.pyinstall
示例和用法
必须首先使用Petfinder创建帐户才能接收API和secret
钥匙API和密钥将用于授予对Petfinder API的访问权限,该权限将持续3600秒,或者
小时身份验证期结束后,必须使用petfinder api重新进行身份验证。以下是一些
使用petpy
开始的快速示例。关于petpy
的更深入的教程以及
可以使用库完成,请参阅下面的更多示例和教程部分。
使用petfinder api进行身份验证
在初始化Petfinder
类的同时,验证与petfinder api的连接。
pf=Petfinder(key=key,secret=secret)
寻找动物类型
# All animal types and their relevant data.all_types=pf.animal_types()# Returning data for a single animal typedogs=pf.animal_types('dog')# Getting multiple animal types at oncecat_dog_rabbit_types=pf.animal_types(['cat','dog','rabbit'])
获取可用动物类型的动物品种
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'])
也可以设置breeds
方法,通过设置
参数return_df = True
。
cat_breeds_df=pf.breeds('cat',return_df=True)all_breeds_df=pf.breeds(return_df=True)
在petfinder上查找可用的动物
animals()
方法根据petfinder数据库中列出的指定条件返回动物。特定的
可以使用animal_id
参数搜索动物,也可以通过输入
所需的搜索条件
# Getting first 20 results without any search criteriaanimals=pf.animals()# Extracting data on specific animals with animal_idsanimal_ids=[]foriinanimals['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 resultsanimals=pf.animals(results_per_page=50,pages=3,return_df=True)
在petfinder数据库中获取动物福利组织
与上面描述的animals()
方法类似,organizations()
方法返回关于动物福利的数据
petfinder数据库中列出的基于特定条件的组织(如果有)。除了一般的搜索
在动物福利组织中,可以通过提供organizations()
来提取特定的组织数据。
具有组织ID的方法。
# Return the first 1,000 animal welfare organizations as a pandas DataFrameorganizations=pf.organizations(results_per_page=100,pages=10,return_df=True)# Get organizations in the state of Washingtonwa_organizations=pf.organizations(state='WA')
更多示例和教程
一系列ipython笔记本,介绍和探讨
petpy
库。通过单击
“启动活页夹”徽章
请注意以下笔记本仍然基于旧版本的petfinder,因此不完全
最新版本petpy
和Petfinder API的功能和方法的代表这些
目前正在更新以反映petpy
的新版本。
文件
要求
关于Petfinder.com
Petfinder.com是最大的在线可搜索数据库之一,用于在线寻找新宠物数据库包含 北美超过14000个动物收容所和收养组织的信息,将近300000只动物 可供领养。这不仅使它成为一个伟大的资源,为那些希望收养他们的新的最好的朋友, 但petfinder数据库中提供的数据和信息使其成为理想的分析工具。
许可证
麻省理工学院