Package: py42
py42, the official Code42 Python SDKpy42is a Python wrapper around the Code42 REST APIs that also provides several other useful utility methods.
It is designed to be used for developing your own tools for working with Code42 data while avoiding the overhead
of session / authentication management.RequirementsPython 3.6.0+Code42 Server 6.8.x+ or cloud environment (e.g. console.us.code42.com or crashplan.com)InstallationRun thesetup.pyscript to install the py42 package and its dependencies on your system.
You will likely need administrative privileges for this.$pythonsetup.pyinstallHello, py42Here's a simple example to verify the installation and your server/account.Launch the Python interpreter$pythonImport a couple essentials>>>importpy42.sdk>>>importpy42.utilasutilInitialize the client.>>>sdk=py42.sdk.from_local_account("https://console.us.code42.com","john.doe","password")or alternatively>>> sdk = py42.sdk.from_jwt_provider("https://console.us.code42.com", jwt_provider_function)Get and print your user information.>>>response=sdk.users.get_current()>>>util.print_response(response)You should see something like the following:{"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}ConfigurationThere are a few default settings that affect the behavior of the client.NameDescriptionDefaultverify_ssl_certsControls whether the SDK verifies the server's certificate.Possible values:True,False, or a path to a CA bundle to use.TrueproxiesDictionary mapping protocol or protocol and hostname to the URL of the proxy.Seethe Requests library's documentation on proxiesfor more info.Nonedebug.levelControls log levellogging.NOTSETdebug.loggerControls logger usedlogging.LoggerwithStreamHandlersending tosys.stderritems_per_pageControls how many items are retrieved per request for methods that loops over several "pages" of items in order to collect them all.500To override these settings, importpy42.settingsand override values as necessary before creating the client.
For example, to disable certificate validation in a dev environment: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")UsageThe SDK object opens availability to APIs across the Code42 environment, including storage nodes.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)Additional ResourcesFor complete documentation on the Code42 web API that backs this SDK, here are some helpful resources:Introduction to the Code42 APICode42 API documentation viewers