Skip to main content

evc - Simple client for the EVE Python REST API Framework

Project description

Latest version on PyPi Supported Python versions Code style: black

evc

evc - a simple wrapper over "requests" HTTP library, which uses json format for transferring, with automatic decoding to the Python dictionary and back when executing HTTP requests to the REST-API server based on the "Eve" framework.


Contents: Installation | Requirements | Running the tests | Example of usage | Versioning | Authors | License


Getting Started

Installation

From pip

pip install --upgrade evc

Manual install

git clone https://github.com/evbg/evc.git
cd evc
python setup.py install

Installing directly from the repository on GitHub.com

pip install git+https://github.com/evbg/evc.git

Requirements

evc requires requests and simplejson libraries.

Running the tests

Evc has been tested on the following versions of Python: 2.7, 3.4, 3.5, 3.6, 3.7, pypy, pypy3.

Integration tests with the Eve framework

Prerequisites

To run tests on a localhost, it is necessary that the MongoDB service is started with access control disabled.

Running the tests via tox tool

git clone https://github.com/evbg/evc.git
cd evc
tox

Example of usage

The following example shows the use of evc through the Python interactive shell:

First, run the server "Eve"

    Python 2.7.5 (default, Mar  9 2014, 22:15:05)
    [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from eve import Eve
    >>> settings = {'XML': False, 'JSON': True, 'SERVER_NAME': '127.0.0.1:5555', 'MONGO_DBNAME': 'evc_test'}
    >>> settings['RESOURCE_METHODS'] = ['GET', 'POST', 'DELETE']
    >>> settings['ITEM_METHODS'] = ['GET', 'PATCH', 'PUT', 'DELETE']
    >>> settings['DOMAIN'] = {'persons': {'versioning': True, 'allow_unknown': True, 'schema': {}}}
    >>> app = Eve(settings=settings)
    >>> app.run()
     * Running on http://127.0.0.1:5555/ (Press CTRL+C to quit)

Second, run the client "Evc"

    Python 2.7.5 (default, Mar  9 2014, 22:15:05)
    Type "copyright", "credits" or "license" for more information.

    IPython 5.1.0 -- An enhanced Interactive Python.
    ?         -> Introduction and overview of IPython's features.
    %quickref -> Quick reference.
    help      -> Python's own help system.
    object?   -> Details about 'object', use 'object??' for extra details.

    In [1]: from evc import Evc

    In [2]: REST = Evc('http://127.0.0.1:5555')

    In [3]: type(REST.response)
    Out[3]: NoneType

    In [4]: REST.get()
    Out[4]: {u'_links': {u'child': [{u'href': u'persons', u'title': u'persons'}]}}

    In [5]: type(REST.response)
    Out[5]: requests.models.Response

    In [6]: REST.response.text
    Out[6]: u'{"_links": {"child": [{"href": "persons", "title": "persons"}]}}'

    In [7]: REST.response.json
    Out[7]: <bound method Response.json of <Response [200]>>

    In [8]: REST.response.json()
    Out[8]: {u'_links': {u'child': [{u'href': u'persons', u'title': u'persons'}]}}

    In [9]: REST.post('persons', {'name': 'Bob', 'email': 'bob@bobmail.com'})
    Out[9]:
    {u'_created': u'Tue, 25 Oct 2016 10:46:39 GMT',
     u'_etag': u'90d02265b8d7c832247fcaeacf11d1f4bbf8f0bc',
     u'_id': u'580f380fa7a3497495d72bd4',
     u'_latest_version': 1,
     u'_links': {u'self': {u'href': u'persons/580f380fa7a3497495d72bd4',
       u'title': u'Person'}},
     u'_status': u'OK',
     u'_updated': u'Tue, 25 Oct 2016 10:46:39 GMT',
     u'_version': 1}

    In [10]: REST.patch('persons', '580f380fa7a3497495d72bd4', '90d02265b8d7c832247fcaeacf11d1f4bbf8f0bc', {'name': 'Bob', 'email': 'bob2@bobmail.com'})
    Out[10]:
    {u'_created': u'Tue, 25 Oct 2016 10:46:39 GMT',
     u'_etag': u'50da6d8e759eeb0a32eaf0bd820dcfb729cdf5d9',
     u'_id': u'580f380fa7a3497495d72bd4',
     u'_latest_version': 2,
     u'_links': {u'self': {u'href': u'persons/580f380fa7a3497495d72bd4',
       u'title': u'Person'}},
     u'_status': u'OK',
     u'_updated': u'Tue, 25 Oct 2016 10:48:20 GMT',
     u'_version': 2}


    In [11]: REST.delete('persons', '580f380fa7a3497495d72bd4', '50da6d8e759eeb0a32eaf0bd820dcfb729cdf5d9')
    Out[11]: u''

    In [12]: REST.get('persons', '580f380fa7a3497495d72bd4')
    Out[12]:
    {u'_items': [],
     u'_links': {u'parent': {u'href': u'/', u'title': u'home'},
      u'self': {u'href': u'persons', u'title': u'persons'}},
     u'_meta': {u'max_results': 25, u'page': 1, u'total': 0}}

Versioning

We use SemVer for versioning.

Authors

  • Evgeny V. Bogodukhov - Initial work - evbg

License

This project is licensed under the MIT License - see the LICENSE file for details

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

evc-0.6.1.tar.gz (9.0 kB view details)

Uploaded Source

Built Distribution

evc-0.6.1-py2.py3-none-any.whl (8.5 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file evc-0.6.1.tar.gz.

File metadata

  • Download URL: evc-0.6.1.tar.gz
  • Upload date:
  • Size: 9.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.32.0 CPython/3.7.5

File hashes

Hashes for evc-0.6.1.tar.gz
Algorithm Hash digest
SHA256 137b55f740b315a1c82502ce51f54424b53c1248dd1ac48a66feccee1fb0e42d
MD5 33ca79ca3ad57485fff9ac05009943b4
BLAKE2b-256 bf76d9d975df4390d082d045e15ac058b8d478cc05b409cb3dbdad126ff1523e

See more details on using hashes here.

File details

Details for the file evc-0.6.1-py2.py3-none-any.whl.

File metadata

  • Download URL: evc-0.6.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.32.0 CPython/3.7.5

File hashes

Hashes for evc-0.6.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 c9663e88d86563051c230eee5a970bdc2f92b66bfe7eabfd7c7e8c346d61835c
MD5 f9232e6fd35031e918977684be4eed7b
BLAKE2b-256 ed13d6ddeee656493b0fa96b005fc14635d48f0468ca808450ef1e9cab8d89fd

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