1 <?xml version=
"1.0" encoding=
"utf-8" ?>
2 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns=
"http://www.w3.org/1999/xhtml" xml:
lang=
"en" lang=
"en">
5 <meta http-equiv=
"Content-Type" content=
"text/html; charset=utf-8" />
6 <meta name=
"generator" content=
"Docutils 0.5: http://docutils.sourceforge.net/" />
7 <title>libtorrent python binding
</title>
8 <meta name=
"author" content=
"Arvid Norberg, arvid@rasterbar.com" />
9 <link rel=
"stylesheet" href=
"style.css" type=
"text/css" />
12 <div class=
"document" id=
"libtorrent-python-binding">
13 <h1 class=
"title">libtorrent python binding
</h1>
14 <table class=
"docinfo" frame=
"void" rules=
"none">
15 <col class=
"docinfo-name" />
16 <col class=
"docinfo-content" />
18 <tr><th class=
"docinfo-name">Author:
</th>
19 <td>Arvid Norberg,
<a class=
"last reference" href=
"mailto:arvid@rasterbar.com">arvid
@rasterbar.com
</a></td></tr>
22 <div class=
"contents topic" id=
"table-of-contents">
23 <p class=
"topic-title first"><a name=
"table-of-contents">Table of contents
</a></p>
25 <li><a class=
"reference" href=
"#building" id=
"id1" name=
"id1">building
</a></li>
26 <li><a class=
"reference" href=
"#using" id=
"id2" name=
"id2">using
</a></li>
30 <h1><a id=
"building" name=
"building">building
</a></h1>
31 <p>Building the libtorrent python bindings will produce a shared library (DLL)
32 which is a python module that can be imported in a python program.
</p>
33 <p>The only supported build system for the bindings are currently boost build. To
34 set up your build environment, you need to add some settings to your
35 <tt class=
"docutils literal"><span class=
"pre">$BOOST_BUILD_PATH/user-config.jam
</span></tt>.
</p>
36 <p>Make sure your user config contains the following line:
</p>
37 <pre class=
"literal-block">
40 <p>Set the version to the version of python you have installed or want to use. If
41 you've installed python in a non-standard location, you have to add the prefix
42 path used when you installed python as a second option. Like this:
</p>
43 <pre class=
"literal-block">
44 using python :
2.3 : /usr ;
46 <p>The bindings require
<em>at least
</em> python version
2.2.
</p>
47 <p>For more information on how to install and set up boost-build, see the
48 <a class=
"reference" href=
"building.html#step-2-setup-bbv2">building libtorrent
</a> section.
</p>
49 <p>Once you have boost-build set up, you cd to the
<tt class=
"docutils literal"><span class=
"pre">bindings/python
</span></tt>
50 directory and invoke
<tt class=
"docutils literal"><span class=
"pre">bjam
</span></tt> with the apropriate settings. For the available
51 build variants, see
<a class=
"reference" href=
"building.html#step-3-building-libtorrent">libtorrent build options
</a>.
</p>
53 <pre class=
"literal-block">
54 $ bjam dht-support=on release link=static
56 <p>On Mac OS X, this will produce the following python module:
</p>
57 <pre class=
"literal-block">
58 bin/darwin-
4.0/release/dht-support-on/link-static/logging-none/threading-multi/libtorrent.so
62 <h1><a id=
"using" name=
"using">using
</a></h1>
63 <p>The python interface is nearly identical to the C++ interface. Please refer to
64 the
<a class=
"reference" href=
"manual.html">main library reference
</a>.
</p>
65 <p>For an example python program, see
<tt class=
"docutils literal"><span class=
"pre">client.py
</span></tt> in the
<tt class=
"docutils literal"><span class=
"pre">bindings/python
</span></tt>
67 <p>A very simple example usage of the module would be something like this:
</p>
68 <pre class=
"literal-block">
69 import libtorrent as lt
73 ses.listen_on(
6881,
6891)
75 e = lt.bdecode(open(
"test.torrent
", 'rb').read())
76 info = lt.torrent_info(e)
78 h = ses.add_torrent(info,
"./
", compact_mode = True)
80 while (not h.is_seed()):
83 state_str = ['queued', 'checking', 'connecting', 'downloading metadata', \
84 'downloading', 'finished', 'seeding', 'allocating']
85 print '%
.2f%% complete (down: %
.1f kb/s up: %
.1f kB/s peers: %d) %s' % \
86 (s.progress *
100, s.download_rate /
1000, s.upload_rate /
1000, \
87 s.num_peers, state_str[s.state])