官方代码42 Python API客户端

py42的Python项目详细描述


py42,Python-SDK的官方代码

{1}$ codecov.ioversionsCode style: blackDocumentation Status

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}

配置

有一些默认设置会影响客户端的行为。在

NameDescriptionDefault
verify_ssl_certsControls whether the SDK verifies the server's certificate.
Possible values: ^{}, ^{}, or a path to a CA bundle to use.
^{}
proxiesDictionary mapping protocol or protocol and hostname to the URL of the proxy.
See the Requests library's documentation on proxies for more info.
^{}
debug.levelControls log level^{}
debug.loggerControls logger used^{} with ^{} sending to ^{}
items_per_pageControls 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的完整文档,以下是一些有用的资源:

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

推荐PyPI第三方库


热门话题
java为什么这个循环打印1020之间的所有值?我想让它打印出可以被5整除的值   java如何在JTable中集中单元格   java无法通过一个键从hashmap获取对象,该键具有相同的hashcode,并且两个键等于()   不兼容的类型?JAVA   将字符串开头与空格匹配时java replaceAll的正则表达式混淆结果   java为非java应用程序创建jar文件。类文件   java无法从另一个普通Http Servlet访问筛选器Servlet的会话属性   java Ejb,第二个方法中的错误回滚第一个方法   swing java操作侦听器在菜单上,而不是在菜单项上   分析文件时出错:分析文件时出错:无法在Java的XSSF中分析excel文件   java将实体注入到ViewScope Bean中   java如何关闭终端而不终止正在运行的jar文件进程   爪哇力下传   java不能隐式地将[T]强制转换为AT,其中[T]扩展为AT   java Spring项目在jsp页面中显示mysql表数据   java在创建新实例SQLITE时出错