Simple, extendable base rest client for python
Project description
Rest Wrapper
Simple, extendable base rest client for python. I've rewritten this pattern time after time, figured I would just package it and install when necessary.
- GitHub repo: https://github.com/nat5142/rest-wrapper.git
- Documentation: https://rest-wrapper.readthedocs.io
- Free software: MIT
Features
Rest Wrapper provides a simple exposure of the requests
module. Just provide a base_url
to target and go from there:
from rest_wrapper import RestClient
client = RestClient('https://example.com/')
# make a GET request. just provide an endpoint to append it to your base_url
resp = client.get('users/1/info')
# POST request
resp = client.post('users', json={'name': 'nick', 'username': 'nat5142'}) # kwargs are passed directly to the request itself
# don't append, just request any full URL:
resp = client.get('https://www.google.com/search?q=cats', append_url=False)
Or, use the client to make constructing your own API Wrappers easier:
import os
from rest_wrapper import RestClient
class SomeApiWrapper(RestClient):
base_url = 'https://some-api.com/'
def authenticate(self):
# authenticate method is invoked at the end of the object intialization.
self.session.headers.update({
'X-Api-Key': os.environ['API_KEY']
})
client = SomeApiWrapper()
resp = client.get('/api/v1/users') # will request https://some-api.com/api/v1/users
Credits
This package was created with Cookiecutter and the fedejaure/cookiecutter-modern-pypackage project template.
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
rest_wrapper-0.0.1.tar.gz
(5.0 kB
view hashes)
Built Distribution
Close
Hashes for rest_wrapper-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54ac19ccbee1eacfe0d2e7b9f766acd8fc14e6ab753205f73eda09ad11d7e304 |
|
MD5 | d0028d37f69d44a72b4a9bd59ae92ab6 |
|
BLAKE2b-256 | 34c7dded0ddb22d7d2987befe1ff8a219f96bb74f8fe57234583a721c1b577fb |