
Product
Socket Now Supports pylock.toml Files
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Tiny framework for building good API client libraries thanks to
urllib3 <https://github.com/shazow/urllib3/>
_.
Klout API <https://github.com/shazow/apiclient/blob/master/examples/klout.py>
_
and the
Facebook OpenGraph API <https://github.com/shazow/apiclient/blob/master/examples/facebook.py>
_.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()
>>> acme_api.call('/hello')
{'what': 'world'}
>>> acme_api.call('/echo', params={"ping": "pong"})
{'ping': 'pong'}
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/ <https://github.com/shazow/apiclient/blob/master/examples/>
_ directory.
To handle different calling conventions, apiclient
can be extended through
subclassing.
For example, if an API requires that all arguments be JSON encoded, the
_compose_url
method could be implemented like this::
>>> class JSONArgsAPIClient(APIClient):
... def _compose_url(self, path, params=None):
... if params is not None:
... params = dict((key, json.dumps(val))
... for (key, val) in params.iteritems())
... return APIClient._compose_url(self, path, params=params)
Or if an API returns YAML instead of JSON, the _handle_response
method
could be overridden::
>>> class YAMLResponseAPIClient(APIClient):
... def _handle_response(self, response):
... return yaml.load(response.data)
Any contribution is highly encouraged and desired. :)
#. Fork on Github. #. Make the changes. Bonus points if changes include documentation and tests. #. Send a pull request.
If you're unsure if it's a good idea,
open an Issue <https://github.com/shazow/apiclient/issues>
_ or
contact me <https://github.com/inbox/new/shazow>
_ to discuss your proposal.
Extra juicy bonus points if you pick off some of the items in the TODO list.
MIT <https://github.com/shazow/apiclient/blob/master/LICENSE>
_
FAQs
Framework for making good API client libraries using urllib3.
We found that apiclient demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Socket now supports pylock.toml, enabling secure, reproducible Python builds with advanced scanning and full alignment with PEP 751's new standard.
Security News
Research
Socket uncovered two npm packages that register hidden HTTP endpoints to delete all files on command.
Research
Security News
Malicious Ruby gems typosquat Fastlane plugins to steal Telegram bot tokens, messages, and files, exploiting demand after Vietnam’s Telegram ban.