smart-rest-client


Namesmart-rest-client JSON
Version 0.4.3 PyPI version JSON
download
home_pagehttps://github.com/rhenter/smart-rest-client
SummaryPython wrapper to perform requests to Rest APIs using objects to request endpoints and their methods
upload_time2023-06-01 17:54:10
maintainer
docs_urlNone
authorRafael Henter
requires_python
license
keywords rest api client python
VCS
bugtrack_url
requirements pysimplemodel requests unipath
Travis-CI No Travis.
coveralls test coverage No coveralls.
            `Para visualizar o README em português <https://github.com/rhenter/smart-rest-client/blob/master/README.pt.rst>`_.


=================
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:

.. code:: shell

    $ pip install smart-rest-client


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

.. code:: shell

    $ 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:

.. code-block:: python

  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)


.. note::
   - The name of this variable will be the name of the client that you can use throughout your project
   - It is recommended that the production use a set of configurations without configurations.py to change the simple way or the name of the API without the need to create several.
   - In our case, we have the option of "production" and "localhost", the factory generates the customer according to the name used and the parameters identified in it


* 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:

.. code-block:: text

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

- List:

.. code-block:: python

  usage: api_client.user.users.list()
  return: Response of GET to /user/users/

- Get/Retrieve/Detail:

.. code-block:: python

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

- Update:

.. code-block:: python

  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:

.. code-block:: python

  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

.. code-block:: python

    >> 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 <https://rhenter.github.io/smart-rest-client/>`_


Contributing
============

Please send pull requests, very much appreciated.


1. Fork the `repository <https://github.com/rhenter/smart-rest-client>`_ 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


.. |Docs| image:: https://img.shields.io/static/v1?label=DOC&message=GitHub%20Pages&color=%3CCOLOR%3E
   :target: https://rhenter.github.io/smart-rest-client/
.. |PyPI Version| image:: https://img.shields.io/pypi/pyversions/smart-rest-client.svg?maxAge=60
   :target: https://pypi.python.org/pypi/smart-rest-client
.. |PyPI License| image:: https://img.shields.io/pypi/l/smart-rest-client.svg?maxAge=120
   :target: https://github.com/rhenter/smart-rest-client/blob/master/LICENSE
.. |PyPI latest| image:: https://img.shields.io/pypi/v/smart-rest-client.svg?maxAge=120
   :target: https://pypi.python.org/pypi/smart-rest-client
.. |CicleCI Status| image:: https://circleci.com/gh/rhenter/smart-rest-client.svg?style=svg
   :target: https://circleci.com/gh/rhenter/smart-rest-client
.. |Open Source? Yes!| image:: https://badgen.net/badge/Open%20Source%20%3F/Yes%21/blue?icon=github
   :target: https://github.com/rhenter/smart-rest-client



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/rhenter/smart-rest-client",
    "name": "smart-rest-client",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "rest api client python",
    "author": "Rafael Henter",
    "author_email": "rafael@henter.com.br",
    "download_url": "https://files.pythonhosted.org/packages/17/97/f58bfa0e6194f2bf723e3d66c16212cd1beb7a6db3007d021f6ca45febb4/smart-rest-client-0.4.3.tar.gz",
    "platform": null,
    "description": "`Para visualizar o README em portugu\u00eas <https://github.com/rhenter/smart-rest-client/blob/master/README.pt.rst>`_.\n\n\n=================\nSmart REST Client\n=================\n\n|PyPI latest| |PyPI Version| |PyPI License| |Docs| |Open Source? Yes!|\n\nPython wrapper to perform requests to Rest APIs using objects to request endpoints and their methods\n\n\nRequirements\n============\n\n- Python 3.x\n\n\nHow to install\n==============\n\nYou can get Smart Rest Client by using pip:\n\n.. code:: shell\n\n    $ pip install smart-rest-client\n\n\nIf you want to install it from source, grab the git repository from GitHub and run setup.py:\n\n.. code:: shell\n\n    $ git clone git@github.com:rhenter/smart-rest-client.git\n    $ cd smart-rest-client\n    $ python setup.py install\n\n\nSettings\n========\n\n* 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:\n\n.. code-block:: python\n\n  from smart_rest_client.client import api_client_factory\n  from smart_rest_client.settings import APIClientSettings\n\n  API_CLIENT_SETTINGS = {\n      'API': [\n        {\n            'NAME': 'production',\n            'BASE_URL': 'https://example.com',\n            'ENDPOINTS': [\n                '/v1/order/orders',\n                '/v1/user/users',\n                ...\n            ],\n            'AUTHENTICATION_ACCESS_TOKEN': 'TOKEN'\n        },\n        {\n            'NAME': 'localhost',\n            'BASE_URL': 'http://localhost:8001',\n            'ENDPOINTS': [\n                '/v1/order/orders',\n                '/v1/user/users',\n                ...\n            ],\n            'AUTHENTICATION_ACCESS_TOKEN': 'TOKEN'\n        }\n      ]\n    }\n\n\n  api_settings = APIClientSettings(API_CLIENT_SETTINGS)\n  api_client = api_client_factory('production', api_settings)\n\n\n.. note::\n   - The name of this variable will be the name of the client that you can use throughout your project\n   - It is recommended that the production use a set of configurations without configurations.py to change the simple way or the name of the API without the need to create several.\n   - In our case, we have the option of \"production\" and \"localhost\", the factory generates the customer according to the name used and the parameters identified in it\n\n\n* Now we are going to list the data using the normal Django template system\n\nLet's imagine which client is located in a folder called clients on project folder (folder containing the settings.py file)\n\nUsage\n=====\n\nFor each endpoint the client Factory will create the follow structure:\n\nExample to ``/user/users/``\n\n- Create:\n\n.. code-block:: text\n\n  usage: api_client.user.users.create(data=data)\n  return: Response of POST of data (dict) to /user/users/\n\n- List:\n\n.. code-block:: python\n\n  usage: api_client.user.users.list()\n  return: Response of GET to /user/users/\n\n- Get/Retrieve/Detail:\n\n.. code-block:: python\n\n  usage: api_client.user.users.get(id=123)\n  return: Response of GET to /user/users/123/\n\n- Update:\n\n.. code-block:: python\n\n  usage: api_client.user.users.update(id=123, data=data, partial=False)\n  return: the response of UPDATE or PATCH of data (dict) to /user/users/123/\n\n- Delete:\n\n.. code-block:: python\n\n  usage: api_client.user.users.delete(id=123)\n  return: Response of GET to /user/users/123/\n\n\nExample\n=======\n\n- Import the api_client from your client file\n\n.. code-block:: python\n\n    >> from client import api_client\n    >> result = api_client.user.users.list()\n    >>\n    >> # Use the result as object\n    >> print(result.as_obj())\n    UserUsers(\n        previous=None,\n        count=1,\n        next=None,\n        results=[\n            NamelessModel(occupation=None, full_name='Admin System',\n                image=None, cpf='', is_superuser=True, cellphone='', email='', sex=None, username='admin', birthdate='09/09/1999',\n                logged_as='', id=1, is_temp=False, is_active=True)\n        ]\n    )\n    >>\n    >> # Use the result as dict\n    >> print(result.as_dict())\n    {'count': 1,\n     'next': None,\n     'previous': None,\n     'results': [{'id': 1,\n       'username': 'admin',\n       'full_name': 'Admin System',\n       'sex': None,\n       'birthdate': '09/09/1999',\n       'cpf': '',\n       'cellphone': '',\n       'email': '',\n       'image': None,\n       'occupation': None,\n       'logged_as': '',\n       'is_superuser': True,\n       'is_active': True,\n       'is_temp': False}\n      ]\n     }\n\n\nDocumentation\n=============\n\nCheck out the latest ``smart-rest-client`` documentation at `Github Pages <https://rhenter.github.io/smart-rest-client/>`_\n\n\nContributing\n============\n\nPlease send pull requests, very much appreciated.\n\n\n1. Fork the `repository <https://github.com/rhenter/smart-rest-client>`_ on GitHub.\n2. Make a branch off of master and commit your changes to it.\n3. Install requirements. ``pip install -r requirements-dev.txt``\n4. Install pre-commit. ``pre-commit install``\n5. Create a Pull Request with your contribution\n\n\n.. |Docs| image:: https://img.shields.io/static/v1?label=DOC&message=GitHub%20Pages&color=%3CCOLOR%3E\n   :target: https://rhenter.github.io/smart-rest-client/\n.. |PyPI Version| image:: https://img.shields.io/pypi/pyversions/smart-rest-client.svg?maxAge=60\n   :target: https://pypi.python.org/pypi/smart-rest-client\n.. |PyPI License| image:: https://img.shields.io/pypi/l/smart-rest-client.svg?maxAge=120\n   :target: https://github.com/rhenter/smart-rest-client/blob/master/LICENSE\n.. |PyPI latest| image:: https://img.shields.io/pypi/v/smart-rest-client.svg?maxAge=120\n   :target: https://pypi.python.org/pypi/smart-rest-client\n.. |CicleCI Status| image:: https://circleci.com/gh/rhenter/smart-rest-client.svg?style=svg\n   :target: https://circleci.com/gh/rhenter/smart-rest-client\n.. |Open Source? Yes!| image:: https://badgen.net/badge/Open%20Source%20%3F/Yes%21/blue?icon=github\n   :target: https://github.com/rhenter/smart-rest-client\n\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Python wrapper to perform requests to Rest APIs using objects to request endpoints and their methods",
    "version": "0.4.3",
    "project_urls": {
        "Homepage": "https://github.com/rhenter/smart-rest-client"
    },
    "split_keywords": [
        "rest",
        "api",
        "client",
        "python"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9c5eb4c1bb76b65a16385b87a80740c75af435ba4795448f7e5011e83cc6e45b",
                "md5": "634f2af3db5ee78d71c5b363e9e2484e",
                "sha256": "3342f0348488fb4c645be17c6e0e2416f0a3bd3b7d72b08d89c708d3145f2e89"
            },
            "downloads": -1,
            "filename": "smart_rest_client-0.4.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "634f2af3db5ee78d71c5b363e9e2484e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 15070,
            "upload_time": "2023-06-01T17:54:07",
            "upload_time_iso_8601": "2023-06-01T17:54:07.897687Z",
            "url": "https://files.pythonhosted.org/packages/9c/5e/b4c1bb76b65a16385b87a80740c75af435ba4795448f7e5011e83cc6e45b/smart_rest_client-0.4.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "1797f58bfa0e6194f2bf723e3d66c16212cd1beb7a6db3007d021f6ca45febb4",
                "md5": "c10c9adcea253831b7f668543af87bed",
                "sha256": "aa75426101f62802c4d1b9393afa5dc8467ca9956881cce4559c8383467df1ed"
            },
            "downloads": -1,
            "filename": "smart-rest-client-0.4.3.tar.gz",
            "has_sig": false,
            "md5_digest": "c10c9adcea253831b7f668543af87bed",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 61749,
            "upload_time": "2023-06-01T17:54:10",
            "upload_time_iso_8601": "2023-06-01T17:54:10.402137Z",
            "url": "https://files.pythonhosted.org/packages/17/97/f58bfa0e6194f2bf723e3d66c16212cd1beb7a6db3007d021f6ca45febb4/smart-rest-client-0.4.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-06-01 17:54:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "rhenter",
    "github_project": "smart-rest-client",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "circle": true,
    "requirements": [
        {
            "name": "pysimplemodel",
            "specs": [
                [
                    "==",
                    "2.3.3"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": []
        },
        {
            "name": "unipath",
            "specs": []
        }
    ],
    "lcname": "smart-rest-client"
}
        
Elapsed time: 0.11953s