所有FamilySearch API的Python包装器
python-fs-stack的Python项目详细描述
python-fs-stack提供了一个python包,它简化了对 FamilySearchREST-style API。
Home Page: | http://pypi.python.org/pypi/python-fs-stack |
---|---|
Source Code: | https://github.com/familysearch-devnet/python-fs-stack |
内容
Dependencies
- python 2.4或更高版本
- simplejson,如果使用早于2.6的python
- wsgi_intercept0.5.0或更高版本(仅在运行测试套件时需要)
Installation
使用pip:
pip install python-fs-stack
或者使用easy_install(来自setuptools或distribute):
easy_install python-fs-stack
或(手动下载后):
python setup.py install
Example Usage
首先,导入familysearch类:
from familysearch import FamilySearch
Authenticating with FamilySearch
python-fs-stack支持几种启动会话的方法 FamilySearch,包括基本身份验证、OAuth和恢复以前的 会议。
使用基本身份验证立即登录:
fs = FamilySearch('ClientApp/1.0', 'developer_key', 'username', 'password')
使用基本身份验证在单独的步骤中登录:
fs = FamilySearch('ClientApp/1.0', 'developer_key') fs.login('username', 'password')
使用基本身份验证分两步登录:
fs = FamilySearch('ClientApp/1.0', 'developer_key') fs.initialize() fs.authenticate('username', 'password')
使用OAuth登录:
import webbrowser fs = FamilySearch('ClientApp/1.0', 'developer_key') fs.request_token() webbrowser.open(fs.authorize()) # [Enter username and password into browser window that opens] verifier = [verifier from resulting web page] fs.access_token(verifier)
继续上一个会话:
fs = FamilySearch('ClientApp/1.0', 'developer_key', session='session_id')
使用生产系统而不是参考系统:
fs = FamilySearch('ClientApp/1.0', 'developer_key', base='https://api.familysearch.org')
Accessing Family Tree Information
打印当前用户的家族树详细信息:
print fs.person()
要指定要检索的个人ID,请将该ID作为参数传递:
print fs.person('ABCD-123')
要打印多个族树条目,请将ID列表作为参数传递。到 将其他参数传递给api,只需将它们作为命名参数传递即可:
print fs.person(['ABCD-123', 'EFGH-456'], events='all', children='all')
打印最新版本的人员列表(此请求更轻量级 而不是完整的个人请求,因此它同时支持更多的ID:
for person in fs.version(['ABCD-123', 'EFGH-456']): print person['id'], person['version']
打印人物角色的内容:
print fs.persona('ABCD-123')
打印当前用户的血统:
print fs.pedigree()
更好地格式化血统输出:
import pprint pprint.pprint(fs.pedigree())
Searching for Persons in the Family Tree
找一个叫约翰·史密斯的男人:
results = fs.search(givenName='John', familyName='Smith', gender='Male', maxResults=10)
检索上一次搜索的第二页:
more_results = fs.search(contextId=results[0]['contextId'], maxResults=10, startIndex=10)
搜索john smith的完全匹配项(使用optionsdict指定 名称中带有句点的选项:
results = fs.search(options={'givenName.exact': 'John', 'familyName.exact': 'Smith'}, gender='Male', maxResults=10)
Searching for Possible Duplicates
搜索一个人的可能副本:
matches = fs.match('ABCD-123')
计算两个人之间的匹配分数:
match = fs.match('ABCD-123', id='EFGH-456')
搜索与指定参数匹配的可能重复项:
matches = fs.match(givenName='John', familyName='Smith', gender='Male', birthDate='1900', birthPlace='USA', deathDate='1950', deathPlace='USA')
Standardizing Places, Names, and Dates
按名称查找地点:
place = fs.place(place='paris')
按ID查找地点:
place = fs.place(5061509)
按ID查找位置列表:
places = fs.place([5061509, 5061446])
按名称查找一个位置,仅显示最可能的结果,并以其他语言环境返回结果:
place = fs.place(place='germany', filter=True, locale='de')
标准化名称:
name = fs.name('John Smith')
标准化名称列表:
names = fs.name(['John Smith', 'Jane Doe'])
标准化日期:
date = fs.date('1-1-11')
标准化日期列表:
dates = fs.date(['1-1-11', 'december 31 1999'])