Allow to pass a requests.Session object to the miniflux client. #36
Merged
fguillot merged 4 commits intominiflux:mainfrom Jan 26, 2025
Merged
Allow to pass a requests.Session object to the miniflux client. #36fguillot merged 4 commits intominiflux:mainfrom
fguillot merged 4 commits intominiflux:mainfrom
Conversation
e731285 to
5b3a2be
Compare
5b3a2be to
81aad77
Compare
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!
81aad77 to
a7593c3
Compare
Member
|
Your pull-request looks good. However, there are some minor issues detected by the linter if you don't mind fixing that (this project uses Ruff).
That sounds like a good idea. Feel free to improve that as well :) |
To handle the underlying session
Contributor
Author
|
Glad you liked it. |
fguillot
reviewed
Jan 26, 2025
6eb56a7 to
86514fb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This update introduces the ability to pass a
requests.Sessionobject to the miniflux client. This change enables users to leverage session management features such as rate limiting and caching.Changes:
session: requests.Sessionas an optional parameter to theClientclass constructor.Example (header configuration):
Example (client-side caching):
Possible improvement:
request.Sessionobject is auto-closeable, would it make sense to make theminiflux.Clientauto-closeable as well to close the session ?Let me know if you have any questions or suggestions!