提供与CaveVeStaseAPI交互时可使用的方法和类。

aspace-client的Python项目详细描述


archivesspace python客户端

Build Status

PyPI version

python包提供的web客户端功能 以ArchivesSpace 2.x及更高版本的API为目标。这个包是开发出来的 以帮助正在进行的和将来的归档空间迁移。

关于

aspace模块从 requestspython库,并尝试提供对所有 archivesspace的rest api端点,同时也保留向后 兼容性和支持开发工具,如pylint。档案空间 目前(2019年5月)有超过250个API端点。支持和维护所有 其中的端点是一项艰巨的任务,因此新的特性和错误修复是 根据它们对执行正在进行的归档空间迁移的价值确定优先级。

安装

This has a listing on PyPI!

pip install aspace-client

您还可以直接从github存储库安装此项目:

pip install https://github.com/AtlasSystems/ArchivesSpace-Python-Client/zipball/master

开发人员安装

下面是在“可编辑”模式下安装此软件包的说明。这个 将允许您对包进行更改并实时测试它们。

AS_CLIENT_DIR="/path/to/aspace-client"
git clone https://github.com/AtlasSystems/ArchivesSpace-Python-Client.git "$AS_CLIENT_DIR"# In your python project directory, or in your venv
pip install -e "$AS_CLIENT_DIR"

用法

fromaspace.clientimportASpaceClientclient=ASpaceClient('http://localhost:8089','admin','admin')

这将初始化一个以archivespace实例为目标的客户端 应用程序编程接口。此初始化还将自动验证您的用户。在那里 如果您将此包用作 更大的脚本,其中与archivespace的交互不是主要的 组件,而您所处的环境不是100%确定 ArchivesSpace正在运行且可访问。对于该操作:

fromtimeimportsleepfromaspace.clientimportASpaceClientclient=ASpaceClient(base_url='http://localhost:8089',# Base url for connecting to your ASpace's API.username='admin',password='admin',auto_authenticate=False,)whileclient.get('/version').status_code!=200:print('ArchivesSpace API is not up')sleep(2)client.authenticate()

上面的操作也有内置的支持,还有内置的 从configparser实例中提取设置的功能。

在settings.ini中:

[aspace_credentials]api_host='http://aspace.cloudapp.eastus.azure.com'username='automation-user'password='automation-user-password'

应用程序内.py:

importconfigparserimportaspaceconfig=configparser.ConfigParser()config.load('settings.ini')client=(aspace.client.ASpaceClient.init_from_config(config).wait_until_ready(check_interval=2.0,max_wait_time=200.0,authenticate_on_success=True,))

失败的身份验证会引发错误,因此如果这些脚本中仍有任何一个 运行时,就可以查询api了!此包与 使用以下注意事项的ArchivesSpace API。

  1. 我们都喜欢的python库所描述的语法
  2. 文档为archivespace api描述的api端点结构

python库的典型语法被保留,因此所有http 方法(post、get、delete等)通常以uri或端点开头, 相对于api的基url。从来没有假设uri可以确保 所有操作都是可预测的,并且 API使用正确。

获取存档空间系统信息

# Get the system infoprint(client.get('/').json())

管理存储库

# Get a listing of all repositoriesrepositories=client.get('/repositories').json()forrepositoryinrepositories:print(repository)# Create a new repositorynew_repo={}new_repo['repo_code']='test_repo'new_repo['name']='Test Repository'response=client.post('/repositories',json=new_repo).json()# Update the name of that repositoryrepo=client.get(response['uri']).json()repo['name']='Andy Samberg University Archives - Test Repository'client.post(repo['uri'],json=repo)# Delete the repositoryclient.delete(new_repo['uri'])

此语法可用于与ArchivesSpace的所有端点交互,如 只要响应返回为json。大多数都是。还有一些 当前提供的ArchivesSpace API功能的扩展。

流记录

# Manage your resource records one at a time, no matter how many you haveforresourceinclient.stream_records().resources():ifresource['title'].endswith('!'):# Remove trailing spaces and print('Cleaning Resource:',resource['uri'],resource['title'])resource['title']=resource['title'].rstrip('!')update_result=client.post(resource['uri'],json=resource).json()print(update_result)# Works for accessions and agentsclient.stream_records().accessions()client.stream_records().people()client.stream_records().corporate_entities()client.stream_records().families()client.stream_records().software()client.stream_records().all_agents()# Works for endpoints that do not have an explicitly defined stream methodclient.stream_records().records('container_profiles'):pass# Works for endpoints that do not have an explicitly defined stream method# and require a repository reference in the URI.forassessmentinclient.stream_records().repository_records('assessments'):pass# Optional limits can be placed on record streams, so that only 1 repository# is considered, as opposed to streaming all records from all repositories,# which is default.assessments_stream=client.stream_records().repository_records('assessments',repository_uris=['/repositories/2'])forassessmentinassessments_stream:pass

用户管理

# Change all of your user's passwords to "something really complicated"client.manage_users().change_all_passwords('pa$$w0rd',include_admin=True)# Randomize all of your non-admin user's passwordsimportstringimportrandomdefrandom_password():return''.join(random.choice(string.ascii_uppercase+string.digits)for_inrange(25))# The same password for every userclient.manage_users().change_all_passwords(new_password=random_password(),include_admin=False,)# Different password for every userclient.manage_users().change_all_passwords(new_password=lambdauser:random_password(),include_admin=False,)

贡献

如果您有任何建议或错误报告,请随时报告 the issues tab 或者发邮件到devgineers@atlas-sys.com。 如果您是Git的新手,请随时给我们发电子邮件,但仍希望 贡献。

拉取请求是受欢迎的,但它们将接受一个审查过程。 一致的代码样式是这个项目的目标,因为它目前 尝试遵循 PEP8 Python style guide。 在提交或要求投稿时请记住这一点, 但也要记住PEP是一个灵活的标准,我们是 愿意破例。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
用Java学习Eclipse可视化编辑器Swing   eclipse如何找到运行Java程序所需的时间?   JAVA用于在Tomcat 8上运行Jena API的lang.UnsupportedClassVersionError   java在Main中调用字符串方法   javascript“子进程”。exec无法运行Java函数   java如何使用Gmail API获取电子邮件正文内容   java为什么客户端看不到服务器发送的第一条消息?   java无法在安卓 WebView中滚动到顶部   从服务器运行web服务时,java代码中的日期为空   从子任务返回后执行后台任务时发生java错误   java无法一致地处理弹出窗口   java(Android)通过蓝牙向µ控制器发送字节   java无法在emulator中启动AVD?安卓工作室   Android Java应用程序正在冻结,没有返回错误消息   java如何使用TestNg记录测试历史?