Commit 5b3a2be
committed
Allow to pass a requests.Session object to the miniflux client.
This update introduces the ability to pass a `requests.Session` object to the `Miniflux` client. This change enables users to leverage session management features such as rate limiting and caching.
**Changes:**
- Added `session: requests.Session` as an optional parameter to the `Miniflux` class constructor.
- Update the constructor to configure the session and trying to avoid to clash with any preset Session config
- The session is used for every HTTP request
- The default behavior creates a new session for each client instance.
**Example (header configuration):**
```python
import requests
import miniflux
session = requests.Session()
session.headers.update({"User-Agent": "Custom User-Agent"})
client = miniflux.Client("https://reader.miniflux.app", session=session)
```
**Example (client-side caching):**
```python
import miniflux
from cachecontrol import CacheControl
from cachecontrol.heuristics import ExpiresAfter
session = CacheControl(requests.Session(), heuristic=ExpiresAfter(days=1))
client = miniflux.Client("https://reader.miniflux.app", session=session)
```
**Possible improvement:**
The `request.Session` object is auto-closeable, would it make sense to
make the `miniflux.Client` auto-closeable as well to close the session ?
Let me know if you have any questions or suggestions!1 parent 76ae0ca commit 5b3a2be
2 files changed
Lines changed: 373 additions & 457 deletions
0 commit comments