Buckets and Files — Renga 0.1.0.dev20170915 documentation

Join us on GitHub

# Buckets and Files

Manage buckets and files on the server.

class `renga.models.storage.` `BucketCollection`(client=None)

  Represent storage buckets on the server.

  Create representation of objects on the server.

  class `Meta`

    Information about individual buckets.

    `model`

      alias of `Bucket`

  `backends`

    Return a list of the enabled backends.

  `create`(name=None, backend='local', **kwargs)

    Create new `Bucket` instance.

  `list`()

    Return list if the collection is iterable.

## Bucket objects

class `renga.models.storage.` `Bucket`

  Represent a storage bucket.

  Create representation of object on the server.

  `backend`

    The backend of this bucket.

  `files`

    The `FileCollection` instance.

  `id`

    The identifier of the object.

  `name`

    The bucket name.

## Files

Manage files in the bucket.

class `renga.models.storage.` `FileCollection`(bucket, **kwargs)

  Represent files in a bucket on the server.

  Initialize collection of files in the bucket.

  class `Meta`

    Information about individual files.

    `model`

      alias of `File`

  `create`(file_name=None)

    Create an empty file in this bucket.

  `from_url`(url, file_name=None)

    Create a file with data from the streamed GET response.

    Example

        >>> file_ = client.buckets[1234].files.from_url(
        ...     'https://example.com/tests/data', file_name='hello')
        >>> file_.open('r').read()
        b'hello world'

  `list`()

    Return list if the collection is iterable.

  `open`(file_name=None, mode='w')

    Create an empty file in this bucket.

## File objects

class `renga.models.storage.` `File`

  Represent a file object.

  Create representation of object on the server.

  `access_token`

    The access token for performing file operations.

  `filename`

    Filename of the file.

  `id`

    The identifier of the object.

  `open`(mode='r')

    Return the `FileHandle` instance.

## File handle objects

class `renga.models.storage.` `FileHandle`

  An object exposing a pythonic file-oriented API.

  Depending on the bucket to which it belongs to, a file object can mediate access to different storage backends (local, Swift, etc).

  Create representation of object on the server.

  `can_read`

    Check if the file handle is readable.

  `can_write`

    Check if the file handle is writable.

  `from_url`(url)

    Write data from the streamed GET response from the given URL.

    Example

        >>> with client.buckets[1234].files[1234].open('w') as fp:
        ...     fp.from_url('https://example.com/tests/data')

  `id`

    The identifier of the object.

  `read`(*args, **kwargs)

    Read data from the file.

  `write`(data)

    Write data to the file.