Skip to main content

Python wrapper to perform requests to Rest APIs using objects to request endpoints and their methods

Project description

Para visualizar o README em português.

Smart REST Client

PyPI latest PyPI Version PyPI License Docs Open Source? Yes!

Python wrapper to perform requests to Rest APIs using objects to request endpoints and their methods

Requirements

  • Python 3.x

How to install

You can get Smart Rest Client by using pip:

$ pip install smart-rest-client

If you want to install it from source, grab the git repository from GitHub and run setup.py:

$ git clone git@github.com:rhenter/smart-rest-client.git
$ cd smart-rest-client
$ python setup.py install

Settings

  • Create a clients.py file in the core folder of your project, if you haven’t, created it within your project folder to be simple to be imported from anywhere in the project with the following content:

from smart_rest_client.client import api_client_factory
from smart_rest_client.settings import APIClientSettings

API_CLIENT_SETTINGS = {
    'API': [
      {
          'NAME': 'production',
          'BASE_URL': 'https://example.com',
          'ENDPOINTS': [
              '/v1/order/orders',
              '/v1/user/users',
              ...
          ],
          'AUTHENTICATION_ACCESS_TOKEN': 'TOKEN'
      },
      {
          'NAME': 'localhost',
          'BASE_URL': 'http://localhost:8001',
          'ENDPOINTS': [
              '/v1/order/orders',
              '/v1/user/users',
              ...
          ],
          'AUTHENTICATION_ACCESS_TOKEN': 'TOKEN'
      }
    ]
  }


api_settings = APIClientSettings(API_CLIENT_SETTINGS)
api_client = api_client_factory('production', api_settings)
  • Now we are going to list the data using the normal Django template system

Let’s imagine which client is located in a folder called clients on project folder (folder containing the settings.py file)

Usage

For each endpoint the client Factory will create the follow structure:

Example to /user/users/

  • Create:

usage: api_client.user.users.create(data=data)
return: Response of POST of data (dict) to /user/users/
  • List:

usage: api_client.user.users.list()
return: Response of GET to /user/users/
  • Get/Retrieve/Detail:

usage: api_client.user.users.get(id=123)
return: Response of GET to /user/users/123/
  • Update:

usage: api_client.user.users.update(id=123, data=data, partial=False)
return: the response of UPDATE or PATCH of data (dict) to /user/users/123/
  • Delete:

usage: api_client.user.users.delete(id=123)
return: Response of GET to /user/users/123/

Example

  • Import the api_client from your client file

>> from client import api_client
>> result = api_client.user.users.list()
>>
>> # Use the result as object
>> print(result.as_obj())
UserUsers(
    previous=None,
    count=1,
    next=None,
    results=[
        NamelessModel(occupation=None, full_name='Admin System',
            image=None, cpf='', is_superuser=True, cellphone='', email='', sex=None, username='admin', birthdate='09/09/1999',
            logged_as='', id=1, is_temp=False, is_active=True)
    ]
)
>>
>> # Use the result as dict
>> print(result.as_dict())
{'count': 1,
 'next': None,
 'previous': None,
 'results': [{'id': 1,
   'username': 'admin',
   'full_name': 'Admin System',
   'sex': None,
   'birthdate': '09/09/1999',
   'cpf': '',
   'cellphone': '',
   'email': '',
   'image': None,
   'occupation': None,
   'logged_as': '',
   'is_superuser': True,
   'is_active': True,
   'is_temp': False}
  ]
 }

Documentation

Check out the latest smart-rest-client documentation at Github Pages

Contributing

Please send pull requests, very much appreciated.

  1. Fork the repository on GitHub.

  2. Make a branch off of master and commit your changes to it.

  3. Install requirements. pip install -r requirements-dev.txt

  4. Install pre-commit. pre-commit install

  5. Create a Pull Request with your contribution

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

smart-rest-client-0.2.0.tar.gz (61.5 kB view details)

Uploaded Source

Built Distribution

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

smart_rest_client-0.2.0-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file smart-rest-client-0.2.0.tar.gz.

File metadata

  • Download URL: smart-rest-client-0.2.0.tar.gz
  • Upload date:
  • Size: 61.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

File hashes

Hashes for smart-rest-client-0.2.0.tar.gz
Algorithm Hash digest
SHA256 e21cd2f51f0be3e44650473551f0922c89946f33ba921bd2555462a9210a35ea
MD5 a3cf6292b90345b2dc789061cfb23a61
BLAKE2b-256 75d370d8d2b65bd035dbb99fadd1e82a684a8610d01f62386a6fd855eaed08a2

See more details on using hashes here.

File details

Details for the file smart_rest_client-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: smart_rest_client-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.8

File hashes

Hashes for smart_rest_client-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 28dd63ad75066954516d7dba405f8a1a7539ea309e9e5ebd2f39eec37f88d1a2
MD5 84209b22484d793d0253a605526ec87a
BLAKE2b-256 5257e1c4c3d40c0f73e4f2ea6e98bcc572df0212a3e27d7ab05ba63b1ae62f31

See more details on using hashes here.

Supported by

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