Getting started with py42


This project uses the MIT License.


You can install py42 from PyPI, from source, or from distribution.

From PyPI

The easiest and most common way is to use pip:

pip install py42

To install a previous version of py42 via pip, add the version number. For example, to install version 0.4.1, you would enter:

pip install py42==0.4.1

Visit the project history on PyPI to see all published versions.

From source

Alternatively, you can install py42 directly from source code:

git clone

When it finishes downloading, from the root project directory, run:

python install

From distribution

If you want create a .tar ball for installing elsewhere, run this command from the project’s root directory:

python sdist

After it finishes building, the .tar ball will be located in the newly created dist directory. To install it, enter:

pip install py42-[VERSION].tar.gz



py42 currently only supports token-based authentication.

To initialize the py42.sdk.SDKClient, you must provide your credentials. If you are writing a script, we recommend using a secure password storage library, such as keyring, for retrieving passwords and secrets. However, subsequent requests use JWT authentication.

Basic Authentication

Py42 supports basic auth with your Code42 username and password.

If your account uses two-factor authentication, include the time-based one-time password (TOTP) when you initialize the py42.sdk.SDKClient. You can also provide a callable object that returns a TOTP. If you pass a callable, it will be called whenever a new TOTP is required to renew the authentication token.

import py42.sdk

sdk = py42.sdk.from_local_account("", "", "password")

Code42 API Clients

Py42 also supports api clients. You can use the client ID and secret generated through the Code42 console to initiate the SDKClient.

import py42.sdk

sdk = py42.sdk.from_api_client("", "key-123-42", "my%secret!")

Troubleshooting and support

Debug mode

Debug mode may be useful if you are trying to determine if you are experiencing permissions issues. When debug mode is on, py42 logs HTTP request data to the console’s stderr. Use the following as a guide for how to turn on debug mode in py42:

import py42.sdk
import py42.settings
import logging

py42.settings.debug.level = logging.DEBUG

To provide your own logger, just replace py42.settings.debug.logger:

custom_logger = logging.getLogger("my_app")
handler = logging.FileHandler("my_app.log")

py42.settings.debug.logger = custom_logger

File an issue on GitHub

If you are experiencing an issue with py42, you can create a New issue at the project repository. See the Github guide on creating an issue for more information.

Contact Code42 Support

If you don’t have a GitHub account and are experiencing issues, contact Code42 support.

What’s next?

Learn the basics by following the py42 Basics guide.