Skip to main content

Framework for making good API client libraries using urllib3.

Project description

Tiny framework for building good API client libraries thanks to urllib3.

Highlights

  • Threadsafely reuses connections with Keep-Alive (via urllib3).

  • Small and easy to understand codebase perfect for extending and building upon.

  • Built-in support for rate limiting and request throttling.

  • Functional examples for the Klout API and the Facebook OpenGraph API.

Examples

How to make your own super-simple client API library:

from apiclient import APIClient

class AcmePublicAPI(APIClient):
    BASE_URL = 'https://localhost:1234/'


acme_api = AcmePublicAPI()
r = acme_api.call('/stream') # <- Returns parsed JSON response

How to add rate limiting to your client API library so that we don’t exceed 10 requests per minute:

from apiclient import RateLimiter

lock = RateLimiter(max_messages=10, every_seconds=60)

acme_api = AcmePublicAPI(rate_limit_lock=lock)

# Get the first 100 pages
for page in xrange(100):
    # Whenever our request rate exceeds the specifications of the API's
    # RateLimiter, the next request will block until the next request window
    r = acme_api.call('/stream', page=str(page))

For more specific API examples, see the examples/ directory.

TODO

  • More documentation and examples.

  • Tests.

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

apiclient-1.0.tar.gz (2.9 kB view details)

Uploaded Source

File details

Details for the file apiclient-1.0.tar.gz.

File metadata

  • Download URL: apiclient-1.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for apiclient-1.0.tar.gz
Algorithm Hash digest
SHA256 ba6d761bf43f462c7dbec6c38f43448f2b2dc1d69dbcb8faae56af0041bca5ee
MD5 000edd2d9d1066a2a9e1cf72bb22c522
BLAKE2b-256 0db6c9a5252187cd2f66b3b418001e2eb842480e9f82f72063b7b64add635c25

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