Skip to main content

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>

Metadata

Release files for eater 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for eater 0.4.0
File Size Uploaded
eater-0.4.0.tar.gz 930.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for eater 0.4.0
File Interpreter ABI Platform
eater-0.4.0-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 942.2 kB

Release files / eater-0.4.0.tar.gz

Download URL eater-0.4.0.tar.gz
Size 930.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4697bf2e9b1c96defa5dec11ea64b3ebe933f75d54d8f509aaabfa260b8b959a
BLAKE2b-256 checksum
How to use checksums
c4084173360f04f79a138fcdce7365de70204c0ef2fb2500b358cdb7144bb81e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / eater-0.4.0-py2.py3-none-any.whl

Download URL eater-0.4.0-py2.py3-none-any.whl
Size 11.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
48a0467199d0e00297da3c86bbfdbba99d3171698704239fcfa3087c20eb3a67
BLAKE2b-256 checksum
How to use checksums
99b946e0387496a0390c5fb0a4b580bb55579d3df09629b16df8d97400c549e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page