Skip to main content

The Official Code42 Python API Client

Project description

py42, the official Code42 Python SDK

Build status codecov.io versions Code style: black Documentation Status

Py42 end-of-life

Py42 is now deprecated. It has been replaced by the Incydr SDK.

  • Py42 will reach end-of-support on January 1, 2026, and end-of-life on January 1, 2027.
  • To ensure uninterrupted functionality and access to the latest features, migrate your integrations to the Incydr SDK as soon as possible. For more details, see our FAQ.

py42 is 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.

Requirements

  • Python 3.6.0+
  • Code42 Server 6.8.x+ or cloud environment (e.g. console.us.code42.com or crashplan.com)

Installation

Run the setup.py script to install the py42 package and its dependencies on your system. You will likely need administrative privileges for this.

$ python setup.py install

Hello, py42

Here's a simple example to verify the installation and your server/account.

Launch the Python interpreter

$ python

Import a couple essentials

>>> import py42.sdk
>>> import py42.util as util

Initialize 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
}

Configuration

There are a few default settings that affect the behavior of the client.

Name Description Default
verify_ssl_certs Controls whether the SDK verifies the server's certificate.
Possible values: True, False, or a path to a CA bundle to use.
True
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.
None
debug.level Controls log level logging.NOTSET
debug.logger Controls logger used logging.Logger with StreamHandler sending to sys.stderr
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

To override these settings, import py42.settings and override values as necessary before creating the client. For example, to disable certificate validation in a dev environment:

import py42.sdk
import py42.settings as settings
import logging

settings.verify_ssl_certs = False

# customize logging
custom_logger = logging.getLogger("my_app")
handler = logging.FileHandler("my_app.log")
custom_logger.addHandler(handler)
settings.debug.logger = custom_logger
settings.debug.level = logging.DEBUG

sdk = py42.sdk.from_local_account("https://console.us.code42.com", "my_username", "my_password")

Usage

The SDK object opens availability to APIs across the Code42 environment, including storage nodes.

import py42.sdk

sdk = 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.
for device_page in sdk.devices.get_all():
    for device in device_page["computers"]:
        print(device)

# page through all orgs available to this user.
for org_page in sdk.orgs.get_all():
    for org in org_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")
with open("/path/to/my/file", 'wb') as f:
    for chunk in stream_response.iter_content(chunk_size=128):
        if chunk:
            f.write(chunk)

# search file events
from py42.sdk.queries.fileevents.file_event_query import FileEventQuery
from py42.sdk.queries.fileevents.filters import *

query = FileEventQuery.all(MD5.eq("e804d1eb229298b04522c5504b8131f0"))
file_events = sdk.securitydata.search_file_events(query)

Additional Resources

For complete documentation on the Code42 web API that backs this SDK, here are some helpful resources:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py42-1.29.1.tar.gz (112.5 kB view details)

Uploaded Source

Built Distribution

py42-1.29.1-py2.py3-none-any.whl (126.2 kB view details)

Uploaded Python 2Python 3

File details

Details for the file py42-1.29.1.tar.gz.

File metadata

  • Download URL: py42-1.29.1.tar.gz
  • Upload date:
  • Size: 112.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for py42-1.29.1.tar.gz
Algorithm Hash digest
SHA256 a9c95b0a85da6ea2a4daadc9b638ed89426b3c04d8280610f7d50f4f5fb91b3c
MD5 0d04793bb1bec0b34478a12261da0b64
BLAKE2b-256 c7b8193e0a4b06a07a91033cb553eeaec9f50a7fe1b3fa6099a94a90a43963c0

See more details on using hashes here.

File details

Details for the file py42-1.29.1-py2.py3-none-any.whl.

File metadata

  • Download URL: py42-1.29.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 126.2 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for py42-1.29.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 051bfbb85ebefbef02ded5d80cd69ed11d9a8ab72f981055a34b802f3061704c
MD5 781b24e136f6c88f7a50d40089ccd8a9
BLAKE2b-256 5bdff59d55dc25ecde6aeff7c6ca95e0121a224237276501d0538b65ba0d009b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page