8 The latest release of python-musicpd can be found at
9 http://pypi.python.org/pypi/python-musicpd.
12 Getting the latest source code
13 ------------------------------
15 If you would instead like to use the latest source code, you can grab a copy
16 of the development version from git by running the command:
18 git clone git://git.kaliko.me/python-musicpd.git
21 Installing from source
22 ----------------------
24 To install python-musicpd from source, simply run the command::
26 python3 setup.py install
28 You can use the `--help` switch to `setup.py` for a complete list of commands
29 and their options. See the `Installing Python Modules`_ document for more details.
32 Using the client library
33 ------------------------
35 The client library can be used as follows::
37 client = musicpd.MPDClient() # create client object
38 client.connect('localhost', 6600) # connect to localhost:6600
39 print client.mpd_version # print the mpd version
40 print client.cmd('one', 2) # print result of the command "cmd one 2"
41 client.close() # send the close command
42 client.disconnect() # disconnect from the server
44 A list of supported commands, their arguments (as MPD currently understands
45 them), and the functions used to parse their responses can be found in
46 `doc/commands.txt`. See the `MPD protocol documentation`_ for more
49 Command lists are also supported using `command_list_ok_begin()` and
50 `command_list_end()` ::
52 client.command_list_ok_begin() # start a command list
53 client.update() # insert the update command into the list
54 client.status() # insert the status command into the list
55 results = client.command_list_end() # results will be a list with the results
57 Provide a 2-tuple as argument for command supporting ranges (cf. `MPD protocol documentation`_ for more details).
58 Possible ranges are: "START:END", "START:" and ":" ::
60 # An intelligent clear
61 # clears played track in the queue, currentsong included
62 pos = client.currentsong().get('pos', 0)
63 # the 2-tuple range object accepts str, no need to convert to int
64 client.delete((0, pos))
65 # missing end interpreted as highest value possible, pay attention still need a tuple.
66 client.delete((pos,)) # purge queue from current to the end
68 A notable case is the `rangeid` command allowing an empty range specified
69 as a single colon as argument (i.e. sending just ":")::
71 # sending "rangeid :" to clear the range, play everything
72 client.rangeid(()) # send an empty tuple
74 Empty start in range (i.e. ":END") are not possible and will raise a CommandError.
77 Commands may also return iterators instead of lists if `iterate` is set to
81 for song in client.playlistinfo():
84 Each command have a *send\_<CMD>* and a *fetch\_<CMD>* variant, which allows to
85 send a MPD command and then fetch the result later.
86 This is useful for the idle command::
88 >>> client.send_idle()
89 # do something else or use function like select()
90 # http://docs.python.org/howto/sockets.html#non-blocking-sockets
91 # ex. select([client], [], [])
92 >>> events = client.fetch_idle()
94 # more complex use for example, with glib/gobject:
95 >>> def callback(source, condition):
96 >>> changes = client.fetch_idle()
98 >>> return False # removes the IO watcher
100 >>> client.send_idle()
101 >>> gobject.io_add_watch(client, gobject.IO_IN, callback)
102 >>> gobject.MainLoop().run()
107 You can contact the original author by emailing J. Alexander Treuman
108 <jat⊘spatialrift.net>. He can also be found idling in #mpd on
109 irc.freenode.net as jat.
111 The current maintainer can be found on xmpp chat room <kaliko.me⊘conf.azylum.org>
112 or you can contact him by email/xmpp <kaliko⊘azylum.org>.
114 .. _Installing Python Modules: http://docs.python.org/3/install/
115 .. _MPD protocol documentation: http://www.musicpd.org/doc/protocol/