Django''s application to provide simple and shared requests client.
Project description
django-requests-api 
GitHub

Test

Check Demo Project
Requirements
- Python 3.8+ supported.
- Django 4.2+ supported.
Setup
- Install from pip:
pip install django-requests-api
- Modify
settings.pyby adding the app toINSTALLED_APPS:
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 (with or without leading/trailing slashes on either part). If the path is already an absolute URL (http:// or https://), it is used as-is. The package declares a dependency on requests (see install_requires).
Reusable helpers
RequestsApi lives in requests_api.requests_api; the utilities are in requests_api.helpers. All are re-exported from the package root so you can still use from requests_api import ….
from requests_api import (
copy_get_params_with_overrides,
normalize_api_language,
requests_api_for_base,
)
# Map Django language to an API that only supports a subset of codes
lang = normalize_api_language(
request.LANGUAGE_CODE,
allowed=("it", "en"),
fallback="en",
)
# Outbound GET: keep the browser query string but force lang=
params = copy_get_params_with_overrides(request, lang=lang)
# One shared Session / connection pool per base URL in the process
client = requests_api_for_base("https://www.example.com")
r = client.get("api/resource", params=params, timeout=30)
Run Example Project
git clone --depth=50 --branch=django-requests-api https://github.com/DLRSP/example.git DLRSP/example
cd DLRSP/example
python manage.py runserver
Now browser the app @ http://127.0.0.1:8000
Project details
Release history Release notifications | RSS feed
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.2.tar.gz.
File metadata
- Download URL: django_requests_api-0.6.2.tar.gz
- Upload date:
- Size: 24.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3aa3bf7dc41ed33d24012f81522583cd2d2d68cba8f9dddfdfe312db127eee07
|
|
| MD5 |
6a13e827487d05001817764db86bb7a5
|
|
| BLAKE2b-256 |
cb9d10c7f2f688ba77f8bdb2d45cacd0c28a618e5eed45beb543622a6ec2f9e3
|
File details
Details for the file django_requests_api-0.6.2-py2.py3-none-any.whl.
File metadata
- Download URL: django_requests_api-0.6.2-py2.py3-none-any.whl
- Upload date:
- Size: 6.8 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
41fdc9b4409aa16b85d303281295a4112ae2b5d5eed095519757234e9c598e38
|
|
| MD5 |
fdbcbe321fe1b0c5bcfb9f57e81995ec
|
|
| BLAKE2b-256 |
64be44e3316b74942eaf69d0889dd9da1ad76a5ed7b87fadd8491db4684fa791
|