The mangal class¶
The mangal
class is where most of the action happens. Almost all user
actions consist in calling various methods of this class.
Documentation¶
-
class
pymangal.
mangal
(url='http://mangal.io', suffix='/api/v1/', usr=None, key=None)[source]¶ Creates an object of class
mangal
This is the main class used by
pymangal
. When called, it will return an object with all methods and attributes required to interact with the database.Parameters: - url – The URL of the site with the API (default:
http://mangal.io
) - suffix – The suffix of the API (default:
/api/v1/
) - usr – Your username on the server (default:
None
) - key – Your API key on the server (default:
None
)
Returns: An object of class
mangal
-
Get
(resource='dataset', key='1')[source]¶ Get an object identified by its key (id)
Parameters: - resource – The type of object to get
- key – The unique identifier of the object
Returns: A
dict
representation of the resource
-
List
(resource='dataset', filters=None, page=10, offset=0)[source]¶ Lists all objects of a given resource type, according to a filter
Parameters: - resource – The type of resource (default:
dataset
) - filters – A string giving the filtering criteria (default:
None
) - page – Either an integer giving the number of results to return, or
'all'
(default:10
) - offset – Number of initial results to discard (default:
0
)
Returns: A
dict
with keysmeta
andobjects
Note
The
objects
key of the returned dictionary is alist
ofdict
, each being a record in the database. Themeta
key contains thenext
andprevious
urls, and thetotal_count
number of objects for the request.- resource – The type of resource (default:
-
Patch
(resource='taxa', data=None)[source]¶ Patch a resource in the database
Parameters: - resource – The type of object to patch
- data – The dict representation of the object
The value of the
owner
field will be preserved, i.e. the owner of the object is not changed when patching the data object. This is important for users to find back the objects they uploaded even though they have been curated.This method converts the fields values to URIs automatically.
If the request is successful, this method will return the newly created object. If not, it will print the reply from the server and fail.
-
Post
(resource='taxa', data=None)[source]¶ Post a resource to the database
Parameters: - resource – The type of object to post
- data – The dict representation of the object
The
data
may or may not contain anowner
key. If so, it must be the URI of the owner object. If noowner
key is present, the value used will beself.owner
.This method converts the fields values to URIs automatically
If the request is successful, this method will return the newly created object. If not, it will print the reply from the server and fail.
- url – The URL of the site with the API (default: