elapi 1.0.7.dev1__tar.gz → 1.0.7.dev2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/PKG-INFO +81 -25
- elapi-1.0.7.dev2/README.md +201 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/pyproject.toml +2 -3
- elapi-1.0.7.dev2/src/elapi/VERSION +1 -0
- elapi-1.0.7.dev2/src/elapi/_exceptions.py +1 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/api.py +2 -2
- elapi-1.0.7.dev2/src/elapi/cli/__init__.py +1 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/cli/doc.py +2 -1
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/cli/elapi.py +40 -24
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/path.py +68 -14
- elapi-1.0.7.dev2/src/elapi/plugins/bill_teams/_doc.py +30 -0
- elapi-1.0.7.dev2/src/elapi/plugins/bill_teams/bill_teams.py +253 -0
- elapi-1.0.7.dev2/src/elapi/plugins/bill_teams/cli.py +372 -0
- elapi-1.0.7.dev2/src/elapi/plugins/bill_teams/format.py +30 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/plugins/bill_teams/invoice.py +8 -19
- elapi-1.0.7.dev2/src/elapi/plugins/bill_teams/validator.py +221 -0
- {elapi-1.0.7.dev1/src/elapi/plugins/utils → elapi-1.0.7.dev2/src/elapi/plugins/commons}/__init__.py +1 -0
- elapi-1.0.7.dev1/src/elapi/cli/helpers.py → elapi-1.0.7.dev2/src/elapi/plugins/commons/cli_helpers.py +7 -7
- elapi-1.0.7.dev2/src/elapi/plugins/commons/get_information.py +117 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/plugins/experiments/_doc.py +29 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/plugins/experiments/cli.py +5 -7
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/plugins/experiments/experiments.py +3 -3
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/plugins/show_config.py +4 -4
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/styles/__init__.py +2 -2
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/styles/format.py +47 -4
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/styles/highlight.py +10 -2
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/validators/__init__.py +2 -1
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/validators/base.py +18 -6
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/validators/identity.py +46 -3
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/validators/path.py +8 -14
- elapi-1.0.7.dev2/src/elapi/validators/permission.py +136 -0
- elapi-1.0.7.dev1/README.md +0 -145
- elapi-1.0.7.dev1/src/elapi/VERSION +0 -1
- elapi-1.0.7.dev1/src/elapi/cli/__init__.py +0 -1
- elapi-1.0.7.dev1/src/elapi/plugins/bill_teams/_doc.py +0 -3
- elapi-1.0.7.dev1/src/elapi/plugins/bill_teams/bill_teams.py +0 -164
- elapi-1.0.7.dev1/src/elapi/plugins/bill_teams/cli.py +0 -143
- elapi-1.0.7.dev1/src/elapi/validators/permission.py +0 -84
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/LICENSE +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/__init__.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/_names.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/cli/__main__.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/cli/_plugin_handler.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/configuration/__init__.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/configuration/_config_history.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/configuration/config.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/configuration/log_file.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/endpoint.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/loggers/__init__.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/loggers/base.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/loggers/handlers/__init__.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/loggers/handlers/file.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/loggers/handlers/stderr.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/plugins/__init__.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/plugins/bill_teams/__init__.py +0 -0
- {elapi-1.0.7.dev1/src/elapi/plugins/utils → elapi-1.0.7.dev2/src/elapi/plugins/commons}/export.py +0 -0
- {elapi-1.0.7.dev1/src/elapi/plugins/utils → elapi-1.0.7.dev2/src/elapi/plugins/commons}/get_location_from_headers.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/plugins/experiments/__init__.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/plugins/experiments/formats.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/plugins/version.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/styles/_markdown_doc.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/styles/_missing.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/styles/base.py +0 -0
- {elapi-1.0.7.dev1 → elapi-1.0.7.dev2}/src/elapi/styles/colors.py +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: elapi
|
|
3
|
-
Version: 1.0.7.
|
|
4
|
-
Summary: elAPI is a powerful, extensible API
|
|
3
|
+
Version: 1.0.7.dev2
|
|
4
|
+
Summary: elAPI is a powerful, extensible API client for eLabFTW.
|
|
5
5
|
Home-page: https://www.urz.uni-heidelberg.de/en/service-catalogue/software-and-applications/elabftw
|
|
6
6
|
License: AGPL-3.0-only
|
|
7
7
|
Keywords: elabftw,api
|
|
@@ -38,7 +38,10 @@ Description-Content-Type: text/markdown
|
|
|
38
38
|
|
|
39
39
|
# elAPI
|
|
40
40
|
|
|
41
|
-
elAPI is a powerful, extensible API
|
|
41
|
+
elAPI is a powerful, extensible API client for eLabFTW built for
|
|
42
|
+
the [University Computing Centre](https://www.urz.uni-heidelberg.de/en) (
|
|
43
|
+
URZ, [FIRE](https://www.urz.uni-heidelberg.de/en/node/64/organisation/future-it-research-education) division) at
|
|
44
|
+
Universität Heidelberg. It supports serving almost all kinds of requests documented on
|
|
42
45
|
[eLabFTW API documentation](https://doc.elabftw.net/api/v2/) with ease. elAPI treats eLabFTW API endpoints as its
|
|
43
46
|
arguments.
|
|
44
47
|
|
|
@@ -55,18 +58,47 @@ $ elapi get users --id <id>
|
|
|
55
58
|
|
|
56
59
|
## Installation
|
|
57
60
|
|
|
58
|
-
|
|
59
|
-
|
|
61
|
+
elAPI can be used both as a CLI tool and as a Python library. If you are interested in simply using elAPI's
|
|
62
|
+
off-the-shelf features from the command-line, install elAPI as a CLI tool. If you intend to write automation script for
|
|
63
|
+
eLabFTW, you should install elAPI as a library inside a virtual environment. Of course, if you're interested in
|
|
64
|
+
both, you can have elAPI installed in both ways.
|
|
65
|
+
|
|
66
|
+
### Install elAPI as a CLI tool
|
|
67
|
+
|
|
68
|
+
Support for installing Python packages with `pip install --user` has been deprecated with the adoption
|
|
69
|
+
of [PEP 688](https://peps.python.org/pep-0668/) on many systems
|
|
70
|
+
like [Debian 12](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1030335#5).
|
|
71
|
+
We recommend [`pipx`](https://pipx.pypa.io/stable/) for installing elAPI for use of its CLI functionalities. Pipx
|
|
72
|
+
installs packages in isolated virtual environments, so Pipx-installed elAPI should not conflict with elAPI installed
|
|
73
|
+
inside other virtual environments.
|
|
60
74
|
|
|
61
75
|
```shell
|
|
62
76
|
$ pipx install elapi
|
|
63
77
|
```
|
|
64
78
|
|
|
65
|
-
|
|
79
|
+
After installation with Pipx is complete, you would also be able to run elAPI just by entering the `elapi` command on
|
|
80
|
+
the
|
|
81
|
+
terminal.
|
|
82
|
+
|
|
83
|
+
### Install elAPI as a library
|
|
84
|
+
|
|
85
|
+
It is recommended to install elAPI inside a Python virtual environment for use of its rich APIs for
|
|
86
|
+
working with eLabFTW. From inside a virtual environment, elAPI CLI can be invoked with `python -m elapi.cli`.
|
|
87
|
+
At the moment, though, the documentation about using elAPI as a library is severely lacking.
|
|
66
88
|
|
|
67
89
|
## Configuration
|
|
68
90
|
|
|
69
|
-
elAPI needs to be configured first before
|
|
91
|
+
elAPI needs to be configured first before you can do anything useful with it. Mainly, elAPI needs to know your eLabFTW
|
|
92
|
+
server's API URL and your API key (or token) for access.
|
|
93
|
+
|
|
94
|
+
### Quick configuration
|
|
95
|
+
|
|
96
|
+
You can run `elapi init` to simplify the configuration process. You will be prompted with questions
|
|
97
|
+
about your eLabFTW server with examples to help you fill in the answers.
|
|
98
|
+
|
|
99
|
+
### Advanced configuration
|
|
100
|
+
|
|
101
|
+
elAPI supports a YAML configuration file in
|
|
70
102
|
the following locations.
|
|
71
103
|
|
|
72
104
|
- Current directory: `./elapi.yml`
|
|
@@ -74,12 +106,12 @@ the following locations.
|
|
|
74
106
|
- Root directory: `/etc/elapi.yml`
|
|
75
107
|
|
|
76
108
|
elAPI supports configuration overloading. I.e., a keyword set in root configuration file `/etc/elapi.yml` can be
|
|
77
|
-
|
|
109
|
+
overridden by setting a different value in user configuration file `$HOME/.config/elapi.yml`. In terms of precedence,
|
|
78
110
|
configuration file present in the currently active directory has the highest priority, and configuration in root
|
|
79
111
|
directory has the lowest.
|
|
80
112
|
|
|
81
113
|
The following parameters are currently configurable, with `host` and `api_token` being the required fields. For testing
|
|
82
|
-
purposes it would be safe to store everything in
|
|
114
|
+
purposes it would be safe to store everything in `$HOME/.config/elapi.yml`.
|
|
83
115
|
|
|
84
116
|
```yaml
|
|
85
117
|
# elAPI configuration
|
|
@@ -94,13 +126,13 @@ export_dir: ~/Downloads/elAPI
|
|
|
94
126
|
unsafe_api_token_warning: yes
|
|
95
127
|
```
|
|
96
128
|
|
|
97
|
-
|
|
129
|
+
You can get an overview of detected configurations.
|
|
98
130
|
|
|
99
131
|
```shell
|
|
100
132
|
$ elapi show-config
|
|
101
133
|
```
|
|
102
134
|
|
|
103
|
-
If both `host` and `api_token` are detected,
|
|
135
|
+
If both `host` and `api_token` are detected, you are good to go!
|
|
104
136
|
|
|
105
137
|
## Usage
|
|
106
138
|
|
|
@@ -112,14 +144,14 @@ $ elapi --help
|
|
|
112
144
|
|
|
113
145
|
### `GET` requests
|
|
114
146
|
|
|
115
|
-
|
|
147
|
+
Request an overview of running eLabFTW server:
|
|
116
148
|
|
|
117
149
|
```shell
|
|
118
150
|
$ elapi get info -F yml
|
|
119
151
|
# Here -F (or --format) defines the output format
|
|
120
152
|
```
|
|
121
153
|
|
|
122
|
-
|
|
154
|
+
You can request a list o all active experiments and export it to a `JSON` file.
|
|
123
155
|
|
|
124
156
|
```shell
|
|
125
157
|
$ elapi get experiments --export ~/Downoads/experiments.json
|
|
@@ -127,7 +159,7 @@ $ elapi get experiments --export ~/Downoads/experiments.json
|
|
|
127
159
|
|
|
128
160
|
### `POST` requests
|
|
129
161
|
|
|
130
|
-
|
|
162
|
+
Create a new user by the name 'John Doe':
|
|
131
163
|
|
|
132
164
|
```shell
|
|
133
165
|
$ elapi post users --id <user id> -d '{"firstname": "John", "lastname": "Doe", "email": "test_test@itnerd.de"}'
|
|
@@ -135,46 +167,70 @@ $ elapi post users --id <user id> -d '{"firstname": "John", "lastname": "Doe", "
|
|
|
135
167
|
|
|
136
168
|
### `PATCH` requests
|
|
137
169
|
|
|
138
|
-
|
|
170
|
+
Update an existing user's email address:
|
|
139
171
|
|
|
140
172
|
```shell
|
|
141
173
|
$ elapi patch users --id <user id> -d '{"email": "new_email@itnerd.de"}'
|
|
142
174
|
```
|
|
143
175
|
|
|
144
|
-
`patch` command allows us to make changes to eLabFTW server settings. E.g.,
|
|
176
|
+
`patch` command allows us to make changes to eLabFTW server settings. E.g., you can update the time (in minutes)
|
|
145
177
|
after which the authentication cookie will expire.
|
|
146
178
|
|
|
147
179
|
```shell
|
|
148
180
|
$ elapi patch config -d '{"cookie_validity_time": 43200}'
|
|
149
181
|
```
|
|
150
182
|
|
|
151
|
-
|
|
183
|
+
You can publish an announcement to all the members.
|
|
152
184
|
|
|
153
185
|
```shell
|
|
154
186
|
$ elapi patch config -d '{"announcement": "Notice: Server will be down tomorrow at midnight due to scheduled maintenance."}'
|
|
155
187
|
```
|
|
156
188
|
|
|
157
|
-
###
|
|
189
|
+
### `DELETE` requests
|
|
158
190
|
|
|
159
|
-
|
|
191
|
+
Delete all the tags associated to an experiment:
|
|
160
192
|
|
|
161
193
|
```shell
|
|
162
|
-
$ elapi
|
|
194
|
+
$ elapi delete experiments -i <experiment ID> --sub tags
|
|
163
195
|
```
|
|
164
196
|
|
|
165
|
-
|
|
197
|
+
You can reset the configuration to default values.
|
|
166
198
|
|
|
167
199
|
```shell
|
|
168
|
-
$ elapi
|
|
200
|
+
$ elapi delete config
|
|
169
201
|
```
|
|
170
202
|
|
|
171
|
-
|
|
172
|
-
|
|
203
|
+
### `experiments` plugin
|
|
204
|
+
|
|
205
|
+
`experiments` plugin enables experiments-specific actions. You can download an experiment in PDF by its "Unique eLabID"
|
|
206
|
+
to `~/Downloads` directory.
|
|
173
207
|
|
|
174
208
|
```shell
|
|
175
|
-
elapi
|
|
209
|
+
$ elapi experiments get -i <experiment unique elabid> -F pdf --export ~/Downloads/
|
|
176
210
|
```
|
|
177
211
|
|
|
212
|
+
Append text in markdown to an existing experiment by its ID:
|
|
213
|
+
|
|
214
|
+
```shell
|
|
215
|
+
$ elapi experiments append --id <experiment ID> -M -t "**New content.**"
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
You can also upload an attachment to an experiment.
|
|
219
|
+
|
|
220
|
+
```shell
|
|
221
|
+
$ elapi experiments upload-attachment --id <experiment ID> --path <path to attachment file> --comment <comment for your attachment>
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
### Bill teams
|
|
225
|
+
|
|
226
|
+
You can get a list of all teams and its users for billing purposes and export it to home directory.
|
|
227
|
+
|
|
228
|
+
```shell
|
|
229
|
+
$ elapi bill-teams teams-info --export ~
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Most sub-commands available under `elapi bill-teams` plugin are for Universität Heidelberg specific use-cases.
|
|
233
|
+
|
|
178
234
|
## Open-source
|
|
179
235
|
|
|
180
236
|
elAPI is open-source and published under AGPLv3 license. The repository is however hosted internally within
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
# elAPI
|
|
2
|
+
|
|
3
|
+
elAPI is a powerful, extensible API client for eLabFTW built for
|
|
4
|
+
the [University Computing Centre](https://www.urz.uni-heidelberg.de/en) (
|
|
5
|
+
URZ, [FIRE](https://www.urz.uni-heidelberg.de/en/node/64/organisation/future-it-research-education) division) at
|
|
6
|
+
Universität Heidelberg. It supports serving almost all kinds of requests documented on
|
|
7
|
+
[eLabFTW API documentation](https://doc.elabftw.net/api/v2/) with ease. elAPI treats eLabFTW API endpoints as its
|
|
8
|
+
arguments.
|
|
9
|
+
|
|
10
|
+
**Example:**
|
|
11
|
+
|
|
12
|
+
From [the documentation](https://doc.elabftw.net/api/v2/#/Users/read-user):
|
|
13
|
+
> GET /users/{id}
|
|
14
|
+
|
|
15
|
+
With elAPI you can do the following:
|
|
16
|
+
|
|
17
|
+
```sh
|
|
18
|
+
$ elapi get users --id <id>
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Installation
|
|
22
|
+
|
|
23
|
+
elAPI can be used both as a CLI tool and as a Python library. If you are interested in simply using elAPI's
|
|
24
|
+
off-the-shelf features from the command-line, install elAPI as a CLI tool. If you intend to write automation script for
|
|
25
|
+
eLabFTW, you should install elAPI as a library inside a virtual environment. Of course, if you're interested in
|
|
26
|
+
both, you can have elAPI installed in both ways.
|
|
27
|
+
|
|
28
|
+
### Install elAPI as a CLI tool
|
|
29
|
+
|
|
30
|
+
Support for installing Python packages with `pip install --user` has been deprecated with the adoption
|
|
31
|
+
of [PEP 688](https://peps.python.org/pep-0668/) on many systems
|
|
32
|
+
like [Debian 12](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1030335#5).
|
|
33
|
+
We recommend [`pipx`](https://pipx.pypa.io/stable/) for installing elAPI for use of its CLI functionalities. Pipx
|
|
34
|
+
installs packages in isolated virtual environments, so Pipx-installed elAPI should not conflict with elAPI installed
|
|
35
|
+
inside other virtual environments.
|
|
36
|
+
|
|
37
|
+
```shell
|
|
38
|
+
$ pipx install elapi
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
After installation with Pipx is complete, you would also be able to run elAPI just by entering the `elapi` command on
|
|
42
|
+
the
|
|
43
|
+
terminal.
|
|
44
|
+
|
|
45
|
+
### Install elAPI as a library
|
|
46
|
+
|
|
47
|
+
It is recommended to install elAPI inside a Python virtual environment for use of its rich APIs for
|
|
48
|
+
working with eLabFTW. From inside a virtual environment, elAPI CLI can be invoked with `python -m elapi.cli`.
|
|
49
|
+
At the moment, though, the documentation about using elAPI as a library is severely lacking.
|
|
50
|
+
|
|
51
|
+
## Configuration
|
|
52
|
+
|
|
53
|
+
elAPI needs to be configured first before you can do anything useful with it. Mainly, elAPI needs to know your eLabFTW
|
|
54
|
+
server's API URL and your API key (or token) for access.
|
|
55
|
+
|
|
56
|
+
### Quick configuration
|
|
57
|
+
|
|
58
|
+
You can run `elapi init` to simplify the configuration process. You will be prompted with questions
|
|
59
|
+
about your eLabFTW server with examples to help you fill in the answers.
|
|
60
|
+
|
|
61
|
+
### Advanced configuration
|
|
62
|
+
|
|
63
|
+
elAPI supports a YAML configuration file in
|
|
64
|
+
the following locations.
|
|
65
|
+
|
|
66
|
+
- Current directory: `./elapi.yml`
|
|
67
|
+
- User directory: `$HOME/.config/elapi.yml`
|
|
68
|
+
- Root directory: `/etc/elapi.yml`
|
|
69
|
+
|
|
70
|
+
elAPI supports configuration overloading. I.e., a keyword set in root configuration file `/etc/elapi.yml` can be
|
|
71
|
+
overridden by setting a different value in user configuration file `$HOME/.config/elapi.yml`. In terms of precedence,
|
|
72
|
+
configuration file present in the currently active directory has the highest priority, and configuration in root
|
|
73
|
+
directory has the lowest.
|
|
74
|
+
|
|
75
|
+
The following parameters are currently configurable, with `host` and `api_token` being the required fields. For testing
|
|
76
|
+
purposes it would be safe to store everything in `$HOME/.config/elapi.yml`.
|
|
77
|
+
|
|
78
|
+
```yaml
|
|
79
|
+
# elAPI configuration
|
|
80
|
+
# Saved in `$HOME/.config/elapi.yml`
|
|
81
|
+
|
|
82
|
+
host: <host API url>
|
|
83
|
+
# Example: https://demo.elabftw.net/api/v2/
|
|
84
|
+
# Note the host URL ends with the API endpoint
|
|
85
|
+
api_token: <token with at least read-access>
|
|
86
|
+
# You can generate an API token from eLabFTW user panel -> API keys tab.
|
|
87
|
+
export_dir: ~/Downloads/elAPI
|
|
88
|
+
unsafe_api_token_warning: yes
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
You can get an overview of detected configurations.
|
|
92
|
+
|
|
93
|
+
```shell
|
|
94
|
+
$ elapi show-config
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
If both `host` and `api_token` are detected, you are good to go!
|
|
98
|
+
|
|
99
|
+
## Usage
|
|
100
|
+
|
|
101
|
+
elAPI can be invoked from the command-line.
|
|
102
|
+
|
|
103
|
+
```shell
|
|
104
|
+
$ elapi --help
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### `GET` requests
|
|
108
|
+
|
|
109
|
+
Request an overview of running eLabFTW server:
|
|
110
|
+
|
|
111
|
+
```shell
|
|
112
|
+
$ elapi get info -F yml
|
|
113
|
+
# Here -F (or --format) defines the output format
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
You can request a list o all active experiments and export it to a `JSON` file.
|
|
117
|
+
|
|
118
|
+
```shell
|
|
119
|
+
$ elapi get experiments --export ~/Downoads/experiments.json
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
### `POST` requests
|
|
123
|
+
|
|
124
|
+
Create a new user by the name 'John Doe':
|
|
125
|
+
|
|
126
|
+
```shell
|
|
127
|
+
$ elapi post users --id <user id> -d '{"firstname": "John", "lastname": "Doe", "email": "test_test@itnerd.de"}'
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### `PATCH` requests
|
|
131
|
+
|
|
132
|
+
Update an existing user's email address:
|
|
133
|
+
|
|
134
|
+
```shell
|
|
135
|
+
$ elapi patch users --id <user id> -d '{"email": "new_email@itnerd.de"}'
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
`patch` command allows us to make changes to eLabFTW server settings. E.g., you can update the time (in minutes)
|
|
139
|
+
after which the authentication cookie will expire.
|
|
140
|
+
|
|
141
|
+
```shell
|
|
142
|
+
$ elapi patch config -d '{"cookie_validity_time": 43200}'
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
You can publish an announcement to all the members.
|
|
146
|
+
|
|
147
|
+
```shell
|
|
148
|
+
$ elapi patch config -d '{"announcement": "Notice: Server will be down tomorrow at midnight due to scheduled maintenance."}'
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### `DELETE` requests
|
|
152
|
+
|
|
153
|
+
Delete all the tags associated to an experiment:
|
|
154
|
+
|
|
155
|
+
```shell
|
|
156
|
+
$ elapi delete experiments -i <experiment ID> --sub tags
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
You can reset the configuration to default values.
|
|
160
|
+
|
|
161
|
+
```shell
|
|
162
|
+
$ elapi delete config
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### `experiments` plugin
|
|
166
|
+
|
|
167
|
+
`experiments` plugin enables experiments-specific actions. You can download an experiment in PDF by its "Unique eLabID"
|
|
168
|
+
to `~/Downloads` directory.
|
|
169
|
+
|
|
170
|
+
```shell
|
|
171
|
+
$ elapi experiments get -i <experiment unique elabid> -F pdf --export ~/Downloads/
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Append text in markdown to an existing experiment by its ID:
|
|
175
|
+
|
|
176
|
+
```shell
|
|
177
|
+
$ elapi experiments append --id <experiment ID> -M -t "**New content.**"
|
|
178
|
+
```
|
|
179
|
+
|
|
180
|
+
You can also upload an attachment to an experiment.
|
|
181
|
+
|
|
182
|
+
```shell
|
|
183
|
+
$ elapi experiments upload-attachment --id <experiment ID> --path <path to attachment file> --comment <comment for your attachment>
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
### Bill teams
|
|
187
|
+
|
|
188
|
+
You can get a list of all teams and its users for billing purposes and export it to home directory.
|
|
189
|
+
|
|
190
|
+
```shell
|
|
191
|
+
$ elapi bill-teams teams-info --export ~
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
Most sub-commands available under `elapi bill-teams` plugin are for Universität Heidelberg specific use-cases.
|
|
195
|
+
|
|
196
|
+
## Open-source
|
|
197
|
+
|
|
198
|
+
elAPI is open-source and published under AGPLv3 license. The repository is however hosted internally within
|
|
199
|
+
Universität Heidelberg's network. The codebase can still be accessed from [PyPI](https://pypi.org/project/elapi/#files).
|
|
200
|
+
If you express interest in having the repository made completely public, or if you have any question, feel free
|
|
201
|
+
to [contact us](mailto:elabftw@uni-heidelberg.de).
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "elapi"
|
|
3
|
-
version = "1.0.7-
|
|
4
|
-
description = "
|
|
5
|
-
the University Computing Centre (URZ, FIRE division) at Universität Heidelberg."""
|
|
3
|
+
version = "1.0.7-dev2"
|
|
4
|
+
description = "elAPI is a powerful, extensible API client for eLabFTW."
|
|
6
5
|
authors = [
|
|
7
6
|
"Alexander Haller <alexander.haller@urz.uni-heidelberg.de>",
|
|
8
7
|
"Mahadi Xion <mahadi.xion@urz.uni-heidelberg.de>",
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
1.0.7-dev2
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
class NoException(Exception): ...
|
|
@@ -154,7 +154,7 @@ class ElabFTWURL:
|
|
|
154
154
|
@endpoint_id.setter
|
|
155
155
|
def endpoint_id(self, value):
|
|
156
156
|
if value is not None:
|
|
157
|
-
if not re.match(r"
|
|
157
|
+
if not re.match(r"^(\d+)$|^(me)$", value := str(value)):
|
|
158
158
|
# Although, eLabFTW primarily supports integer-only IDs, there are exceptions, like the alias
|
|
159
159
|
# ID "me" for receiving one's own user information.
|
|
160
160
|
raise ElabFTWURLError("Invalid endpoint ID (or entity ID).")
|
|
@@ -173,7 +173,7 @@ class ElabFTWURL:
|
|
|
173
173
|
"Sub-endpoint ID cannot be defined without first specifying its sub-endpoint name."
|
|
174
174
|
)
|
|
175
175
|
if value is not None:
|
|
176
|
-
if not re.match(r"
|
|
176
|
+
if not re.match(r"^(\d+)$|^(me)$", value := str(value)):
|
|
177
177
|
raise ElabFTWURLError("Invalid sub-endpoint ID (or entity sub-ID).")
|
|
178
178
|
self._sub_endpoint_id = value
|
|
179
179
|
else:
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
from ..plugins.commons.cli_helpers import CLIExport, CLIFormat, OrderedCommands # noqa: F401
|
|
@@ -76,7 +76,8 @@ __PARAMETERS__doc__ = {
|
|
|
76
76
|
"When 'txt' is used, the response will be sent in *original*, un-formatted (almost), "
|
|
77
77
|
"without syntax highlighting. This can be utilized if one wishes to pipe the output "
|
|
78
78
|
" to some external formatting program like `less`. "
|
|
79
|
-
"If an unsupported format value is provided then the output format
|
|
79
|
+
"If an unsupported format value is provided then the output format "
|
|
80
|
+
f"falls back to `{DEFAULT_EXPORT_DATA_FORMAT.upper()}`.",
|
|
80
81
|
"no_keys": "Do not show the names of configuration keywords.",
|
|
81
82
|
"init_host": 'The host URL of your eLabFTW instance. It will look like \"https://demo.elabftw.net/api/v2\".',
|
|
82
83
|
"init_api_token": 'API token (or API key) of your eLabFTW instance. You can generate it from eLabFTW "User Panel". '
|
|
@@ -21,10 +21,10 @@ from typing_extensions import Annotated
|
|
|
21
21
|
|
|
22
22
|
from ._plugin_handler import internal_plugin_typer_apps
|
|
23
23
|
from .doc import __PARAMETERS__doc__ as docs
|
|
24
|
-
from .helpers import OrderedCommands
|
|
25
24
|
from .. import APP_NAME
|
|
26
25
|
from ..configuration import EXPORT_DIR
|
|
27
26
|
from ..loggers import Logger
|
|
27
|
+
from ..plugins.commons.cli_helpers import OrderedCommands
|
|
28
28
|
from ..styles import get_custom_help_text
|
|
29
29
|
from ..styles import stdin_console, stderr_console
|
|
30
30
|
|
|
@@ -101,6 +101,7 @@ def init(
|
|
|
101
101
|
from ..configuration import LOCAL_CONFIG_LOC
|
|
102
102
|
from ..validators import Validate, ValidationError
|
|
103
103
|
from ..validators import PathValidator
|
|
104
|
+
from ..path import ProperPath
|
|
104
105
|
from time import sleep
|
|
105
106
|
|
|
106
107
|
with stdin_console.status(
|
|
@@ -119,27 +120,42 @@ def init(
|
|
|
119
120
|
)
|
|
120
121
|
raise typer.Exit(1)
|
|
121
122
|
else:
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
123
|
+
path = ProperPath(LOCAL_CONFIG_LOC)
|
|
124
|
+
try:
|
|
125
|
+
with path.open(mode="r") as f:
|
|
126
|
+
if f.read():
|
|
127
|
+
logger.error(
|
|
128
|
+
f"A configuration file '{LOCAL_CONFIG_LOC}' already exists and it's not empty! "
|
|
129
|
+
f"It's ambiguous what to do in this situation."
|
|
130
|
+
)
|
|
131
|
+
logger.error("Configuration initialization has failed!")
|
|
132
|
+
raise typer.Exit(1)
|
|
133
|
+
except path.PathException as e:
|
|
134
|
+
if isinstance(e, FileNotFoundError):
|
|
135
|
+
path.create()
|
|
130
136
|
else:
|
|
137
|
+
logger.error(e)
|
|
138
|
+
logger.error("Configuration initialization has failed!")
|
|
139
|
+
raise typer.Exit(1)
|
|
140
|
+
try:
|
|
141
|
+
with path.open(mode="w") as f:
|
|
131
142
|
_configuration_yaml_text = f"""host: {host_url}
|
|
132
|
-
api_token: {api_token}
|
|
133
|
-
export_dir: {export_directory}
|
|
134
|
-
unsafe_api_token_warning: yes
|
|
135
|
-
"""
|
|
143
|
+
api_token: {api_token}
|
|
144
|
+
export_dir: {export_directory}
|
|
145
|
+
unsafe_api_token_warning: yes
|
|
146
|
+
"""
|
|
136
147
|
f.write(_configuration_yaml_text)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
148
|
+
except path.PathException as e:
|
|
149
|
+
logger.error(e)
|
|
150
|
+
logger.error("Configuration initialization has failed!")
|
|
151
|
+
raise typer.Exit(1)
|
|
152
|
+
else:
|
|
153
|
+
stdin_console.print(
|
|
154
|
+
"Configuration file has been successfully created! "
|
|
155
|
+
f"Run '{APP_NAME} show-config' to see the configuration path "
|
|
156
|
+
"and more configuration details.",
|
|
157
|
+
style="green",
|
|
158
|
+
)
|
|
143
159
|
|
|
144
160
|
|
|
145
161
|
@app.command(short_help="Make `GET` requests to eLabFTW endpoints.")
|
|
@@ -200,9 +216,9 @@ def get(
|
|
|
200
216
|
import re
|
|
201
217
|
from .. import APP_NAME
|
|
202
218
|
from ..api import GETRequest, ElabFTWURLError
|
|
203
|
-
from .
|
|
219
|
+
from ..plugins.commons.cli_helpers import CLIExport, CLIFormat
|
|
204
220
|
from ..validators import Validate, HostIdentityValidator
|
|
205
|
-
from ..plugins.
|
|
221
|
+
from ..plugins.commons import Export
|
|
206
222
|
from ..styles import Highlight
|
|
207
223
|
|
|
208
224
|
validate_config = Validate(HostIdentityValidator())
|
|
@@ -324,7 +340,7 @@ def post(
|
|
|
324
340
|
|
|
325
341
|
With `elapi` you can do the following:
|
|
326
342
|
<br/>
|
|
327
|
-
`$ elapi post users
|
|
343
|
+
`$ elapi post users -d '{"firstname": "John", "lastname": "Doe", "email": "test_test@itnerd.de"}'`
|
|
328
344
|
will create a new user.
|
|
329
345
|
"""
|
|
330
346
|
import ast
|
|
@@ -332,7 +348,7 @@ def post(
|
|
|
332
348
|
from ..api import POSTRequest, ElabFTWURLError
|
|
333
349
|
from json import JSONDecodeError
|
|
334
350
|
from ..validators import Validate, HostIdentityValidator
|
|
335
|
-
from ..plugins.
|
|
351
|
+
from ..plugins.commons import get_location_from_headers
|
|
336
352
|
from ..styles import Format, Highlight
|
|
337
353
|
from ..path import ProperPath
|
|
338
354
|
|
|
@@ -670,7 +686,7 @@ def show_config(
|
|
|
670
686
|
no_keys: Annotated[
|
|
671
687
|
Optional[bool],
|
|
672
688
|
typer.Option("--no-keys", help=docs["no_keys"], show_default=True),
|
|
673
|
-
] =
|
|
689
|
+
] = False,
|
|
674
690
|
) -> None:
|
|
675
691
|
"""
|
|
676
692
|
Get information about detected configuration values.
|