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.

Files for apiclient, version 1.0
Filename, size File type Python version Upload date Hashes
Filename, size apiclient-1.0.tar.gz (2.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page