Skip to main content

py42, the official Code42 Python SDK

Build status versions Code style: black

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 2.7.x or 3.5.0+
  • Code42 Server 6.8.x+

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

>>> from py42.sdk import SDK
>>> import py42.util as util

Initialize the client.

>>> sdk = SDK.create_using_local_account("https://console.us.code42.com", "john.doe", "password")

Get and print your user information.

>>> response = sdk.users.get_current_user()
>>> util.print_response(response)

You should see something like the following:

{
    "data": {
        "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
    },
    "metadata": {
        "timestamp": "2019-03-05T06:06:31.438-06:00",
        "params": {}
    }
}

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 print statements for debugging py42.debug_level.NONE
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. 1000

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.settings as settings
from py42.sdk import SDK

settings.verify_ssl_certs = False
sdk = SDK.create_using_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.

from py42.sdk import SDK

sdk = SDK.create_using_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_user() 

# get server diagnostic info.
diagnostics = sdk.administration.get_diagnostics()

# get a list of all devices available to this user.
devices = sdk.devices.get_devices()

# get a list of all orgs available to this user.
orgs = sdk.orgs.get_orgs()

# save a copy of a file from an archive this user has access to into the current working directory.
sdk.archive.download_from_backup("/full/path/to/file.txt", "1234567890")

# search file events
from py42.sdk.file_event_query import *
query = FileEventQuery.all(MD5.eq("e804d1eb229298b04522c5504b8131f0"))
file_events = sdk.security.search_file_events(query)

Additional Resources

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

Download files

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

Source Distribution

py42-0.5.1.tar.gz (31.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py42-0.5.1-py3-none-any.whl (43.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: py42-0.5.1.tar.gz
  • Upload date:
  • Size: 31.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for py42-0.5.1.tar.gz
Algorithm Hash digest
SHA256 951bfd50d520575d4e791bd902b14be51f319d5a0df89c60037c8acba959bfd0
MD5 17db7761891e1ac3ba68d12197890566
BLAKE2b-256 d665d7acb4d1e5275152509b32cededf71ae021812ed5b3e581d0f1674e5738c

See more details on using hashes here.

File details

Details for the file py42-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: py42-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 43.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for py42-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 7f0f4c61d15644ae1baf7c41b822fb57b7228157c0825a33dfd06dac6753a722
MD5 fb2a7fa2b9afdab697f6e741087f5c0f
BLAKE2b-256 d7fdd2739a8ca04450f12d9448a26db9c4386b017c57d2487b1a59c1d5528095

See more details on using hashes here.

Release history Release notifications | RSS feed

1.29.1

2 files

1.29.0

2 files

1.28.2

2 files

1.28.1

2 files

1.28.0

2 files

1.27.3

2 files

1.27.2

2 files

1.27.1

2 files

1.27.0

2 files

1.26.2

2 files

1.26.1

2 files

1.26.0

2 files

1.25.1

2 files

1.25.0

2 files

1.24.0

2 files

1.23.0

2 files

1.22.0

2 files

1.21.1

2 files

1.21.0

2 files

1.20.0

2 files

1.19.3

2 files

1.19.2

2 files

1.19.1

2 files

1.19.0

2 files

1.18.1

2 files

1.18.0

2 files

1.17.0

2 files

1.16.1

2 files

1.16.0

2 files

1.15.1

2 files

1.15.0

2 files

1.14.2

2 files

1.14.1

2 files

1.14.0

2 files

1.13.0

2 files

1.11.1

2 files

1.11.0

2 files

1.10.1

2 files

1.10.0

2 files

1.9.0

2 files

1.8.2

2 files

1.8.1

2 files

1.8.0

2 files

1.7.1

2 files

1.7.0

2 files

1.6.2

2 files

1.6.1

2 files

1.6.0

2 files

1.5.1

2 files

1.5.0

2 files

1.4.0

2 files

1.3.0

2 files

1.2.0

2 files

1.1.3

2 files

1.1.2

2 files

1.1.1

2 files

1.1.0

2 files

1.0.1

2 files

1.0.0

2 files

0.9.0

2 files

0.8.1

2 files

0.8.0

2 files

0.7.0

2 files

0.6.1

2 files

0.6.0

2 files

This release

0.5.1 This release

2 files

0.5.0

2 files

0.4.4

2 files

0.4.3

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page