Skip to main content

A Python SDK for the Storj API

Project description

BuildLink CoverageLink LicenseLink

A Python SDK for the Storj API.

Installation

pip install storj

Usage

Create a user account

import storj
storj.register_new_user(
    email='someone@email.com',
    password='a better password than this'
)
# Check email for confirmation link

Generate a key pair and start using it for authentication

import storj
(private_key, public_key) = storj.generate_new_key_pair()
storj.authenticate(
    email='someone@email.com',
    password='a better password than this'
)
storj.public_keys.add(public_key)
storj.authenticate(ecdsa_private_key=private_key)

Manage your public keys

import storj

# Get all registered public keys
key_list = storj.public_keys.all()

# Add a key
storj.public_keys.add(public_key)

# Remove one key
storj.public_keys.remove(public_key)

# Remove all keys
storj.public_keys.clear()

Manage your buckets

import storj

# Get all buckets
bucket_list = storj.buckets.all()

# Get a single bucket
existing_bucket = storj.buckets.get(id='56ef0d4656bf7b950faace7a')

# Create a new bucket
new_bucket = storj.buckets.create(name='my first bucket')
another_bucket = storj.buckets.create(
    name='another bucket', storage_limit=300, transfer_limit=100
)

# Delete a bucket
new_bucket.delete()

# Delete a bucket without fetching it
storj.buckets.delete(bucket_id='56ef0d4656bf7b950faace7a')

Get file metadata for files in a bucket

existing_bucket.files.all()

Create a PUSH or PULL token for a bucket

push_token = existing_bucket.tokens.create(operation='PUSH')

Upload a file

# Use a file path string
new_bucket.files.upload('/path/to/file.txt')

# Or a file handle
with open('/path/to/another/file.png') as file:
    another_bucket.files.upload(file)

Download a file

files = existing_bucket.files.all()
txt_file = files[0]
txt_file_contents = txt_file.download()

Delete a file

existing_file.delete()

Manage a bucket’s public keys

# Get all registered public keys
key_list = existing_bucket.authorized_public_keys.all()

# Add a key
existing_bucket.authorized_public_keys.add(public_key)

# Remove a key
existing_bucket.authorized_public_keys.remove(public_key)

# Remove all keys
existing_bucket.authorized_public_keys.clear()

Use your own Storj API service

import storj
storj.api_client.base_url = 'https://myserver.org'

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

storj-0.1.5.tar.gz (28.4 kB view hashes)

Uploaded Source

Supported by

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