pyUSIrest package¶
Submodules¶
pyUSIrest.auth module¶
Created on Thu May 24 15:46:37 2018
@author: Paolo Cozzi <cozzi@ibba.cnr.it>
-
class
pyUSIrest.auth.
Auth
(user=None, password=None, token=None)[source]¶ Bases:
object
Deal with EBI AAP tokens. Starts from a token object or by providing user credentials. It parse token and provide methods like checking expiration times.
-
expire
¶ when token expires
Type: datetime.datetime
-
issued
¶ when token was requested
Type: datetime.datetime
-
header
¶ token header read by python_jwt.process_jwt
Type: dict
-
claims
¶ token claims read by python_jwt.process_jwt
Type: dict
-
__init__
(user=None, password=None, token=None)[source]¶ Instantiate a new python EBI AAP Object. You can generate a new object providing both user and password, or by passing a valid token string
Parameters:
-
auth_url
= None
-
get_domains
()[source]¶ Returns a list of domain managed by this object
Returns: a list of managed domains Return type: list
-
get_duration
()[source]¶ Get token remaining time before expiration
Returns: remaining time as timedelta
objectReturn type: datetime.timedelta
-
is_expired
()[source]¶ Return True if token is exipired, False otherwise
Returns: True if token is exipired Return type: bool
-
token
¶ Get/Set token as a string
-
pyUSIrest.client module¶
Created on Thu Dec 19 16:28:46 2019
@author: Paolo Cozzi <paolo.cozzi@ibba.cnr.it>
-
class
pyUSIrest.client.
Client
(auth)[source]¶ Bases:
object
A class to deal with EBI submission API. It perform request modelling user token in request headers. You need to call this class after instantiating an
Auth
object:import getpass from pyUSIrest.auth import Auth from pyUSIrest.client import Client auth = Auth(user=<you_aap_user>, password=getpass.getpass()) client = Client(auth) response = client.get("https://submission-test.ebi.ac.uk/api/")
-
last_response
¶ last response object read by this class
Type: requests.Response
-
session
¶ a session object
Type: request.Session
-
auth
Get/Set
Auth
object
-
check_headers
(headers=None)[source]¶ Checking headers and token
Parameters: headers (dict) – custom header for request Returns: an update headers tocken Return type: headers (dict)
-
check_status
(response, expected_status=200)[source]¶ Check response status. See HTTP status codes
Parameters: - response (requests.Reponse) – the reponse returned by requests
- method –
-
delete
(url, headers={}, params={})[source]¶ Generic DELETE method
Parameters: Returns: a response object
Return type:
-
get
(url, headers={}, params={})[source]¶ Generic GET method
Parameters: Returns: a response object
Return type:
-
headers
= {'Accept': 'application/hal+json', 'User-Agent': 'pyUSIrest 0.3.1'}
-
patch
(url, payload={}, headers={}, params={})[source]¶ Generic PATCH method
Parameters: Returns: a response object
Return type:
-
-
class
pyUSIrest.client.
Document
(auth=None, data=None)[source]¶ Bases:
pyUSIrest.client.Client
Base class for pyUSIrest classes. It models common methods and attributes by calling
Client
and reading json response from biosample API-
data
¶ data from USI read with
response.json()
Type: dict
-
__init__
(auth=None, data=None)[source]¶ Instantiate the class
Parameters: auth (Auth) – a valid Auth
object
-
classmethod
clean_url
(url)[source]¶ Remove stuff like
{?projection}
from urlParameters: url (str) – a string url Returns: the cleaned url Return type: str
-
follow_self_url
()[source]¶ Follow self url and update class attributes. For instance:
document.follow_self_url()
will reload document instance by requesting with
Client.get()
usingdocument.data['_links']['self']['href']
as url
-
follow_tag
(tag, force_keys=True)[source]¶ Pick a url from data attribute relying on tag, perform a request and returns a document object. For instance:
document.follow_tag('userSubmissions')
will return a document instance by requesting with
Client.get()
usingdocument._links['userSubmissions']['href']
as urlParameters: Returns: a document object
Return type:
-
get
(url, force_keys=True)[source]¶ Override the Client.get method and read data into object:
document = Document(auth) document.get(settings.ROOT_URL + "/api/")
Parameters: Returns: a response object
Return type:
-
paginate
()[source]¶ Follow all the pages. Return an iterator of document objects
Parameters: response (requests.Response) – a response object Yields: Document – a new Document instance
-
read_data
(data, force_keys=False)[source]¶ Read data from a dictionary object and set class attributes
Parameters: - data (dict) – a data dictionary object read with
response.json()
- force_keys (bool) – If True, define a new class attribute from data keys
- data (dict) – a data dictionary object read with
-
pyUSIrest.exceptions module¶
Created on Fri Jan 10 16:44:49 2020
@author: Paolo Cozzi <paolo.cozzi@ibba.cnr.it>
-
exception
pyUSIrest.exceptions.
NotReadyError
[source]¶ Bases:
RuntimeError
Raised when doing stuff on not ready data (ex finalizing a Submission after validation)
-
exception
pyUSIrest.exceptions.
TokenExpiredError
[source]¶ Bases:
RuntimeError
Raised when token expires while using pyUSIrest
-
exception
pyUSIrest.exceptions.
USIConnectionError
[source]¶ Bases:
ConnectionError
Deal with connection issues with API
pyUSIrest.settings module¶
Created on Mon Nov 18 11:47:42 2019
@author: Paolo Cozzi <paolo.cozzi@ibba.cnr.it>
pyUSIrest.usi module¶
Created on Thu May 24 16:41:31 2018
@author: Paolo Cozzi <cozzi@ibba.cnr.it>
-
class
pyUSIrest.usi.
Domain
(auth, data=None)[source]¶ Bases:
pyUSIrest.client.Document
A class to deal with AAP domain objects
-
data
¶ data (dict): data from AAP read with
response.json()
Type: dict
-
create_profile
(attributes={})[source]¶ Create a profile for this domain
Parameters: attributes (dict) – a dictionary of attributes
-
users
¶ Get users belonging to this domain
-
-
class
pyUSIrest.usi.
Root
(auth)[source]¶ Bases:
pyUSIrest.client.Document
Models the USI API Root endpoint
-
api_root
= None
-
get_submission_by_name
(submission_name)[source]¶ Got a specific submission object by providing its name
Parameters: submission_name (str) – input submission name Returns: The desidered submission as instance Return type: Submission
-
get_team_by_name
(team_name)[source]¶ Get a
Team
object by nameParameters: team_name (str) – the name of the team Returns: a team object Return type: Team
-
get_user_submissions
(status=None, team=None)[source]¶ Follow the userSubmission url and returns all submission owned by the user
Parameters: Returns: A list of
Submission
objectsReturn type:
-
-
class
pyUSIrest.usi.
Sample
(auth, data=None)[source]¶ Bases:
pyUSIrest.usi.TeamMixin
,pyUSIrest.client.Document
A class to deal with USI Samples
-
get_validation_result
()[source]¶ Return validation results for submission
Returns: the ValidationResult
of this sampleReturn type: ValidationResult
-
has_errors
(ignorelist=[])[source]¶ Return True if validation results throw an error
Parameters: ignorelist (list) – ignore errors in these databanks Returns: True if sample has an errors in one or more databank Return type: bool
-
patch
(sample_data)[source]¶ Update sample by patching data with
Client.patch()
Parameters: sample_data (dict) – sample data to update
-
read_data
(data, force_keys=False)[source]¶ Read data from a dictionary object and set class attributes
Parameters: - data (dict) – a data dictionary object read with
response.json()
- force_keys (bool) – If True, define a new class attribute from data keys
- data (dict) – a data dictionary object read with
-
-
class
pyUSIrest.usi.
Submission
(auth, data=None)[source]¶ Bases:
pyUSIrest.usi.TeamMixin
,pyUSIrest.client.Document
A class to deal with USI Submissions
-
check_ready
()[source]¶ Test if a submission can be submitted or not (Must have completed validation processes)
Returns: True if ready for submission Return type: bool
-
create_sample
(sample_data)[source]¶ Create a sample from a dictionary
Parameters: sample_data (dict) – a dictionary of data Returns: a Sample
objectReturn type: Sample
-
finalize
(ignorelist=[])[source]¶ Finalize a submission to insert data into biosample
Parameters: ignorelist (list) – ignore samples with errors in these databanks Returns: output of finalize submission as a Document
objectReturn type: Document
-
get_samples
(status=None, has_errors=None, ignorelist=[])[source]¶ Returning all samples as a list. Can filter by errors and error types:
# returning samples with errors in other checks than Ena submission.get_samples(has_errors=True, ignorelist=['Ena']) # returning samples which validation is still in progress submission.get_samples(status='Pending')
Get all sample with errors in other fields than Ena databank
Parameters: Yields: Sample – a
Sample
object
-
get_status
()[source]¶ Count validation statues for submission
Returns: A counter object for different validation status Return type: collections.Counter
-
get_validation_results
()[source]¶ Return validation results for submission
Yields: ValidationResult – a ValidationResult
object
-
has_errors
(ignorelist=[])[source]¶ Count sample errors for a submission
Parameters: ignorelist (list) – ignore samples with errors in these databanks Returns: A counter object for samples with errors and with no errors Return type: collections.Counter
-
read_data
(data, force_keys=False)[source]¶ Read data from a dictionary object and set class attributes
Parameters: - data (dict) – a data dictionary object read with
response.json()
- force_keys (bool) – If True, define a new class attribute from data keys
- data (dict) – a data dictionary object read with
-
status
¶ Return
submissionStatus
attribute. FollowsubmissionStatus
link and update attribute is such attribute is NoneReturns: submission status as a string Return type: str
-
update_status
()[source]¶ Update
submissionStatus
attribute by followingsubmissionStatus
link
-
-
class
pyUSIrest.usi.
Team
(auth, data=None)[source]¶ Bases:
pyUSIrest.client.Document
A class to deal with USI Team objects
-
data
¶ data (dict): data from USI read with
response.json()
Type: dict
-
create_submission
()[source]¶ Create a new submission
Returns: the new submission as an instance Return type: Submission
-
get_submissions
(status=None)[source]¶ Follows submission url and get submissions from this team
Parameters: status (str) – filter submission using status Returns: A list of Submission
objectsReturn type: list
-
-
class
pyUSIrest.usi.
User
(auth, data=None)[source]¶ Bases:
pyUSIrest.client.Document
Deal with EBI AAP endpoint to get user information
-
data
¶ data (dict): data from AAP read with
response.json()
Type: dict
-
add_user_to_team
(user_id, domain_id)[source]¶ Add a user to a team
Parameters: Returns: the updated
Domain
objectReturn type:
-
create_team
(description, centreName)[source]¶ Create a new team
Parameters: Returns: the new team as a
Team
instanceReturn type:
-
classmethod
create_user
(user, password, confirmPwd, email, full_name, organisation)[source]¶ Create another user into biosample AAP and return its ID
Parameters: Returns: the new user_id as a string
Return type:
-
get_domain_by_name
(domain_name)[source]¶ Get a domain by name
Parameters: domain_name (str) – the required team Returns: the desidered Domain
instanceReturn type: Domain
-
get_domains
()[source]¶ Get domains belonging to this instance
Returns: a list of Domain
objectsReturn type: list
-
get_my_id
()[source]¶ Get user id using own credentials, and set userReference attribute
Returns: the user AAP reference as a string Return type: str
-
get_team_by_name
(team_name)[source]¶ Get a team by name
Parameters: team_name (str) – the required team Returns: the desidered Team
instanceReturn type: Team
-
get_teams
()[source]¶ Get teams belonging to this instance
Returns: a list of Team
objectsReturn type: list
-
get_user_by_id
(user_id)[source]¶ Get a
User
object by user_idParameters: user_id (str) – the required user_id Returns: a user object Return type: User
-
user_url
= None¶
-
-
class
pyUSIrest.usi.
ValidationResult
(auth, data=None)[source]¶ Bases:
pyUSIrest.client.Document
Module contents¶
Top-level package for Python EBI submission REST API.