Skip to content
54 changes: 54 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,60 @@ Example usage (refer to docs for more):
print(file_content)
```

## Experimental support for data-proxy

Original implementation from Bjorn Kindler & Jan Fousek.

Example Usage:

### Access collab bucket

```python
from ebrains_drive import BucketApiClient
client = BucketApiClient(token="ey...")

# access existing bucket
bucket = client.buckets.get_bucket("existing_collab_name")

# or create a new collab + bucket
bucket = client.create_new("new_collab_name")

# upload new file
bucket.upload("/home/jovyan/test.txt", "test/foobar.txt")

# it seems newly uplaoded file will **NOT** be available immediately. Sleep for x seconds?
from time import sleep
sleep(1)

# list the contents
files = [f for f in bucket.ls(prefix="test")]

# get the uploaded file
file_handle = bucket.get_file("foobar.txt")
file_content = file_handle.get_content()

# delete a bucket (n.b. this will **NOT** delete the collab!)
client.delete_bucket("new_bucket_name")
```

### Access datasets (e.g. HDG datasets)

```python
from ebrains_drive import BucketApiClient
client = BucketApiClient(token="ey...")

# access dataset bucket
# setting requeste_access = True will start the relevant access-request-flow when accessing HDG datasets
bucket = client.buckets.get_dataset("existing_dataset_id", request_access=True)

# list the contents
files = [f for f in bucket.ls(prefix="path/to/somewhere/foo")]

# get a file content
file_handle = bucket.get_file("path/to/somewhere/foobar.txt")
file_content = file_handle.get_content()

```

<div><img src="https://raw.githubusercontent.com/HumanBrainProject/ebrains-drive/master/eu_logo.jpg" alt="EU Logo" width="15%" align="right"></div>

Expand Down
269 changes: 267 additions & 2 deletions doc.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Python Seafile
# Ebrains Drive
<p><div class="doc">
<ul>
<li><a href="#sea_file">Drive (Seafile)</a></li>
<ul>
<li><a href="#get_client">Get Client</a></li>
<li>
<a href="#repo"> Library </a>
Expand Down Expand Up @@ -33,10 +35,33 @@
</ul>
</li>
</ul>

<li><a href="#bucket">DataProxy</a></li>
<ul>
<li><a href="#bucket_get_client">Get Client</a></li>
<li><a href="#bucket_bucket">Bucket</li>
<ul>
<li><a href="#bucket_bucket_get">Get Bucket</a></li>
<li><a href="#bucket_bucket_create">Create Bucket</a></li>
<li><a href="#bucket_bucket_ls">List Bucket Entries</a></li>
</ul>
<li><a href="#bucket_dataset">Dataset</a></li>
<ul>
<li><a href="#bucket_dataset_get">Get Dataset</a></li>
</ul>
<li><a href="#bucket_file">File</a></li>
<ul>
<li><a href="#bucket_file_get">Get File</a></li>
<li><a href="#bucket_file_get_content">Get Content</a></li>
<li><a href="#bucket_file_upload">Upload File</a></li>
<li><a href="#bucket_file_delete">Delete File</a></li>
</ul>
</ul>
</ul>
</div>
</p>

# Python Seafile
# <a id="sea_file"></a> Drive (Seafile)


## <a id="get_client"></a> Get Client ##
Expand Down Expand Up @@ -459,3 +484,243 @@ None
**Return Type**

A Response Instance



# <a id="bucket"></a> Bucket

## <a id ="bucket_get_client"></a> Get Client
**Request Parameters**

* token

**Sample Case**

```python
from ebrains_drive import BucketApiClient
client = BucketApiClient(token="ey...")
```


**Return Type**

A Client Object

## <a id="bucket_bucket"></a> Bucket ##
### <a id="bucket_bucket_get"></a> Get Bucket ###
**Request Parameters**

* existing_collab_name

**Sample Case**

```python

from ebrains_drive import BucketApiClient
client = BucketApiClient(token="ey...")
bucket = client.buckets.get_bucket("existing_collab_name")
```

**Return Type**

A Bucket Object

**Exceptions**

* Bucket does not exist or not authorized to use the specified bucket

### <a id="bucket_bucket_create"></a> Create Bucket ###
**Request Parameters**

* new_collab_name

**Sample Case**

```python

from ebrains_drive import BucketApiClient
client = BucketApiClient(token="ey...")
bucket = client.create_new("new_collab_name")
```

**Return Type**

A Bucket Object

**Exceptions**

* Unauthorized to create new collab or bucket

### <a id="bucket_bucket_ls"></a> List Bucket Entries ###
**Request Parameters**

* prefix (optional)

**Sample Case**

```python

from ebrains_drive import BucketApiClient
client = BucketApiClient(token="ey...")
bucket = client.buckets.get_bucket("existing_collab_name")

# shows all files
all_files = [f for f in bucket.ls()]

# shows all files that begins with path/to/my/files
my_files = [f for f in bucket.ls(prefix="path/to/my/files")]
```

**Return Type**

An Iterator of File Objects

**Exceptions**

* Unauthorized

## <a id="bucket_dataset"></a> Dataset ##
### <a id="bucket_dataset_get"></a> Get Dataset ###

Note, if _request_access_ is set to `True`, this method may require user interaction.

**Request Parameters**

* dataset_id
* request_access (optional, default `False`)

**Sample Case**

```python

from ebrains_drive import BucketApiClient
client = BucketApiClient(token="ey...")
bucket = client.buckets.get_dataset("dataset_id")

```

**Return Type**
A Bucket Object

**Exceptions**

* Unauthorized (if _request_access_ is not set)

## <a id="bucket_file"></a> File ##

Files in buckets are not typically organised in directories. Users may use the `/` in filename to construct a directory-like structure.


### <a id="bucket_file_get"></a> Get File ###
**Request Parameters**

* filename

**Sample Case**

```python

from ebrains_drive import BucketApiClient
client = BucketApiClient(token="ey...")

bucket = client.buckets.get_bucket("existing_collab_name")
# OR
bucket = client.buckets.get_dataset("dataset_id")

file_handle = bucket.get_file("filename")

```

**Return Type**

A File Object

**Exceptions**

* Unauthorized
* DoesNotExist

### <a id="bucket_file_get_content"></a> Get File Content ###
**Request Parameters**

* filename

**Sample Case**

```python

from ebrains_drive import BucketApiClient
client = BucketApiClient(token="ey...")

bucket = client.buckets.get_bucket("existing_collab_name")
# OR
bucket = client.buckets.get_dataset("dataset_id")

file_handle = bucket.get_file("filename")
file_content = file_handle.get_content()

```

**Return Type**

bytes

**Exceptions**

* Unauthorized
* DoesNotExist


### <a id="bucket_file_upload"></a> Upload File ###
**Request Parameters**

* path_to_file
* dest_filename

**Sample Case**

```python

from ebrains_drive import BucketApiClient
client = BucketApiClient(token="ey...")
bucket = client.buckets.get_bucket("existing_collab_name")

bucket.upload("path_to_file", "dest_filename")

```

**Return Type**

None

**Exceptions**

* Unauthorized

### <a id="bucket_file_delete"></a> Delete File ###
**Request Parameters**

* filename

**Sample Case**

```python

from ebrains_drive import BucketApiClient
client = BucketApiClient(token="ey...")
bucket = client.buckets.get_bucket("existing_collab_name")

file_handle = bucket.get_file("filename")
file_handle.delete()

```

**Return Type**

None

**Exceptions**

* Unauthorized
* DoesNotExist
* AssertionError
2 changes: 1 addition & 1 deletion ebrains_drive/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

"""

from ebrains_drive.client import DriveApiClient
from ebrains_drive.client import DriveApiClient, BucketApiClient

def connect(username=None, password=None, token=None, env=""):
client = DriveApiClient(username, password, token, env)
Expand Down
Loading