Skip to content

Commit 267bf9d

Browse files
authored
Merge pull request #164 from uhd-urz/dev
Final merge before the release.
2 parents 42d6077 + 77061a0 commit 267bf9d

27 files changed

+1439
-493
lines changed

CHANGELOG.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,25 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## [2.4.1] - 2025-10-26
8+
## [2.4.2] - 2025-09-22
9+
10+
This release brings some minor bug fixes and improvements.
11+
12+
### Added
13+
14+
- elAPI `whoami` that shows information about the eLab user (see [documentation](https://github.com/uhd-urz/elAPI/tree/main?tab=readme-ov-file#elapi-whoami))
15+
- New configuration field `async_capacity` that lets you the maximum number of in-flight requests (see [documentation](https://github.com/uhd-urz/elAPI/tree/dev?tab=readme-ov-file#configuration))
16+
- Improved `bill-teams` retry strategy that uses `async_capacity`
17+
18+
### Fixed
19+
20+
- Fix #162, #155, #19, #8
21+
22+
### Changes
23+
24+
- Replace HTTPX's back-end with `aiohttp`. This fixes #162.
25+
26+
## [2.4.1] - 2025-08-26
927

1028
> [!NOTE]
1129
> This release deprecates support for Python versions 3.9 and 3.10.
@@ -17,7 +35,7 @@ This is a hotfix release. See the [version 2.4.0 changelog](https://github.com/u
1735
- Rollback [httpx-limiter](https://midnighter.github.io/httpx-limiter/) to version 0.3.0. The version 0.4.0 would break elAPI support on Pyodide (see GH #160)
1836

1937

20-
## [2.4.0] - 2025-10-25
38+
## [2.4.0] - 2025-08-25
2139

2240
> [!NOTE]
2341
> This release deprecates support for Python versions 3.9 and 3.10.

README.md

Lines changed: 39 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ $ elapi init
8585
<video src='https://github.com/user-attachments/assets/8d5f69ed-b644-4d75-b816-d06d4e937105'> </video>
8686
<p align="center">elapi init demo</p>
8787

88-
That's all! Run [`elapi show-config`](#show-config) to view your configuration details.
88+
That's all! Run [`elapi whoami`](#elapi-whoami) to see a short summary of your eLab user. Run [
89+
`elapi show-config`](#show-config) to view
90+
your configuration details.
8991

9092
## Compatibility
9193

@@ -128,7 +130,8 @@ unsafe_api_token_warning: true
128130
enable_http2: false
129131
verify_ssl: true
130132
timeout: 90
131-
async_rate_limit: 100
133+
async_rate_limit: 20
134+
async_capacity: 500
132135
development_mode: false
133136
```
134137
@@ -144,9 +147,13 @@ development_mode: false
144147
- `timeout` can be modified to your needs. E.g., a poor internet connection might benefit from a higher timeout number.
145148
The default timeout is `90` seconds.
146149
- `async_rate_limit` controls the maximum number of requests per second (i.e., throughput) you want to make to the
147-
server. Default `async_rate_limit` is `null` which is to say no limit. An eLab server might be configured to limit
150+
server. The default `async_rate_limit` is `null` which means no limit. An eLab server might be configured to limit
148151
a high number of requests to prevent spam, `async_rate_limit` can then be set to the maximum number of requests
149152
allowed by the server.
153+
- `async_capacity` controls the maximum number of in-flight async requests. The default `async_capacity` is `null` which
154+
means no limit on capacity. Both `async_rate_limit` and `async_capacity` can be used to better limit the traffic load
155+
put on the server. See this [SA answer](https://stackoverflow.com/a/52100884/7696241) about how they differ from each
156+
other.
150157
- `development_mode` can be set to `True` to show debug logs, Python traceback on the CLI instead of a clean exit, etc.
151158
This mode should not be turned on for production-ready scripts.
152159

@@ -170,6 +177,33 @@ as detected by `elapi show-config`. All plugins will also automatically listen t
170177
be useful to set certain configurations temporarily. E.g., `elapi --OC '{"timeout": 300"}' get info` will override
171178
the `timeout` from the configuration files.
172179

180+
## elAPI `whoami`
181+
182+
Oftentimes, you work with multiple API tokens/keys for multiple teams on multiple eLab servers. elAPI enables robust
183+
workflow management with built-in [advanced configuration](#advanced-configuration) orchestration. During development
184+
though,
185+
juggling between multiple API keys can still lead to confusion as to which API key is being actually used. elAPI version
186+
`2.4.1` adds the `whomai` command that shows the essential information about the requesting eLab user.
187+
188+
```shell
189+
$ elapi whoami
190+
```
191+
192+
![elapi whoami output](https://heibox.uni-heidelberg.de/f/e3096d5659db45e58a94/?dl=1)
193+
194+
So, if your API task requires write permission, but only `Read-only` is shown next to the API key, you know you're using
195+
the wrong API key. But having to run `elapi whoami` every single time for this would be cumbersome. So, we added the
196+
`whoami` information to the debug messages. To enable debug messages, set `development_mode` to `True` in
197+
the [configuration file](#configuration). Once set, before any elAPI command and plugin is run, elAPI will show the
198+
`whoami` information in the debug messages.
199+
200+
```shell
201+
DEBUG Based on the detected configuration, the requests will be made to the server get_whoami.py:114
202+
https://elabftw-dev-002.uni-heidelberg.de (eLabFTW version: 5.2.8), with API token '84-fc******2a384' (Read/Write),
203+
by user 'John Doe' (ID: 2607), from team 'North Kathy' (ID: 19), in user group 'User', not as a sysadmin. Scopes:
204+
experiments = 'Team', items = 'Team', experiments_templates = 'Team', teamgroups = 'Everything'
205+
```
206+
173207
## Examples and usage
174208

175209
Check out the [examples directory](https://github.com/uhd-urz/elAPI/tree/main/examples) for some comprehensive code
@@ -270,7 +304,8 @@ $ elapi experiments upload-attachment --id <experiment ID> --path <path to attac
270304

271305
Sometimes when a script has finished, you and your team would want to receive an email about its success/failure. elAPI
272306
offers a no-code solution for this: the `mail` plugin. The `mail` plugin is not enabled by default. To enable it,
273-
install elAPI with the optional dependency `mail`: `pip install elapi[mail]` or `uv add elapi[mail]`. [__See the wiki__](https://github.com/uhd-urz/elAPI/wiki/mail-plugin) to read more about how to configure the `mail` plugin with your
307+
install elAPI with the optional dependency `mail`: `pip install elapi[mail]` or `uv add elapi[mail]`. [__See the wiki
308+
__](https://github.com/uhd-urz/elAPI/wiki/mail-plugin) to read more about how to configure the `mail` plugin with your
274309
mail server configuration and trigger conditions. In a
275310
nutshell, the `mail` plugin will scan the logs when a script/plugin is done to look for pre-configured trigger
276311
conditions, and if found, it will send an email. The trigger conditions can be atomic and scope-based, i.e., an email

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "elapi"
3-
version = "2.4.1"
3+
version = "2.4.2"
44
description = "elAPI is a powerful, extensible API client for eLabFTW."
55
authors = [{ name = "Alexander Haller, Mahadi Xion", email = "elabftw@uni-heidelberg.de" }]
66
requires-python = ">=3.11.0,<4"
@@ -34,6 +34,7 @@ dependencies = [
3434
"mistune==3.1.3",
3535
"click>=8.1.8,<8.2",
3636
"httpx-limiter>=0.3.0,<0.4.0",
37+
"httpx-aiohttp>=0.1.8,<0.2",
3738
]
3839
license-files = [
3940
"LICENSE",

src/elapi/VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.4.1
1+
2.4.2

src/elapi/_names.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
ENV_XDG_DATA_HOME: str = "XDG_DATA_HOME"
2828
ENV_XDG_DOWNLOAD_DIR: str = "XDG_DOWNLOAD_DIR"
2929
ENV_XDG_CONFIG_HOME: str = "XDG_CONFIG_HOME"
30-
TMP_DIR: Path = Path(f"/var/tmp/{APP_NAME}")
3130

3231
# Fallback definitions
3332
FALLBACK_DIR: Path = user_home / ".local/share" / APP_NAME
@@ -48,6 +47,7 @@
4847
KEY_EXPORT_DIR: str = "EXPORT_DIR"
4948
KEY_UNSAFE_TOKEN_WARNING: str = "UNSAFE_API_TOKEN_WARNING"
5049
KEY_ENABLE_HTTP2: str = "ENABLE_HTTP2"
50+
KEY_ASYNC_CAPACITY: str = "ASYNC_CAPACITY"
5151
KEY_VERIFY_SSL: str = "VERIFY_SSL"
5252
KEY_TIMEOUT: str = "TIMEOUT"
5353
KEY_ASYNC_RATE_LIMIT: str = "ASYNC_RATE_LIMIT"

src/elapi/api/__init__.py

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,36 @@
1-
# ruff: noqa: F401
1+
__all__ = [
2+
"SessionDefaults",
3+
"SimpleClient",
4+
"GlobalSharedSession",
5+
"APIRequest",
6+
"ElabFTWURLError",
7+
"ElabFTWURL",
8+
"GETRequest",
9+
"AsyncGETRequest",
10+
"POSTRequest",
11+
"AsyncPOSTRequest",
12+
"PATCHRequest",
13+
"AsyncPATCHRequest",
14+
"DELETERequest",
15+
"AsyncDELETERequest",
16+
"FixedEndpoint",
17+
"FixedAsyncEndpoint",
18+
]
19+
220
from .api import (
3-
SessionDefaults,
4-
SimpleClient,
5-
GlobalSharedSession,
621
APIRequest,
7-
ElabFTWURLError,
8-
ElabFTWURL,
9-
GETRequest,
22+
AsyncDELETERequest,
1023
AsyncGETRequest,
11-
POSTRequest,
12-
AsyncPOSTRequest,
13-
PATCHRequest,
1424
AsyncPATCHRequest,
25+
AsyncPOSTRequest,
1526
DELETERequest,
16-
AsyncDELETERequest,
27+
ElabFTWURL,
28+
ElabFTWURLError,
29+
GETRequest,
30+
GlobalSharedSession,
31+
PATCHRequest,
32+
POSTRequest,
33+
SessionDefaults,
34+
SimpleClient,
1735
)
18-
from .endpoint import FixedEndpoint, FixedAsyncEndpoint
36+
from .endpoint import FixedAsyncEndpoint, FixedEndpoint

0 commit comments

Comments
 (0)