pytox.Tox Class

PyTox wraps libtoxcore API with the object pytox.Tox, all the tox API methods are in this class.

class pytox.Tox

ToxCore object

add_friend(address, message)

Add a friend.

add_friend_norequest(address)

Add a friend without sending request.

add_groupchat()

Creates a new groupchat and puts it in the chats array.

bootstrap_from_address(address, port, public_key)

Resolves address into an IP address. If successful, sends a ‘get nodes’request to the given node with ip, port.

count_chatlist()

Return the number of chats in the current Tox instance.

count_friendlist()

Return the number of friends.

del_friend(friend_number)

Remove a friend.

del_groupchat(group_number)

Delete a groupchat from the chats array.

do()

The main loop that needs to be run at least 20 times per second.

do_interval()

returns time (in ms) before the next tox_do() needs to be run on success.

file_data_remaining(friend_number, file_number, send_receive)

Give the number of bytes left to be sent/received. send_receive is 0 for sending and 1 for receiving.

file_data_size(friend_number)

Returns the recommended/maximum size of the filedata you send with file_send_data().

file_send_control(friend_number, send_receive, file_number, control_type[, data=None])

Send file transfer control.

send_receive is 0 for sending and 1 for receiving.

control_type can be one of following value:

control_type description
Tox.FILECONTROL_ACCEPT accepts transfer
Tox.FILECONTROL_PAUSE pause transfer
Tox.FILECONTROL_KILL kill/rejct transfer
Tox.FILECONTROL_FINISHED transfer finished
Tox.FILECONTROL_RESUME_BROKEN resume broken transfer
file_send_data(friend_number, file_number, data)

Send file data.

friend_exists(friend_number)

Checks if there exists a friend with given friendnumber.

get_address()

Return address to give to others.

get_chatlist()

Return a list of valid group numbers.

get_client_id(friend_number)

Return the public key associated to that friend number.

get_friend_connection_status(friend_number)

Return True if friend is connected(Online) else False.

get_friend_id(friend_id)

Return the friend id associated to that client id.

get_friendlist()

Get a list of valid friend numbers.

get_is_typing(friend_number)

Return True is user is typing.

get_keys()

Get the public and secret key from the Tox object. Return a tuple (public_key, secret_key)

get_last_online(friend_number)

returns datetime.datetime object representing the last time friend_number was seen online, or None if never seen.

get_name(friend_number)

Get nickname of friend_number.

get_name_size(friend_number)

Get nickname length of friend_number.

get_nospam()

get nospam part from ID

get_num_online_friends()

Return the number of online friends.

get_self_name()

Get your nickname.

get_self_name_size()

Get your nickname string length

get_self_status_message()

Get status message of yourself.

get_self_status_message_size()

Get status message string length of yourself.

get_self_user_status()

Get user status of youself.

get_status_message(friend_number)

Get status message of a friend.

get_status_message_size(friend_number)

Return the length of friend_number‘s status message.

get_user_status(friend_number)

Get friend status.

group_action_send(group_number, action)

send a group action.

group_get_names(group_number)

List all the peers in the group chat.

group_get_title(group_number)

Returns the title for group_number.

group_get_type(group_number)

Return the type of group, could be the following value:

type description
Tox.GROUPCHAT_TYPE_TEXT text chat
Tox.GROUPCHAT_TYPE_AV video chat
group_message_send(group_number, message)

send a group message.

group_number_peers(group_number)

Return the number of peers in the group chat.

group_peername(group_number, peer_number)

Get the group peer’s name.

group_set_title(group_number, title)

Sets the title for group.

invite_friend(friend_number, group_number)

Invite friendnumber to groupnumber.

isconnected()

Return False if we are not connected to the DHT.

join_groupchat(friend_number, data)

Join a group (you need to have been invited first.). Returns the group number of success.

kill()

Run this before closing shop.

load(blob)

Load the messenger from blob.

load_from_file(filename)

Load the messenger from file.

new_file_sender(friend_number, file_size, filename)

Send a file send request. Returns file number to be sent.

on_connection_status(friend_number, status)

Callback for receiving read receipt, default implementation does nothing.

status is a boolean value which indicates the status of the friend indicated by friend_number. True means online and False means offline after previously online.

on_file_control(friend_number, receive_send, file_number, control_type, data)

Callback for receiving file send control, default implementation does nothing. See file_send_control() for the meaning of receive_send and control_type.

on_file_data(friend_number, file_number, data)

Callback for receiving file data, default implementation does nothing.

on_file_send_request(friend_number, file_number, file_size, filename)

Callback for receiving file send requests, default implementation does nothing.

on_friend_action(friend_number, action)

Callback for receiving friend actions, default implementation does nothing.

on_friend_message(friend_number, message)

Callback for receiving friend messages, default implementation does nothing.

on_friend_request(address, message)

Callback for receiving friend requests, default implementation does nothing.

on_group_action(group_number, friend_group_number, action)

Callback for receiving group actions, default implementation does nothing.

on_group_invite(friend_number, type, group_public_key)

Callback for receiving group invitations, default implementation does nothing.

See also

group_get_type()

on_group_message(group_number, friend_group_number, message)

Callback for receiving group messages, default implementation does nothing.

on_group_namelist_change(group_number, peer_number, change)

Callback for receiving group messages, default implementation does nothing.

There are there possible change values:

change description
Tox.CHAT_CHANGE_PEER_ADD a peer is added
Tox.CHAT_CHANGE_PEER_DEL a peer is deleted
Tox.CHAT_CHANGE_PEER_NAME name of peer changed
on_name_change(friend_number, new_name)

Callback for receiving friend name changes, default implementation does nothing.

on_read_receipt(friend_number, receipt)

Callback for receiving read receipt, default implementation does nothing.

on_status_message(friend_number, new_status)

Callback for receiving friend status message changes, default implementation does nothing.

on_typing_change(friend_number, is_typing)

Callback for receiving friend status changes, default implementation does nothing.

on_user_status(friend_number, kind)

Callback for receiving friend status changes, default implementation does nothing.

save()

Return messenger blob in str.

save_to_file(filename)

Save the messenger to a file.

send_action(friend_number, action)

Send an action to an online friend.

send_message(friend_number, message)

Send a text chat message to an online friend.

set_name(name)

Set our nickname.

set_nospam(nospam)

set nospam part of ID. nospam should be of type uint32

set_status_message(message)

Set our user status message.

set_user_is_typing(friend_number, is_typing)

Set user typing status.

set_user_status(status)

Set our user status, status can have following values:

kind description
Tox.USERSTATUS_NONE the user is online
Tox.USERSTATUS_AWAY the user is away
Tox.USERSTATUS_BUSY the user is busy
Tox.USERSTATUS_INVALID invalid status
size()

return size of messenger data (for saving).

Previous topic

pytox.ToxAV Class

Next topic

pytox.ToxAV Class