.. class:: API([auth_handler=None], [host='api.twitter.com'], [cache=None], \
[api_root='/1'], , [retry_count=0], [retry_delay=0], \
[retry_errors=None], [timeout=60], [parser=ModelParser], \
- [compression=False], [wait_on_rate_limit=False], \
- [wait_on_rate_limit_notify=False], [proxy=None])
+ [compression=False], [wait_on_rate_limit=False], [proxy=None])
This class provides a wrapper for the API as provided by Twitter.
The functions provided in this class are listed below.
:param compression: Whether or not to use GZIP compression for requests
:param wait_on_rate_limit: Whether or not to automatically wait for rate
limits to replenish
- :param wait_on_rate_limit_notify: Whether or not to print a notification
- when Tweepy is waiting for rate limits to
- replenish
:param proxy: The full url to an HTTPS proxy to use for connecting to
Twitter.
host='api.twitter.com', upload_host='upload.twitter.com',
cache=None, api_root='/1.1', upload_root='/1.1',
retry_count=0, retry_delay=0, retry_errors=None, timeout=60,
- parser=None, wait_on_rate_limit=False,
- wait_on_rate_limit_notify=False, proxy=''):
+ parser=None, wait_on_rate_limit=False, proxy=''):
"""
API instance constructor
default: None
:param wait_on_rate_limit: If the api wait when it hits the rate limit,
default: False
- :param wait_on_rate_limit_notify: If the api print a notification when
- the rate limit is hit, default: False
:param proxy: Url to use as proxy during the HTTP request, default: ''
:raise TypeError: If the given parser is not a ModelParser instance.
self.retry_errors = retry_errors
self.timeout = timeout
self.wait_on_rate_limit = wait_on_rate_limit
- self.wait_on_rate_limit_notify = wait_on_rate_limit_notify
self.parser = parser or ModelParser()
self.proxy = {}
if proxy:
# Handle running out of API calls
sleep_time = reset_time - int(time.time())
if sleep_time > 0:
- if api.wait_on_rate_limit_notify:
- log.warning(f"Rate limit reached. Sleeping for: {sleep_time}")
+ log.warning(f"Rate limit reached. Sleeping for: {sleep_time}")
time.sleep(sleep_time + 1) # Sleep for extra sec
# Apply authentication