Skip to main content

django-requests-api PyPi license

PyPi status PyPi version PyPi python version codecov.io pre-commit.ci status CI

Demo

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):

  • GitHub stars django-iubenda — Django application for privacy and cookies policy managed by Iubenda. Docs

Missing a project? Open a PR or run the workflow manually in your fork.

License

MIT — see LICENSE.

Metadata

Release files for django-requests-api 0.6.18

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-requests-api 0.6.18
File Size Uploaded Provenance Actions
django_requests_api-0.6.18.tar.gz 27.0 kB Without provenance Details for django_requests_api-0.6.18.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-requests-api 0.6.18
File Interpreter ABI Platform Actions
django_requests_api-0.6.18-py3-none-any.whl Python 3 none any Details for django_requests_api-0.6.18-py3-none-any.whl

Total release size: 100.7 kB

Release files / django_requests_api-0.6.18.tar.gz

Download URL django_requests_api-0.6.18.tar.gz
Size 27.0 kB
Tags Source
SHA-256 checksum
How to use checksums
ed0c3cd4472d3aeef2e4b9bcb04f239b5ef0d7ef1f22b385a50910d7c4e275ac
BLAKE2b-256 checksum
How to use checksums
7bed0f9d7159e30927cad32ca04ca4c9aea58ed63282cffd279270665494dde1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Release files / django_requests_api-0.6.18-py3-none-any.whl

Download URL django_requests_api-0.6.18-py3-none-any.whl
Size 73.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c9fffca99c4e8bba0e5f0f1a7bd6905fbe3e8e36106d8d528958f5ddcb7247d5
BLAKE2b-256 checksum
How to use checksums
6af880f5dc29bbdd32e4477f1d8da05a11eb20f51d889c0e2f751d24f1c528cb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.16

Security for django-requests-api 0.6.18

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page