storj

Installation

This section covers the Storj installation.

pip

$ pip install storj

source

The code is available at github.

There are several alternatives for this installation method.

Here we only describe two possibilities:

  • you can clone the repository:
$ git clone git@github.com:Storj/storj-python-sdk.git

For example:

$ curl -OL https://github.com/Storj/storj-python-sdk/archive/1.0.0.tar.gz

Once you have a copy of the source and have extracted its files, you can install it using:

$ python setup.py install

command-line

To install the command-line tool do:

$ pip install storj[cli]

API documentation

This section contains information on a specific function, class, or method.

storj package

Subpackages

storj.cli package

Module contents

Storj command-line interface package.

Submodules

storj.api module

Storj API module.

ecdsa_to_hex(ecdsa_key)[source]

Return hexadecimal string representation of the ECDSA key.

Parameters:ecdsa_key (bytes) – ECDSA key.
Raises:TypeError – if the ECDSA key is not an array of bytes.
Returns:hexadecimal string representation of the ECDSA key.
Return type:str

storj.configuration module

APP_NAME = 'storj'

(str) – the application name.

CFG_EMAIL = 'email'

(str) – configuration parameter that holds the Storj account email address.

CFG_PASSWORD = 'password'

(str) – configuration parameter that holds the Storj account password.

read_config()[source]

Reads configuration storj client configuration.

Mac OS X (POSIX):
~/.foo-bar
Unix (POSIX):
~/.foo-bar
Win XP (not roaming):
C:\Documents and Settings\<user>\Application Data\storj
Win 7 (not roaming):
C:\Users\<user>\AppData\Local\storj
Returns:storj account credentials (email, password).
Return type:(tuple[str, str])

storj.exception module

Storj exception module.

exception StorjBridgeApiError[source]

Bases: exceptions.Exception

Generic Storj exception.

storj.http module

Storj HTTP module.

class Client(email, password)[source]

Bases: object

api_url

str – the Storj API endpoint.

session
email

str – user email address.

password

str – user password.

private_key
public_key
public_key_hex
authenticate(ecdsa_private_key=None)[source]
bucket_create(name, storage=None, transfer=None)[source]

Create storage bucket.

See API buckets: POST /buckets

Parameters:
  • name (str) – name.
  • storage (int) – storage limit (in GB).
  • transfer (int) – transfer limit (in GB).
Returns:

bucket.

Return type:

(model.Bucket)

bucket_delete(bucket_id)[source]

Destroy a storage bucket.

See API buckets: DELETE /buckets/{id}

Parameters:bucket_id (string) – unique identifier.
bucket_files(bucket_id)[source]

List all the file metadata stored in the bucket.

See API buckets: GET /buckets/{id}/files

Parameters:bucket_id (string) – unique identifier.
Returns:to be changed to model in the future.
Return type:(dict)
bucket_get(bucket_id)[source]

Return the bucket object.

See API buckets: GET /buckets

Parameters:bucket_id (str) – bucket unique identifier.
Returns:bucket.
Return type:(model.Bucket)
bucket_list()[source]

List all of the buckets belonging to the user.

See API buckets: GET /buckets

Returns:buckets.
Return type:(generator[model.Bucket])
bucket_set_keys(bucket_id, bucket_name, keys)[source]

Update the bucket with the given public keys.

See API buckets: PATCH /buckets/{bucket_id}

Parameters:
  • bucket_id (str) – bucket unique identifier.
  • bucket_name (str) – bucket name.
  • keys (list[str]) – public keys.
Returns:

updated bucket information.

Return type:

(storj.model.Bucket)

bucket_set_mirrors(bucket_id, file_id, redundancy)[source]

Establishes a series of mirrors for the given file.

See API buckets: POST /buckets/{id}/mirrors

Parameters:
  • bucket_id (str) – bucket unique identifier.
  • file_id (str) – file unique identitifer.
  • redundancy (int) – number of replicas.
Returns:

the mirror settings.

Return type:

(storj.model.Mirror)

contact_list(page=1, address=None, protocol=None, user_agent=None, connected=None)[source]

Lists contacts.

See API contacts: GET /contacts

Parameters:
  • page (str) – pagination indicator.
  • address (str) – hostname or IP address.
  • protocol (str) – SemVer protocol tag.
  • user_agent (str) – Storj user agent string for farming client.
  • connected (bool) – filter results by connection status.
Returns:

list of contacts.

Return type:

(list[storj.model.Contact])

contact_lookup(node_id)[source]

Lookup for contact information of a node.

See API contacts: GET /contacts/{nodeID}

Parameters:node_id (str) – node unique identifier.
Returns:contact information
Return type:(storj.model.Contact)
file_download(bucket_id, file_id)[source]
file_metadata(bucket_id, file_id)[source]

Get file metadata.

See API buckets: GET /buckets/{id}/files/{file_id}/info

Parameters:
  • bucket_id (str) – bucket unique identifier.
  • file_id (str) – file unique identifier.
Returns:

file metadata.

Return type:

(storj.model.File)

file_pointers(bucket_id, file_id, skip=None, limit=None)[source]

Get list of pointers associated with a file.

See API buckets: GET /buckets/{id}/files/{file_id}

Parameters:
  • bucket_id (str) – bucket unique identifier.
  • file_id (str) – file unique identifier.
  • skip (str) – pointer index to start the file slice.
  • limit (str) – number of pointers to resolve tokens for.
Returns:

file pointers.

Return type:

(generator[storj.model.FilePointer])

file_remove(bucket_id, file_id)[source]

Delete a file pointer from a specified bucket.

See API buckets: DELETE /buckets/{id}/files/{file_id}

Parameters:
  • bucket_id (str) – bucket unique identifier.
  • file_id (str) – file unique identifier.
file_upload(bucket_id, file, frame)[source]

Upload file.

See API buckets: POST /buckets/{id}/files

Parameters:
frame_add_shard(shard, frame_id)[source]

Adds a shard item to the staging frame and negotiates a storage contract.

See API frames: PUT /frames/{frame_id}

Parameters:
  • shard (storj.models.Shard) – the shard.
  • frame_id (str) – the frame unique identifier.
frame_create()[source]

Creates a file staging frame.

See API frames: POST /frames

Returns:the frame.
Return type:(storj.model.Frame)
frame_delete(frame_id)[source]

Destroys the file staging frame by it’s unique ID.

See API frames: DELETE /frames/{frame_id}

Parameters:frame_id (str) – unique identifier.
frame_get(frame_id)[source]

Fetches the file staging frame by it’s unique ID.

See API frame: GET /frames/{frame_id}

Parameters:frame_id (str) – unique identifier.
Returns:a frame.
Return type:(storj.model.Frame)
frame_list()[source]

Returns all open file staging frames.

See `API frame: GET /frames < https://storj.github.io/bridge/#!/frames/get_frames>`_

Returns:all open file staging frames.
Return type:(generator[storj.model.Frame])
key_delete(public_key)[source]

Removes a public ECDSA keys.

See API keys: DELETE /keys/{pubkey}

Parameters:public_key (str) – key to be removed.
key_dump()[source]
key_export()[source]
key_generate()[source]
key_import(private_keyfile_path, public_keyfile_path)[source]
key_list()[source]

Lists the public ECDSA keys associated with the user.

See API keys: GET /keys

Returns:public keys.
Return type:(list[str])
key_register(public_key)[source]

Register an ECDSA public key.

See API keys: POST /keys

Returns:public keys.
Return type:(list[storj.model.Key])
logger = <logging.Logger object>
password

(str) – user password

token_create(bucket_id, operation)[source]

Creates a token for the specified operation.

See API buckets: POST /buckets/{id}/tokens

Parameters:
  • bucket_id (str) – bucket unique identifier.
  • operation (str) – operation.
Returns:

...

Return type:

(dict)

user_activate(token)[source]

Activate user.

See API users: GET /activations/{token}

Parameters:token (str) – activation token.
user_activation_email(email, token)[source]

Send user activation email.

See API users: POST /activations/{token}

Parameters:
  • email (str) – user’s email address.
  • token (str) – activation token.
user_create(email, password)[source]

Create a new user with Storj bridge.

See API users: POST /users

Parameters:
  • email (str) – user’s email address.
  • password (str) – user’s password.
user_deactivate(token)[source]

Discard activation token.

See API users: GET /activations/{token}

Parameters:token (str) – activation token.
user_delete(email)[source]

Delete user account.

See API users: DELETE /users/{email}

Parameters:email (str) – user’s email address.
user_reset_password(email)[source]

Request a password reset.

See API users: PATCH /users/{email}

Parameters:email (str) – user’s email address.
user_reset_password_confirmation(token)[source]

Confirm a password reset request.

See API users: GET /resets/{token}

Parameters:token (str) – password reset token.

storj.metadata module

Storj metadata module.

storj.model module

Storj model module.

class Bucket(id=None, name=None, status=None, user=None, created=None, storage=None, transfer=None, pubkeys=None, publicPermissions=None, encryptionKey=None)[source]

Bases: steenzout.object.Object

Storage bucket.

A bucket is a logical grouping of files which the user can assign permissions and limits to.

id

str – unique identifier.

name

str – name.

status

str – bucket status (Active, ...).

user

str – user email address.

created

datetime.datetime – time when the bucket was created.

storage

int – storage limit (in GB).

transfer

int – transfer limit (in GB).

pubkeys
delete()[source]
class Contact(address=None, port=None, nodeID=None, lastSeen=None, protocol=None, userAgent=None)[source]

Bases: steenzout.object.Object

Contact.

address

str – hostname or IP address.

port

str – .

nodeID

str – node unique identifier.

lastSeen

str – .

protocol

str – SemVer protocol tag.

userAgent

str

lastSeen
class File(bucket=None, hash=None, mimetype=None, filename=None, size=None, id=None, frame=None)[source]

Bases: steenzout.object.Object

bucket

bucket unique identifier.

hash
mimetype
filename
frame

storj.model.Frame – file frame.

size
shard_manager
content_type
delete()[source]
download()[source]
name
class FilePointer(hash=None, token=None, operation=None, channel=None)[source]

Bases: steenzout.object.Object

File pointer.

Parameters:
  • hash (str) –
  • token (str) – token unique identifier.
  • operation (str) –
  • channel (str) –
hash

str

token

storj.model.Token – token.

operation

str

channel

str

class Frame(id=None, created=None, shards=None)[source]

Bases: steenzout.object.Object

File staging frame.

id

str – unique identifier.

created

datetime.datetime – time when the bucket was created.

shards

list[Shard] – shards that compose this frame.

class Keyring[source]

Bases: steenzout.object.Object

export_keyring(password, salt, user_pass)[source]
generate()[source]
import_keyring(filepath)[source]
class MerkleTree(leaves, prehashed=True)[source]

Bases: steenzout.object.Object

Simple merkle hash tree. Nodes are stored as strings in rows. Row 0 is the root node, row 1 is its children, row 2 is their children, etc

Arguments
leaves (list[str]/types.generator[str]):
leaves of the tree, as hex digests
leaves

list[str] – leaves of the tree, as hex digests

depth

int – the number of levels in the tree

count

int – the number of nodes in the tree

rows

list[list[str]] – the levels of the tree

depth

Calculates the depth of the tree.

Returns:tree depth.
Return type:(int)
get_level(depth)[source]

Returns the tree row at the specified depth

get_root()[source]

Return the root of the tree

leaves

(list[str]/types.generator[str]) – leaves of the tree.

class Mirror(hash=None, mirrors=None, status=None)[source]

Bases: steenzout.object.Object

Mirror or file replica settings.

hash

str

mirrors

int – number of file replicas.

status

str – current file replica status.

class Shard(id=None, hash=None, size=None, index=None, challenges=None, tree=None, exclude=None)[source]

Bases: steenzout.object.Object

Shard.

id

str – unique identifier.

hash

str – hash of the data.

size

long – size of the shard in bytes.

index

int – numberic index of the shard in the frame.

challenges

list[str] – list of challenge numbers

tree

list[str] – audit merkle tree

exclude

list[str] – list of farmer nodeIDs to exclude

add_challenge(challenge)[source]

Append challenge.

Parameters:challenge (str) –

.

add_tree(tree)[source]

Append tree.

all()[source]
get_private_record()[source]
get_public_record()[source]
class ShardManager(filepath, shard_size, nchallenges=12)[source]

Bases: steenzout.object.Object

File shard manager.

filepath

str – path to the file.

index

int – number of shards for the given file.

nchallenges

int – number of challenges to be generated.

shard_size

int/long – split file in chunks of this size.

shards

list[Shard] – list of shards

filepath

(str) – path to the file.

static hash(data)[source]

Returns ripemd160 of sha256 of a string as a string of hex.

Parameters:data (str) – content to be digested.
Returns:the ripemd160 of sha256 digest.
Return type:(str)
class Token(token=None, bucket=None, operation=None, expires=None, encryptionKey=None)[source]

Bases: steenzout.object.Object

Token.

Parameters:
  • token (str) – token unique identifier.
  • bucket (str) – bucket unique identifier.
  • () (operation) –
  • expires (str) – expiration date, in the RFC3339 format.
  • encryptionKey (str) –
id

str – token unique identifier.

bucket

storj.model.Bucket – bucket.

operation

str

expires

datetime.datetime – expiration date, in UTC.

encryptionKey

str

storj.web_socket module

Storj web socket module.

class Client(pointer, file_contents)[source]

Bases: ws4py.client.threadedclient.WebSocketClient

Web socket client.

json

generator[storj.model.FilePointer] – file pointers.

closed(code, reason=None)[source]
opened()[source]
received_message(m)[source]

Module contents

Storj package.

class BucketKeyManager(bucket, authorized_public_keys)[source]
bucket
add(key)[source]
all()[source]
clear()[source]
remove(key)[source]
class BucketManager[source]

Bases: abc.ABCMeta

Class to manage buckets.

static all()[source]
static create(name, storage_limit=None, transfer_limit=None)[source]

Create bucket.

Parameters:
  • name (str) –

    .

  • () (transfer_limit) –

    .

  • ()

    .

static delete(bucket_id)[source]

Remove bucket.

Parameters:bucket_id (int) – bucket unique identifier.
static get(bucket_id)[source]
class FileManager(bucket_id)[source]
all()[source]
delete(bucket_id, file_id)[source]
download(file_id)[source]
upload(file, frame)[source]
class TokenManager(bucket_id)[source]

Bucket token manager.

bucket_id

int – bucket unique identifier.

create(operation)[source]

Creates a token.

Parameters:operation (str) – operation (PUSH or PULL).
class UserKeyManager[source]

Bases: abc.ABCMeta

static add(key)[source]
static all()[source]
static clear()[source]
static remove(key)[source]
generate_new_key_pair()[source]

Generate a new key pair.

Returns:
tuple(ecdsa.keys.SigningKey,
ecdsa.keys.VerifyingKey):

key pair (private, public).

get_client()[source]

Returns a pre-configured Storj HTTP client.

Returns:Storj HTTP client.
Return type:(storj.http.Client)