Welcome to Python-genomespaceclient’s documentation!

This is a python client for the GenomeSpace API. There’s a Python API (the genomespaceclient module), and a command-line script (genomespace).

Installation

Install the latest release from PyPi:

pip install python-genomespaceclient

Commandline usage example

# Create remote folder, including all intermediate paths
genomespace -u <username> -p <password> mkdir -p https://dm.genomespace.org/datamanager/v1.0/file/Home/MyBucket/f1/f2/

# copy local files recursively to remote location
genomespace -u <username> -p <password> cp -R /tmp/ https://dm.genomespace.org/datamanager/v1.0/file/Home/MyBucket/

# copy local files matching pattern to remote location - note that paths with wildcards must be enclosed in quotes
genomespace -u <username> -p <password> cp '/tmp/*.txt' https://dm.genomespace.org/datamanager/v1.0/file/Home/MyBucket/

# list remote files
genomespace -u <username> -p <password> ls https://dm.genomespace.org/datamanager/v1.0/file/Home/MyBucket/

# move remote file to new location
genomespace -u <username> -p <password> mv https://dm.genomespace.org/datamanager/v1.0/file/Home/MyBucket/hello.txt https://dm.genomespace.org/datamanager/v1.0/file/Home/MyBucket/world.txt

# download remote files matching pattern, with verbose output
genomespace -vvv -u <username> -p <password> mv https://dm.genomespace.org/datamanager/v1.0/file/Home/MyBucket/*.txt /tmp/

# delete remote file
genomespace -u <username> -p <password> rm https://dm.genomespace.org/datamanager/v1.0/file/Home/MyBucket/world.txt

Python usage example

from genomespaceclient import GenomeSpaceClient

client = GenomeSpaceClient(username="<username>", password="<password>")
client.mkdir("https://dm.genomespace.org/datamanager/v1.0/file/Home/MyBucket/f1/f2". create_path=True)
client.copy("/tmp/", "https://dm.genomespace.org/datamanager/v1.0/file/Home/MyBucket/", recurse=True)
client.list("https://dm.genomespace.org/datamanager/v1.0/file/Home/MyBucket/")
client.move("https://dm.genomespace.org/datamanager/v1.0/file/Home/MyBucket/hello.txt", "https://dm.genomespace.org/datamanager/v1.0/file/Home/MyBucket/world.txt")
client.copy("https://dm.genomespace.org/datamanager/v1.0/file/Home/MyBucket/*.txt", "/tmp/")
client.delete("https://dm.genomespace.org/datamanager/v1.0/file/Home/MyBucket/*.txt")

Notes

Wildcard copying syntax is the same as unix path globbing, except that the ‘?’ symbol is not supported (This is because the ‘?’ is a reserved character in a URL)

Documentation

API reference

This section contains the API documentation for the GenomeSpace client.

genomespaceclient package
genomespaceclient module
class genomespaceclient.client.GSAceObject(permission, sid, ace_id=None)[source]

Bases: object

See: http://www.genomespace.org/support/api/restful-access-to-dm#ace

__init__(permission, sid, ace_id=None)[source]

Initialize self. See help(type(self)) for accurate signature.

class genomespaceclient.client.GSAclObject(object_id, object_type)[source]

Bases: object

See: http://www.genomespace.org/support/api/restful-access-to-dm#acl

__init__(object_id, object_type)[source]

Initialize self. See help(type(self)) for accurate signature.

class genomespaceclient.client.GSDataFormat(name, url, file_extension, description)[source]

Bases: object

See: http://www.genomespace.org/support/api/restful-access-to-dm#appendix_c

__init__(name, url, file_extension, description)[source]

Initialize self. See help(type(self)) for accurate signature.

class genomespaceclient.client.GSDirectoryListing(contents, directory)[source]

Bases: object

See: http://www.genomespace.org/support/api/restful-access-to-dm#appendix_b

__init__(contents, directory)[source]

Initialize self. See help(type(self)) for accurate signature.

class genomespaceclient.client.GSEffectiveAcl(access_control_entries, effective_acl_object, effective_acl_id=None)[source]

Bases: object

See: http://www.genomespace.org/support/api/restful-access-to-dm#appendix_f

__init__(access_control_entries, effective_acl_object, effective_acl_id=None)[source]

Initialize self. See help(type(self)) for accurate signature.

class genomespaceclient.client.GSFileMetadata(name, path, url, parentUrl, size, owner, is_directory, is_link, target_path, last_modified, data_format, available_data_formats, effective_acl)[source]

Bases: object

See: http://www.genomespace.org/support/api/restful-access-to-dm#appendix_a

__init__(name, path, url, parentUrl, size, owner, is_directory, is_link, target_path, last_modified, data_format, available_data_formats, effective_acl)[source]

Initialize self. See help(type(self)) for accurate signature.

class genomespaceclient.client.GSSidObject(name, sid_type, sid_id=None)[source]

Bases: object

See: http://www.genomespace.org/support/api/restful-access-to-dm#sid

__init__(name, sid_type, sid_id=None)[source]

Initialize self. See help(type(self)) for accurate signature.

class genomespaceclient.client.GenomeSpaceClient(username=None, password=None, token=None)[source]

Bases: object

A simple GenomeSpace client

__init__(username=None, password=None, token=None)[source]

Constructs a new GenomeSpace client. A username/password combination or a token must be supplied.

Parameters:
  • username (str) – GenomeSpace username
  • password (str) – GenomeSpace password
  • token (str) – A GenomeSpace auth token. If supplied, the token will be used instead of the username/password.
copy(source, destination, recurse=False)[source]

Copies a file to/from/within GenomeSpace.

E.g. .. code-block:: python

client.copy(“/tmp/local_file.txt”,
https://dm.genomespace.org/datamanager/v1.0/file/Home/MyBucket/hello.txt”)
Parameters:
  • source (str) – Local filename or GenomeSpace URL of source file.
  • destination (str) – Local filename or GenomeSpace URL of destination file.
delete(genomespace_url, recurse=False)[source]

Deletes a file within a GenomeSpace folder.

E.g. .. code-block:: python

Parameters:genomespace_url (str) – GenomeSpace URL of file to delete.
get_metadata(genomespace_url)[source]

Gets metadata information of a genomespace file/folder. See: http://www.genomespace.org/support/api/restful-access-to-dm#file_metadata

E.g.

client.get_metadata("https://dm.genomespace.org/datamanager/v1.0/file/Home/MyBucket/world.txt")
Parameters:genomespace_url (str) – GenomeSpace URL of file to delete.
Return type:dict
Returns:a JSON dict in the format documented here: http://www.genomespace.org/support/api/restful-access-to-dm#appendix_b
get_remaining_token_time(genomespace_url)[source]

Gets the time to live for the gs-token if you have one. If you don’t have one, will return 0, as the non existent token has no time left to live. See: http://www.genomespace.org/support/api/restful-access-to-identity-server#get_token_time

E.g.

client.get_remaining_token_time('https://genomespace.genome.edu.au/')
Parameters:genomespace_url (str) – GenomeSpace URL.
Return type:int
Returns:the time the token has left to live in milliseconds.
isdir(genomespace_url)[source]

Returns True if a given genomespace_url is a directory

Parameters:genomespace_url (str) – GenomeSpace URL of file to delete.
Return type:bool
Returns:True if the url is a directory. False otherwise.
list(genomespace_url)[source]

Returns a list of files within a GenomeSpace folder.

E.g. .. code-block:: python

Parameters:genomespace_url (str) – GenomeSpace URL of folder to list.
Return type:dict
Returns:a JSON dict in the format documented here: http://www.genomespace.org/support/api/restful-access-to-dm#appendix_b
mkdir(genomespace_url, create_path=True)[source]

Creates a folder at a given location.

E.g. .. code-block:: python

Parameters:
  • genomespace_url (str) – GenomeSpace URL of file to delete.
  • create_path (boolean) – Create intermediate directories as required.
move(source, destination)[source]

Moves a file within GenomeSpace.

E.g. .. code-block:: python

Parameters:
  • source – GenomeSpace URL of source file. Cannot be a local file.
  • destination – Local filename or GenomeSpace URL of destination file. If destination is a local file, the file will be copied to the destination and the source file deleted.

Page index