| 
1 |  | -[](https://travis-ci.org/TokTok/py-toxcore-c)  | 
2 |  | -[](https://coveralls.io/github/TokTok/py-toxcore-c?branch=master)  | 
3 |  | - | 
4 | 1 | # PyTox  | 
5 | 2 | 
 
  | 
6 | 3 | Python binding for [Project Tox](https://github.com/TokTok/c-toxcore).  | 
7 | 4 | 
 
  | 
8 |  | -Docker hub: <https://hub.docker.com/r/toxchat/py-toxcore-c/>  | 
9 |  | - | 
10 |  | -```sh  | 
11 |  | -docker pull toxchat/py-toxcore-c  | 
12 |  | -```  | 
13 |  | - | 
14 |  | -PyTox provides a Pythonic binding, i.e Object-oriented instead of C style, raise  | 
15 |  | -exception instead of returning error code. A simple example is as follows:  | 
16 |  | - | 
17 |  | -```python  | 
18 |  | -from pytox import Tox  | 
19 |  | - | 
20 |  | -class ToxOptions(object):  | 
21 |  | -    def __init__(self):  | 
22 |  | -        self.ipv6_enabled = True  | 
23 |  | -        self.udp_enabled = True  | 
24 |  | -        self.proxy_type = 0  # 1=http, 2=socks  | 
25 |  | -        self.proxy_host = ''  | 
26 |  | -        self.proxy_port = 0  | 
27 |  | -        self.start_port = 0  | 
28 |  | -        self.end_port = 0  | 
29 |  | -        self.tcp_port = 0  | 
30 |  | -        self.savedata_type = 0  # 1=toxsave, 2=secretkey  | 
31 |  | -        self.savedata_data = b''  | 
32 |  | -        self.savedata_length = 0  | 
33 |  | - | 
34 |  | - | 
35 |  | -class EchoBot(Tox):  | 
36 |  | -    def __init__(self, opts):  | 
37 |  | -        super(EchoBot, self).__init__(opts)  | 
38 |  | - | 
39 |  | -    def loop(self):  | 
40 |  | -        while True:  | 
41 |  | -            self.iterate()  | 
42 |  | -            time.sleep(0.03)  | 
43 |  | - | 
44 |  | -    def on_friend_request(self, pk, message):  | 
45 |  | -        print 'Friend request from %s: %s' % (pk, message)  | 
46 |  | -        self.friend_add_norequest(pk)  | 
47 |  | -        print 'Accepted.'  | 
48 |  | - | 
49 |  | -    def on_friend_message(self, fid, message):  | 
50 |  | -        name = self.self_get_name(fid)  | 
51 |  | -        print '%s: %s' % (name, message)  | 
52 |  | -        print 'EchoBot: %s' % message  | 
53 |  | -        self.friend_send_message(fid, Tox.MESSAGE_TYPE_NORMAL, message)  | 
54 |  | - | 
55 |  | - | 
56 |  | -EchoBot(ToxOptions()).loop()  | 
57 |  | -```  | 
58 |  | - | 
59 |  | -As you can see callbacks are mapped into class method instead of using it the  | 
60 |  | -the c ways. For more details please refer to  | 
61 |  | -[examples/echo.py](https://github.com/TokTok/py-toxcore-c/blob/master/examples/echo.py).  | 
62 |  | - | 
63 |  | -## Getting started  | 
64 |  | - | 
65 |  | -To get started, a Makefile is provided to run PyTox inside a docker container:  | 
66 |  | - | 
67 |  | -- `make test`: This will launch tests in a container.  | 
68 |  | -- `make run`: This will launch an interactive container with PyTox installed.  | 
69 |  | -- `make echobot`: This will launch the example echobot in a container.  | 
70 |  | - | 
71 |  | -## Examples  | 
72 |  | - | 
73 |  | -- [echo.py](https://github.com/TokTok/py-toxcore-c/blob/master/examples/echo.py):  | 
74 |  | -  A working echo bot that wait for friend requests, and than start echoing  | 
75 |  | -  anything that friend send.  | 
76 |  | - | 
77 |  | -## Documentation  | 
78 |  | - | 
79 |  | -Full API documentation can be read [here](http://aitjcize.github.io/PyTox/).  | 
80 |  | - | 
81 |  | -## Todo  | 
82 |  | - | 
83 |  | -- Complete API binding (use tools/apicomplete.py to check)  | 
84 |  | -- Unittest for ToxAV  | 
85 |  | - | 
86 |  | -## Contributing  | 
87 |  | - | 
88 |  | -1.  Fork it  | 
89 |  | -2.  Create your feature branch (`git checkout -b my-new-feature`)  | 
90 |  | -3.  Commit your changes (`git commit -am 'Add some feature'`)  | 
91 |  | -4.  Push to the branch (`git push origin my-new-feature`)  | 
92 |  | -5.  Create new Pull Request  | 
 | 5 | +TODO: Docs.  | 
0 commit comments