Skip to main content

Consume APIs and hold them to account.

Project description

Consume APIs and hold them to account.

Build Status Code Health Code Coverage Documentation Status Latest Version Supported Python versions

Not every API provider has an API as nice as Stripe and often their documentation is incorrect or (arguably better) non-existent.

Not every API provider can manage their release cycle, like inform customers, conform to semantic version numbers etc..

Chances are, if you’re reading this, you’re trying to talk to an API just like this.

You want to be sure, when you send them something, they give you the right thing back. That is, it contains the write shape of data and the correct data types and if you’re really persnickety, that it validates against defined rules.

Well, this Python library, with the help of schematics, will allow you to do just that.

Install

pip install eater

Usage

Not that this has ever happened to anyone, ever… but let’s say you are dealing with an API that you don’t necessarily trust. Perhaps the API is in flux because it’s alpha/beta or perhaps it’s not versioned and changes get made without notifying users. In any case, you want to be sure that what it says it does, it definitely does.

Using eater, first you define the API to be consumed, in part using schematics models.

import eater
from schematics import Model, IntegerType, StringType, BooleanType, ListType, ModelType

class Book(Model):
    title = StringType(required=True, min_length=3)


class Request(Model):
    """
    Represents, as a Python object, the JSON data required by the API.
    """
    in_print = BooleanType()


class Response(Model):
    """
    Represents, as a Python object, the JSON response returned by the API.
    """
    books = ListType(ModelType(Book))

class BooksAPI(eater.HTTPEater):
    url = 'https://example.com/books/'
    request_cls = Request
    response_cls = Response

You can then consume the API;

api = BooksAPI()
response = api(in_print=True)

for book in response.books:
    print(book.title)

See the full documentation at https://readthedocs.org/projects/eater

Author

Alex Hayes <alex@alution.com>

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

eater-0.3.0.tar.gz (924.6 kB view details)

Uploaded Source

Built Distribution

eater-0.3.0-py2.py3-none-any.whl (10.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file eater-0.3.0.tar.gz.

File metadata

  • Download URL: eater-0.3.0.tar.gz
  • Upload date:
  • Size: 924.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for eater-0.3.0.tar.gz
Algorithm Hash digest
SHA256 c9dbe08eccb6bbd815e95fdf986827a356117d7fe5286edbc4eea2bb7fef8043
MD5 aef45354af4147f10987960b40f4e5a4
BLAKE2b-256 e326ed4faa7eea7e4205a949bbebe33a3ffd0e2c4235023e2eb89d89889d5cca

See more details on using hashes here.

File details

Details for the file eater-0.3.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for eater-0.3.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 330793111d395d4b3deff118881b07c750ef5bb7f0c6cfdc5eaf57e0c2bfe9b6
MD5 4b33959c307fcb4e9073c27b6bafa97a
BLAKE2b-256 ee1b8914e16a7ba936cee369d3dc76ff3fb09fe12e384d4c3a4e8331a8ce33ab

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