Skip to main content

The Official CrashPlan Python API Client

Project description

CrashPlan fork of py42, this will become the official CrashPlan Python SDK

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

pycpg is a Python wrapper around the CrashPlan REST APIs that also provides several other useful utility methods. It is designed to be used for developing your own tools for working with CrashPlan data while avoiding the overhead of session / authentication management.

Requirements

  • Python 3.6.0+
  • CrashPlan Cloud environment (e.g. console.us1.crashplan.com or console.us2.crashplan.com)

Installation

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

$ python setup.py install

Hello, pycpg

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

Launch the Python interpreter

$ python

Import a couple essentials

>>> import pycpg.sdk
>>> import pycpg.util as util

Initialize the client.

>>> sdk = pycpg.sdk.from_local_account("https://console.us1.crashplan.com", "john.doe", "password")

or alternatively

>>> sdk = pycpg.sdk.from_jwt_provider("https://console.us1.crashplan.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 pycpg.settings and override values as necessary before creating the client. For example, to disable certificate validation in a dev environment:

import pycpg.sdk
import pycpg.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 = pycpg.sdk.from_local_account("https://console.us1.crashplan.com", "my_username", "my_password")

Usage

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

import pycpg.sdk

sdk = pycpg.sdk.from_local_account("https://console.us1.crashplan.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 -- deprecated, to be replaced with another example
from pycpg.sdk.queries.fileevents.file_event_query import FileEventQuery
from pycpg.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 CrashPlan 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

pycpg-1.0.0.tar.gz (66.3 kB view details)

Uploaded Source

Built Distribution

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

pycpg-1.0.0-py3-none-any.whl (59.7 kB view details)

Uploaded Python 3

File details

Details for the file pycpg-1.0.0.tar.gz.

File metadata

  • Download URL: pycpg-1.0.0.tar.gz
  • Upload date:
  • Size: 66.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for pycpg-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e3d5f40d41e65aae5284e19554858b79887feb5507f93f89ac6b98f2d51286de
MD5 64d8c27ae53776dbf21a48f18bf117c4
BLAKE2b-256 6e7ca9a11e458406eb355ea414e74d1dce50320080300fe1b718401444ee37e3

See more details on using hashes here.

File details

Details for the file pycpg-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pycpg-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 59.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.11

File hashes

Hashes for pycpg-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 030760e83c444883ca02d0084e268fdc89acdc03072ab65463ab2599a0de3314
MD5 f86002c3755549a335d30eeefce32b3c
BLAKE2b-256 8a94d9478bed0b0dc3a0d3fe6d12c4a9a763908ee1998c81acb2c72ec8bdd2e9

See more details on using hashes here.

Supported by

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