summaryrefslogtreecommitdiff
path: root/docs
diff options
context:
space:
mode:
authorJordan Cook <jordan.cook@pioneer.com>2021-09-04 16:43:36 -0500
committerJordan Cook <jordan.cook@pioneer.com>2021-09-04 16:43:36 -0500
commit1e6ce2399e273f1354b8bde017c5887c42b74e5e (patch)
treec89e689ff0480a9c11ed65f68ca70ac50c6a364c /docs
parent2983618943acee411ff58ce4642ff940c9dbff2e (diff)
downloadrequests-cache-1e6ce2399e273f1354b8bde017c5887c42b74e5e.tar.gz
Format examples
Diffstat (limited to 'docs')
-rw-r--r--docs/user_guide/compatibility.md55
1 files changed, 28 insertions, 27 deletions
diff --git a/docs/user_guide/compatibility.md b/docs/user_guide/compatibility.md
index 080da9b..e3b9424 100644
--- a/docs/user_guide/compatibility.md
+++ b/docs/user_guide/compatibility.md
@@ -44,6 +44,9 @@ The same approach can be used with other libraries that subclass {py:class}`requ
Some libraries, including [requests-futures](https://github.com/ross/requests-futures),
support wrapping an existing session object:
```python
+>>> from requests_cache import CachedSession
+>>> from requests_futures.sessions import FuturesSession
+
>>> session = FutureSession(session=CachedSession())
```
@@ -51,33 +54,6 @@ In this case, `FutureSession` must wrap `CachedSession` rather than the other wa
`FutureSession` returns (as you might expect) futures rather than response objects.
See [issue #135](https://github.com/reclosedev/requests-cache/issues/135) for more notes on this.
-## Requests-Ratelimiter
-[requests-ratelimiter](https://github.com/JWCook/requests-ratelimiter) adds rate-limiting to
-requests via the [pyrate-limiter](https://github.com/vutran1710/PyrateLimiter) library. It also
-provides a mixin, but note that the inheritance order is important: If rate-limiting is applied
-_after_ caching, you get the added benefit of not counting cache hits against your rate limit.
-```python
-from pyrate_limiter import RedisBucket, RequestRate, Duration
-from requests import Session
-from requests_cache import CacheMixin, RedisCache
-from requests_ratelimiter import LimiterMixin
-
-
-class CachedLimiterSession(CacheMixin, LimiterMixin, Session):
- """Session class with caching and rate-limiting behavior. Accepts arguments for both
- LimiterSession and CachedSession.
- """
-
-
-# Limit non-cached requests to 5 requests per second, with unlimited cached requests
-# Optionally use Redis as both the bucket backend and the cache backend
-session = CachedLimiterSession(
- rates=RequestRate(5, Duration.SECOND),
- bucket_class=RedisBucket,
- backend=RedisCache(),
-)
-```
-
## Requests-OAuthlib
Usage with [requests-oauthlib](https://github.com/requests/requests-oauthlib) is the same as other
libraries that subclass `requests.Session`:
@@ -91,6 +67,31 @@ libraries that subclass `requests.Session`:
>>> session = CachedOAuth2Session('my_client_id')
```
+## Requests-Ratelimiter
+[requests-ratelimiter](https://github.com/JWCook/requests-ratelimiter) adds rate-limiting to
+requests via the [pyrate-limiter](https://github.com/vutran1710/PyrateLimiter) library. It also
+provides a mixin, but note that the inheritance order is important: If rate-limiting is applied
+_after_ caching, you get the added benefit of not counting cache hits against your rate limit.
+```python
+>>> from pyrate_limiter import RedisBucket, RequestRate, Duration
+>>> from requests import Session
+>>> from requests_cache import CacheMixin, RedisCache
+>>> from requests_ratelimiter import LimiterMixin
+
+>>> class CachedLimiterSession(CacheMixin, LimiterMixin, Session):
+... """Session class with caching and rate-limiting behavior. Accepts arguments for both
+... LimiterSession and CachedSession.
+... """
+
+>>> # Limit non-cached requests to 5 requests per second, with unlimited cached requests
+>>> # Optionally use Redis as both the bucket backend and the cache backend
+>>> session = CachedLimiterSession(
+... rates=RequestRate(5, Duration.SECOND),
+... bucket_class=RedisBucket,
+... backend=RedisCache(),
+... )
+```
+
## Internet Archive
Usage with [internetarchive](https://github.com/jjjake/internetarchive) is the same as other libraries
that subclass `requests.Session`: