官方代码42 Python API客户端
py42的Python项目详细描述
py42,Python-SDK的官方代码
py42
是一个围绕code42restapi的Python包装器,它还提供了其他一些有用的实用程序方法。
它被设计用来开发您自己的工具来处理Code42数据,同时避免开销
会话/身份验证管理。在
要求
- Python 2.7.x或3.5.0+
- Code42服务器6.8.x+或云环境(例如。控制台.us.code42.com或crashplan.com网站)在
安装
运行setup.py
脚本来安装py42包及其对系统的依赖性。
对此,您可能需要管理权限。在
$ python setup.py install
你好,py42
下面是一个简单的示例来验证安装和您的服务器/帐户。在
启动Python解释器
^{pr2}$进口一些必需品
>>>importpy42.sdk>>>importpy42.utilasutil
初始化客户端。在
>>>sdk=py42.sdk.from_local_account("https://console.us.code42.com","john.doe","password")
获取并打印用户信息。在
>>>response=sdk.users.get_current()>>>util.print_response(response)
您应该看到如下所示:
{"username":"john.doe","orgName":"ACME Organization","userId":123456,"emailPromo":true,"licenses":[],"modificationDate":"2018-08-29T15:32:56.995-05:00","blocked":false,"usernameIsAnEmail":true,"userUid":"1234567890abcdef","userExtRef":null,"email":"john.doe@acme.com","status":"Active","localAuthenticationOnly":false,"orgUid":"123456789123456789","passwordReset":true,"active":true,"creationDate":"2012-01-16T11:25:43.545-06:00","orgType":"BUSINESS","firstName":"John","lastName":"Doe","notes":null,"orgId":123456,"quotaInBytes":-1,"invited":false}
配置
有一些默认设置会影响客户端的行为。在
Name | Description | Default |
---|---|---|
verify_ssl_certs | Controls whether the SDK verifies the server's certificate. Possible values: ^{ | ^{ |
proxies | Dictionary mapping protocol or protocol and hostname to the URL of the proxy. See the Requests library's documentation on proxies for more info. | ^{ |
debug.level | Controls log level | ^{ |
debug.logger | Controls logger used | ^{ |
items_per_page | Controls how many items are retrieved per request for methods that loops over several "pages" of items in order to collect them all. | 500 |
要覆盖这些设置,请在创建客户机之前导入py42.settings
并根据需要重写值。
例如,要在开发环境中禁用证书验证,请执行以下操作:
importpy42.sdkimportpy42.settingsassettingsimportloggingsettings.verify_ssl_certs=False# customize loggingcustom_logger=logging.getLogger("my_app")handler=logging.FileHandler("my_app.log")custom_logger.addHandler(handler)settings.debug.logger=custom_loggersettings.debug.level=logging.DEBUGsdk=py42.sdk.from_local_account("https://console.us.code42.com","my_username","my_password")
使用
SDK对象为跨Code42环境的api打开可用性,包括存储节点。在
importpy42.sdksdk=py42.sdk.from_local_account("https://console.us.code42.com","my_username","my_password")# clients are organized by feature groups and accessible under the sdk object# get information about the current user.current_user=sdk.users.get_current()# page through all devices available to this user.fordevice_pageinsdk.devices.get_all():fordeviceindevice_page["computers"]:print(device)# page through all orgs available to this user.fororg_pageinsdk.orgs.get_all():fororginorg_page["orgs"]:print(org)# save a copy of a file from an archive this user has access to into the current working directory.stream_response=sdk.archive.stream_from_backup("/full/path/to/file.txt","1234567890")withopen("/path/to/my/file",'wb')asf:forchunkinstream_response.iter_content(chunk_size=128):ifchunk:f.write(chunk)# search file eventsfrompy42.sdk.queries.fileevents.file_event_queryimportFileEventQueryfrompy42.sdk.queries.fileevents.filtersimport*query=FileEventQuery.all(MD5.eq("e804d1eb229298b04522c5504b8131f0"))file_events=sdk.securitydata.search_file_events(query)
额外资源
有关支持此SDK的Code42 web API的完整文档,以下是一些有用的资源:
- 项目
标签: