API Reference

The following section outlines the API of pytwot.

Note

This module uses the Python logging module to log to tell you what you are doing wrong, See Logging for more info.

Clients

Client

Environment

Environment

Webhook

Twitter Objects

These following objects are not meant to be create as an instance rather its for knowledge of what you can do with them.

User

Tweet

Space

List

Job

ClientAccount

Message

DirectMessage

WelcomeMessage

WelcomeMessageRule

Twitter Dataclass

These following section documented objects derive from dataclass folder and use dataclasses.dataclass decorator. The following objects are not meant to be create as an instance rather its for knowledge of what you can do with them.

ApplicationInfo

Attachments Objects

Locations Objects

Setting Objects

Space Objects

Embed Objects

Stream Objects

Compliance Objects

Message Object

Metrics Objects

Attachments

Attachments is a way to attach additional part to a message, this include tweet and direct message. You may contruct the following objects except CustomProfile and Geo. Consider using Client.create_custom_profile for making a custom profile attachment and Client.search_geo for searching a geo-location.

Media

CustomProfile

Poll

CTA

QuickReply

Geo

Files

SubFile

Streaming

Streaming is a way to stream in twitter for tweets! This differ with on_tweet_create, Stream can detech global tweets while on_tweet_create only detech tweets from subscription users.

Stream

StreamConnection

Oauth

Oauth is a way to authenticate a twitter user account. You can do this with 3 legged authentication via OauthSession.create_oauth_url() to create an oauth url and OauthSession.post_oauth_token() to post an oauth token and verifier. This also required in every request you’ve made for identification! This section will show you what you can do with oauth, You can use Client.http.oauth_session to get the client’s OauthSession.

OauthSession

Scope

Paginations

Some endpoints returns more objects but limits it to some pages. Using pagination classes like UserPagination and TweetPagination, you can change page and manage objects easily. Example:

pagination = client.account().fetch_following()
print("Page 1, object 1:", pagination.content[0])
pagination.next_page() #Change page to the next page
print("Page 2, object 2:", pagination.content[1])
pagination.previous_page() #Change page to the previous page
print("Page 1, object 3:", pagination.content[2])

#Pagination object stores page's content in a cache everytime you turn a page. You can use the pages property to get the zipped page number and the page content:
for page_number, page_content in pagination.pages:
    print(f"Page {page_number}, content: 1: {page_content[0]}")

Pagination

UserPagination

TweetPagination

ListPagination

MessagePagination

Relations

Relations is an object that returns from a user action or a tweet action. This include but not limited to: Tweet.like, Tweet.retweet, Tweet.hide, and User.follow.

RelationFollow

RelationLike

RelationRetweet

RelationHide

Entities

Objects derives from entities.py

Hashtag

UserMention

Url

Symbol

Event Objects

Event objects are objects returned by an event filled with the event data.

Event Type

Direct Message Events

Event objects thats related with direct message events.

Action Events

Action events are events trigger by or from a user

Event Reference

This section shows events listened to by Client. You can register an event using Client.event()

Example:

@client.event
def on_tweet_create(tweet):
    print(f"Someone posted a tweet: {tweet}")
pytwot.on_stream_connect(connection)

on_stream_connect is an event triggers when the client succesfuly connect to stream, this might trigger multiple times as a reconnect logic would trigger this event too.

Parameters

connection (StreamConnection) – The Stream connection.

pytwot.on_stream_disconnect(connection)

on_stream_disconnect is an event triggers when the client disconnect from stream.

Parameters

connection (StreamConnection) – The Stream connection.

pytwot.on_stream(tweet, connection)

on_stream is an event triggers when a stream return a tweet data.

Parameters
  • tweet (Tweet) – The data that’s going to be returns from the stream.

  • connection (StreamConnection) – The stream connection

pytwot.on_tweet_create(tweet)

on_tweet_create is an event triggers when a subscription user created a tweet.

Parameters

tweet (Tweet) – The Tweet that created by a subscription user.

pytwot.on_tweet_delete(tweet)

on_tweet_delete is an event triggers when a subscription user deleted a tweet.

Parameters

tweet (Tweet) – The Tweet that deleted by a subscription user.

pytwot.on_tweet_favorite(action)

on_tweet_favorite is an event triggers when someone likes/favorites the subscription user’s tweet.

Parameters

action (TweetFavoriteActionEvent) – The event action object information.

pytwot.on_user_revoke(action)

on_user_revoke is an event triggers when someone revoke the application access.

Parameters

action (UserRevokeEvent) – The event action object information.

pytwot.on_user_follow(action)

on_user_follow is an event triggers when someone follows the subscription user or the subscription user follows someone.

Parameters

action (UserFollowActionEvent) – The event action object information.

pytwot.on_user_unfollow(action)

on_user_unfollow is an event triggers when someone unfollows the subscription user.

Parameters

action (UserUnfollowActionEvent) – The event action object information.

pytwot.on_user_block(action)

on_user_block is an event triggers when someone blocks the subscription user.

Parameters

action (UserBlockActionEvent) – The event action object information.

pytwot.on_user_unblock(action)

on_user_unblock is an event triggers when someone unblocks the subscription user.

Parameters

action (UserUnblockActionEvent) – The event action object information.

pytwot.on_user_mute(action)

on_user_mute is an event triggers when someone mutes the subscription user.

Parameters

action (UserMuteActionEvent) – The event action object information.

pytwot.on_user_unmute(action)

on_user_unmute is an event triggers when someone unmutes the subscription user.

Parameters

action (UserUnmuteActionEvent) – The event action object information.

pytwot.on_direct_message(message)

on_direct_message is an event triggers when someone send a message to the subscription user or from the the subscription user.

Parameters

message (DirectMessage) – The DirectMessage that the subscription user sent or from the the subscription user.

pytwot.on_direct_message_read(action)

on_direct_message_read is an event triggers when someone read messages in the subscription user’s dm.

Parameters

action (DirectMessageReadEvent) – The event action object information.

pytwot.on_typing(action)

on_typing is an event triggers when someone trigger a typing animation in the subscription user dm.

Parameters

action (DirectMessageTypingEvent) – The event action object information.

Enums

All of these enums are a subclass of enum.Enum

class pytwot.MessageTypeEnum
DIRECT_MESSAGE

A direct message in twitter.

MESSAGE_TWEET

A public tweet.

MESSAGE_WELCOME_MESSAGE

A welcome message in a direct message.

MESSAGE_WELCOME_MESSAGE_RULE

A welcome message rule in a direct message.

class pytwot.SpaceState
live

indicates the space is live

scheduled

indicates the space is scheduled

class pytwot.ReplySetting
everyone

Everyone can reply.

mention_users

Only users who are mentioned in the tweet can reply.

following

Only people who are following the author of the tweet can reply.

class pytwot.ButtonType
web_url

A button type for opening a url.

class pytwot.ActionEventType
direct_message_read

A direct message read action event, this action event type returns by on_direct_message_read through the Event.type() attribute.

direct_message_typing

A direct message typing action event, this action event type returns by on_typing.

class pytwot.UserActionEventType
follow

A user follow action type returns by on_user_follow and on_user_unfollow.

block

A user block action type returns by on_user_block and on_user_unblock.

mute

A user mute action type returns by on_user_mute and on_user_unmute.

class pytwot.JobType
tweets

Indicates the job only support tweets id.

users

Indicates the job only support users id.

class pytwot.JobResultAction
delete

Indicates if the Job’s status is created.

null

For None value.

class pytwot.JobStatus
created

Indicates if the Job is created.

in_progress

Indicates if the Job is in_progress.

failed

Indicates if the Job is failed.

complete

Indicates if the Job is complete.

expired

Indicates if the Job is expired.

class pytwot.MediaType
photo

Indicates if the media is a photo.

video

Indicates if the media is a video.

gif

Indicates if the media is a gif.

class pytwot.Timezone
international_dateline_west

A timezone for Etc/GMT.

midway_island

A timezone for Pacific/Midway.

american_samoa

A timezone for Pacific/Pago_Pago.

hawaii

A timezone for Pacific/Honolulu.

alaska

A timezone for America/Juneau.

pacific_time

A timezone for America/Los_Angeles.

tijuana

A timezone for America/Tijuana.

mountain_time

A timezone for America/Denver.

arizona

A timezone for America/Phoenix.

chihuahua

A timezone for America/Chihuahua.

mazatlan

A timezone for America/Mazatlan.

central_time

A timezone for America/Chicago.

saskatchewan

A timezone for America/Regina.

guadalajara

A timezone for America/Mexico_City.

mexicoCity

A timezone for America/Mexico_City.

monterrey

A timezone for America/Monterrey.

central_america

A timezone for America/Guatemala.

eastern_time

A timezone for America/New_York.

indiana

A timezone for America/Indiana.

bogota

A timezone for America/Bogota.

lima

A timezone for America/Lima.

quito

A timezone for America/Lima.

atlantic_time

A timezone for America/Halifax.

caracas

A timezone for America/Caracas.

lapaz

A timezone for America/La_Paz.

santiago

A timezone for America/Santiago.

newfoundland

A timezone for America/St_Johns.

brasilia

A timezone for America/Sao_Paulo.

buenos_aires

A timezone for America/Argentina.

montevideo

A timezone for America/Montevideo.

georgetown

A timezone for America/Guyana.

puerto_rico

A timezone for America/Puerto_Rico.

greenland

A timezone for America/Godthab.

mid_atlantic

A timezone for Atlantic/South_Georgia.

azores

A timezone for Atlantic/Azores.

cape_verde

A timezone for Atlantic/Cape_Verde.

dublin

A timezone for Europe/Dublin.

edinburgh

A timezone for Europe/London.

lisbon

A timezone for Europe/Lisbon.

london

A timezone for Europe/London.

casablanca

A timezone for Africa/Casablanca.

monrovia

A timezone for Africa/Monrovia.

utc

A timezone for Etc/UTC.

belgrade

A timezone for Europe/Belgrade.

bratislava

A timezone for Europe/Bratislava.

budapest

A timezone for Europe/Budapest.

ljubljana

A timezone for Europe/Ljubljana.

prague

A timezone for Europe/Prague.

sarajevo

A timezone for Europe/Sarajevo.

skopje

A timezone for Europe/Skopje.

warsaw

A timezone for Europe/Warsaw.

zagreb

A timezone for Europe/Zagreb.

brussels

A timezone for Europe/Brussels.

copenhagen

A timezone for Europe/Copenhagen.

madrid

A timezone for Europe/Madrid.

paris

A timezone for Europe/Paris.

amsterdam

A timezone for Europe/Amsterdam.

berlin

A timezone for Europe/Berlin.

bern

A timezone for Europe/Zurich.

zurich

A timezone for Europe/Zurich.

rome

A timezone for Europe/Rome.

stockholm

A timezone for Europe/Stockholm.

vienna

A timezone for Europe/Vienna.

westCentralAfrica

A timezone for Africa/Algiers.

bucharest

A timezone for Europe/Bucharest.

cairo

A timezone for Africa/Cairo.

helsinki

A timezone for Europe/Helsinki.

kyiv

A timezone for Europe/Kiev.

riga

A timezone for Europe/Riga.

sofia

A timezone for Europe/Sofia.

tallinn

A timezone for Europe/Tallinn.

vilnius

A timezone for Europe/Vilnius.

athens

A timezone for Europe/Athens.

istanbul

A timezone for Europe/Istanbul.

minsk

A timezone for Europe/Minsk.

jerusalem

A timezone for Asia/Jerusalem.

harare

A timezone for Africa/Harare.

pretoria

A timezone for Africa/Johannesburg.

kaliningrad

A timezone for Europe/Kaliningrad.

moscow

A timezone for Europe/Moscow.

StPetersburg

A timezone for Europe/Moscow.

volgograd

A timezone for Europe/Volgograd.

samara

A timezone for Europe/Samara.

kuwait

A timezone for Asia/Kuwait.

riyadh

A timezone for Asia/Riyadh.

nairobi

A timezone for Africa/Nairobi.

baghdad

A timezone for Asia/Baghdad.

tehran

A timezone for Asia/Tehran.

abuDhabi

A timezone for Asia/Muscat.

muscat

A timezone for Asia/Muscat.

baku

A timezone for Asia/Baku.

tbilisi

A timezone for Asia/Tbilisi.

yerevan

A timezone for Asia/Yerevan.

kabul

A timezone for Asia/Kabul.

ekaterinburg

A timezone for Asia/Yekaterinburg.

islamabad

A timezone for Asia/Karachi.

karachi

A timezone for Asia/Karachi.

tashkent

A timezone for Asia/Tashkent.

chennai

A timezone for Asia/Kolkata.

kolkata

A timezone for Asia/Kolkata.

mumbai

A timezone for Asia/Kolkata.

newDelhi

A timezone for Asia/Kolkata.

kathmandu

A timezone for Asia/Kathmandu.

astana

A timezone for Asia/Dhaka.

dhaka

A timezone for Asia/Dhaka.

sriJayawardenepura

A timezone for Asia/Colombo.

almaty

A timezone for Asia/Almaty.

novosibirsk

A timezone for Asia/Novosibirsk.

rangoon

A timezone for Asia/Rangoon.

bangkok

A timezone for Asia/Bangkok.

hanoi

A timezone for Asia/Bangkok.

jakarta

A timezone for Asia/Jakarta.

krasnoyarsk

A timezone for Asia/Krasnoyarsk.

beijing

A timezone for Asia/Shanghai.

chongqing

A timezone for Asia/Chongqing.

hongKong

A timezone for Asia/Hong_Kong.

urumqi

A timezone for Asia/Urumqi.

kualaLumpur

A timezone for Asia/Kuala_Lumpur.

singapore

A timezone for Asia/Singapore.

taipei

A timezone for Asia/Taipei.

perth

A timezone for Australia/Perth.

irkutsk

A timezone for Asia/Irkutsk.

ulaanbaatar

A timezone for Asia/Ulaanbaatar.

seoul

A timezone for Asia/Seoul.

osaka

A timezone for Asia/Tokyo.

sapporo

A timezone for Asia/Tokyo.

tokyo

A timezone for Asia/Tokyo.

yakutsk

A timezone for Asia/Yakutsk.

darwin

A timezone for Australia/Darwin.

adelaide

A timezone for Australia/Adelaide.

canberra

A timezone for Australia/Melbourne.

melbourne

A timezone for Australia/Melbourne.

sydney

A timezone for Australia/Sydney.

brisbane

A timezone for Australia/Brisbane.

hobart

A timezone for Australia/Hobart.

vladivostok

A timezone for Asia/Vladivostok.

guam

A timezone for Pacific/Guam.

portMoresby

A timezone for Pacific/Port_Moresby.

magadan

A timezone for Asia/Magadan.

srednekolymsk

A timezone for Asia/Srednekolymsk.

solomon

A timezone for Pacific/Guadalcanal.

newCaledonia

A timezone for Pacific/Noumea.

fiji

A timezone for Pacific/Fiji.

kamchatka

A timezone for Asia/Kamchatka.

marshall

A timezone for Pacific/Majuro.

auckland

A timezone for Pacific/Auckland.

wellington

A timezone for Pacific/Auckland.

nukualofa

A timezone for Pacific/Tongatapu.

tokelau

A timezone for Pacific/Fakaofo.

chatham

A timezone for Pacific/Chatham.

samoa

A timezone for Pacific/Apia.

Errors

Error raised by pytwot.