Package: pyelabdata
pyelabdatapyelabdata provides functions for simple one-line access to data stored
in eLabFTW via Python or Jupyter.ExamplesExamples for the use of pyelabdata can be found in the examples folder.Functionsdefconnect(host:str,apikey:str):Connects to the API interface of the eLabFTW server specified by the
parameterhost(e.g.https://yourserver.org/api/v2) using the givenapikey.defdisconnect():Disconnect from the eLabFTW server.deflist_experiments(searchstring:str='',tags=[]):Retrieve a list of ids of all experiments that containsearchstringin the title, body or elabid and that match the tags specified intags.
All parameters are optional. If nothing is specified, all accessible
experiments will be listed.defopen_experiment(expid:int,returndata:bool=False):Open an experiment in eLabFTW using the id of the experiment. IfreturndataisTrue, the function returns a dictionary with the metadata of the
experiment.
All subsequent commands will operate on the opened experiment.defclose_experiment():Close the current experiment.
Subsequent commands will not further operate on the experiment.defget_maintext(format:str='html',expid:int=None):Retrieve the body text of the experiment.All parameters are optional. Ifformatis'html', the content of
body_html is returned, i.e. the body text in html format. Otherwise
the content of body is returned, which depends on the format used in
eLabFTW (markdown or html).expidis an integer number which identifies the eLabFTW experiment;
if set to None, the currently opened experiment is used.defget_table_data(tableidx:int=0,header:bool=True,datatype:str='np',expid:int=None):In eLabFTW, tables can be defined in the body text of experiments.
The data of such tables can be retrieved by using this function.All parameters are optional.tableidxtells the function the
return the data of thenthtable, where counting starts withn= 0.
Ifheaderis true, the function assumes that the table contains
columns of data where the first element (row) is the column heading.datatypemay be either'df'or'np'(default). For'df', a pandas dataframe
representing the table data is returned, whereas for'np'a dictionary
of numpy arrays for each column is returned, in which the keys correspond
to the column heading (in case ofheader = True).expidis an integer number which identifies the eLabFTW experiment;
if set to None, the currently opened experiment is used.defget_file_csv_data(filename:str,header:bool=True,sep:str=',',datatype:str='np',expid:int=None):Get the data from csv files attached to eLabFTW experiments.filenameis the name of the file stored in the experiment.All other parameters are optional.sepis the column separator,
by default a comma. The parametersheader,datatypeandexpidhave the same
meaning as inget_table_data().defupload_file(file:str,comment:str,replacefile:bool=True,expid:int=None):Upload a file from local drives to an eLabFTW experiment.fileis the filepath of the file to be uploaded,commentis a description of the file.All other parameters are optional. Ifreplacefileis true, an existing
file with the same filename will be replaced. Otherwise, a new attachment
with the same filename will be created.expidis an integer number which identifies the eLabFTW experiment;
if set to None, the currently opened experiment is used.defupload_image_from_figure(fig:Figure,filename:str,comment:str,replacefile:bool=True,format:str='png',dpi='figure',expid:int=None):Upload an image of a matplotlib Figure (e.g. created byfig, ax = plt.subplots()) as attachment to an eLabFTW experiment.figamatplotlib.figure.Figureobject,filenamethe name of the image
file to be uploaded, andcommentis a description of the image.All other parameters are optional. Ifreplacefileis true, an existing
file with the same filename will be replaced. Otherwise, a new attachment
with the same filename will be created.formatordpispecify the
file format or image resolution, respectively. They are passed to
matplotlib'ssavefig()function.expidis an integer number which identifies the eLabFTW experiment;
if set to None, the currently opened experiment is used.defupload_csv_data(data,filename:str,comment:str,replacefile:bool=True,index:bool=False,expid:int=None):Generate a csv file from a pandas dataframe or a dictionary of
numpy arrays (column data) contained indataand upload it to an experiment on eLabFTW as csv file.commentis a description of the data.All other parameters are optional. Ifreplacefileis true, an existing
file with the same filename will be replaced. Otherwise, a new attachment
with the same filename will be created. Ifindexis true, the line index
of the dataframe is also stored to the file.expidis an integer number which identifies the eLabFTW experiment;
if set to None, the currently opened experiment is used.defupload_this_jupyternotebook(comment:str,replacefile:bool=True,expid:int=None):Saves and uploads the current jupyter notebook
to an experiment on eLabFTW.commentis a description of the
jupyter notebook.All other parameters are optional. Ifreplacefileis true, an existing
file with the same filename will be replaced. Otherwise, a new attachment
with the same filename will be created.expidis an integer number which identifies the eLabFTW experiment;
if set to None, the currently opened experiment is used.