Skip to main content

requests.Session to work with JSON APIs

Project description

api-session

api-session is a small module providing an extended requests.Session class to work with JSON APIs.

We use it at Bixoto as a basis for JSON API clients such as PyMagento or PyBigBuy.

It aims at factoring the common parts of these clients while staying very lightweight (<100 SLOC).

Features

  • base URL: the base API URL is given only once on object creation; subsequent calls use .get("/path")
  • read-only flag: if given, prevents the API from doing POST and similar calls
  • offline flag: if given, prevents the API from doing any call. This is useful for tests.
  • requests.Session inheritance: the class inherits from requests.Session, so it stays 100% compatible with it
  • (since 1.4) Response bodies are included in exception messages for 4xx errors. This behavior can be customized.

Install

pip install api-session

Or with Poetry:

poetry add api-session

Dependency: Python 3.8+.

Usage

from api_session import APISession

client = APISession("https://httpbin.org")

client.get_json_api("/get")
# => {...}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

api_session-1.4.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

api_session-1.4.1-py3-none-any.whl (5.3 kB view details)

Uploaded Python 3

File details

Details for the file api_session-1.4.1.tar.gz.

File metadata

  • Download URL: api_session-1.4.1.tar.gz
  • Upload date:
  • Size: 4.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.16 Linux/6.5.0-1024-azure

File hashes

Hashes for api_session-1.4.1.tar.gz
Algorithm Hash digest
SHA256 a9a16f553b3acc64ea6393c9bd94e57bd9f304f0a04f35e646b495160e5645fd
MD5 f127b7053641f8e74c060b5593bc14ee
BLAKE2b-256 77cb2df0b45adc35165e7a44e78ce849cf50a0e998d7b85bfbec94c0218c7859

See more details on using hashes here.

File details

Details for the file api_session-1.4.1-py3-none-any.whl.

File metadata

  • Download URL: api_session-1.4.1-py3-none-any.whl
  • Upload date:
  • Size: 5.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.9.16 Linux/6.5.0-1024-azure

File hashes

Hashes for api_session-1.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 afa7c2a44ae449a24627dc9cfca0b3e1727e52c9b2a82c939116935881925137
MD5 de9d9504a551a2da5f4ed4ee444d7d16
BLAKE2b-256 fca1d114e728bf212736973786043fd641204cba7bbf084403b75fe05303a7ab

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page