Slumber

raw JSON →
0.7.1 verified Mon Apr 27 auth: no python maintenance

A library that makes consuming a REST API easier and more convenient. Current version is 0.7.1, with no recent releases (last release 2014-07-14). Considered in maintenance mode.

pip install slumber
error AttributeError: 'NoneType' object has no attribute 'get'
cause Resource not found or URL incorrect, resulting in None response.
fix
Check the API URL and endpoint. Use api.users.get() with parentheses.
error TypeError: 'Resource' object is not callable
cause Trying to call a resource object directly instead of using `.get()`, `.post()`, etc.
fix
Use api.users.get() instead of api.users().
error ImportError: No module named slumber
cause Slumber is not installed or installed in a different environment.
fix
Run pip install slumber and ensure you are using the correct Python environment.
breaking Slumber 0.7.x changed resource creation: previously you could call `api.users.get()` directly, but now you must use `api.users.get()` (with parentheses) to trigger a GET request. Older versions allowed `api.users.get` without parentheses.
fix Always call resource methods with parentheses: `api.users.get()` not `api.users.get`.
deprecated Authentication via `slumber.API(url, auth=(user, pass))` works but is considered deprecated in favor of passing a `requests.Session` with auth configured.
fix Use `session = requests.Session(); session.auth = (user, pass); api = API(url, session=session)`.
gotcha Slumber does not support async/await. It is synchronous only. If you need async, consider using `httpx` or `aiohttp` based clients.
fix Use a different library for async workflows.
gotcha Resource paths with trailing slashes may cause unexpected 301 redirects. Slumber does not normalize trailing slashes automatically.
fix Ensure your API URLs do not have trailing slashes, or handle redirects explicitly.

Create an API instance and access resources via attribute chaining.

from slumber import API

# Replace with your API URL
api = API('https://api.example.com', auth=('username', 'password'))
# If no authentication:
# api = API('https://api.example.com')

users = api.users.get()
print(users)
# For a specific resource:
# user = api.users(1).get()