django-requests-api 
Demo
- Heroku demo (if still online)
- Example branch on DLRSP/example
Requirements
- Python 3.9+
- Django 4.2+ (see package classifiers for the full matrix)
Install
pip install django-requests-api
INSTALLED_APPS = (
# ...
"requests_api",
# ...
)
Usage
from requests_api import RequestsApi
client = RequestsApi("https://api.publicapis.org")
r = client.get("/entries")
print(r.json())
github = RequestsApi(
"https://api.github.com",
headers={"Authorization": "token abcdef"},
)
r = github.get("/user", headers={"Accept": "application/json"})
print(r.text)
Paths are joined to base_url with a single slash. Absolute URLs (http:// / https://) are passed through unchanged. The package depends on requests (install_requires).
Helpers
Implementation: requests_api.requests_api and requests_api.helpers; public imports from the package root:
from requests_api import (
copy_get_params_with_overrides,
normalize_api_language,
requests_api_for_base,
)
lang = normalize_api_language(
request.LANGUAGE_CODE,
allowed=("it", "en"),
fallback="en",
)
params = copy_get_params_with_overrides(request, lang=lang)
client = requests_api_for_base("https://www.example.com")
r = client.get("api/resource", params=params, timeout=30)
Configuration (APP_CONFIG / REQUESTS_API_*)
Read via requests_api.conf: Django settings first, then APP_CONFIG["requests_api"], then defaults.
APP_CONFIG["requests_api"] |
Django setting | Notes |
|---|---|---|
CACHED_CLIENTS_MAXSIZE |
REQUESTS_API_CACHED_CLIENTS_MAXSIZE |
Cap for requests_api_for_base (default 8). 0 or below turns caching off. |
DEFAULT_REQUEST_TIMEOUT |
REQUESTS_API_DEFAULT_REQUEST_TIMEOUT |
Optional seconds; default None. Not applied automatically—call get_requests_api_default_request_timeout() and pass timeout= yourself if you want a shared value. |
from requests_api import get_requests_api_default_request_timeout
timeout = get_requests_api_default_request_timeout()
client = requests_api_for_base("https://api.example.com")
r = client.get("v1/x", timeout=timeout if timeout is not None else 30)
In tests, call clear_requests_api_client_cache() when you change cache settings. Full write-up: docs/tutorial/configuration.md (MkDocs: Tutorials → Configuration).
Run the example locally
git clone --depth=50 --branch=django-requests-api https://github.com/DLRSP/example.git example-requests-api
cd example-requests-api
python manage.py runserver
Then open http://127.0.0.1:8000 (install dependencies from that repo’s requirements/ first).
Docs
MkDocs sources live under docs/. See Contributing for mkdocs serve.
Used in
Public GitHub projects that reference django-requests-api / requests_api (weekly sync via .github/used-in.yaml and update-used-in):
django-iubenda — Django application for privacy and cookies policy managed by Iubenda.
Missing a project? Open a PR or run the workflow manually in your fork.
License
MIT — see LICENSE.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_requests_api-0.6.6.tar.gz.
File metadata
- Download URL: django_requests_api-0.6.6.tar.gz
- Upload date:
- Size: 26.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c1de03ad30a814e7c021e2385abf3dc6112e456c03209315eb40f52e63421d02
|
|
| MD5 |
5a7f3f165bf7f8ab3de25a7b3d0d797c
|
|
| BLAKE2b-256 |
a62f7d959f67c311a09e02289000e1a4f315544b29024ee3fef3ffd55a151b79
|
File details
Details for the file django_requests_api-0.6.6-py3-none-any.whl.
File metadata
- Download URL: django_requests_api-0.6.6-py3-none-any.whl
- Upload date:
- Size: 73.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c6ef6a441644727cf384c24923976646f9c8d66a0b371976f57be1a12e485ec3
|
|
| MD5 |
df6a98522a692dd884d880cf5a542f0e
|
|
| BLAKE2b-256 |
b65690d1314911ee7f9ce9f1b84e7ce8db19fe57ab64726d6facb437fa85b20f
|