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.

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

django_requests_api-0.6.9.tar.gz (26.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

django_requests_api-0.6.9-py3-none-any.whl (73.8 kB view details)

Uploaded Python 3

File details

Details for the file django_requests_api-0.6.9.tar.gz.

File metadata

  • Download URL: django_requests_api-0.6.9.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

Hashes for django_requests_api-0.6.9.tar.gz
Algorithm Hash digest
SHA256 5cc23a492103c2f9ab5154cfd77d0e8cbb020bb7c927c571a0a2dc47ad9fa5a6
MD5 a6d0d0236ad83876a4851597fab41165
BLAKE2b-256 60080599cf7a130d068a3cfa50db948ad52367fe8f159b7fa5c7d3f2e7c33a6a

See more details on using hashes here.

File details

Details for the file django_requests_api-0.6.9-py3-none-any.whl.

File metadata

File hashes

Hashes for django_requests_api-0.6.9-py3-none-any.whl
Algorithm Hash digest
SHA256 05fdf5d8686988a14e2ed87ab7d96d136e7554789a373f2ccfa02cbdb16d78ae
MD5 5df56cc603fb2093adf8e79dc3a3efff
BLAKE2b-256 fa9c8ad9bce5da0e7b88e7d7545baa93eafc128d9862bbeb0bba152fff3c7b86

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.6.9 This release

2 files

0.6.8

2 files

0.6.7

2 files

0.6.6

2 files

0.6.5

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.2

2 files

0.5.1

2 files

0.3.2

2 files

0.2.0

3 files

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