RTMP library for Python

Updated 2012/06/11: The project is available on GitHub: rtmp-python
Updated 2012/03/25: Updated to work with newer version of PyAMF.
Updated 2010/10/30: Added an RTMPClient class that simplifies client applications. Also updated the assertions.

Recently I started investigating the RTMP, which is a protocol used by Adobe Flash for communication between the player and the server. The communication could involve either video, audio or plain data. Typically Abode Flash applications communicate with Adobe Flash Media Server.

The RTMP specification is available online but, unfortunatelly, it is not of high quality and does not discuss in depth how to implement a client and a server. For that reason, I started implementing a small library to support the RTMP for Python applications. Together with that, I have also developed a sample RTMP client and a sample RTMP server using this specific library. Portions of source code is taken from the RTMPy project.

Also, the library depends on the PyAMF project which provides support of the AMF binary format. AMF is a serialization format used when exchanging pieces of information over the wire. AMF is available in two versions: AMF 0 and AMF 3. This library is designed to use AMF 0, but should require minimal changes in order to use both.

You can download the RTMP library, the sample RTMP client and the sample RTMP server from GitHub: rtmp-python. They are all written in Python. Included you can find an ActionScript file accompanied by the compiled SWF that implement a sample RTMP client for testing purposes of the RTMP library.

17 Responses to “RTMP library for Python”

  1. Vitaliy Says:


    Promising library. Thank you! Been playing with it for some time…

    Can I ask how I should specify a stream name in “play” call?

    I’m using a RTMPlite as a Flash server (exceptionally for testing purposes). Command to start: python rtmp.py -d

    The code I’m using…

    from rtmp_python.rtmp_protocol import RtmpClient
    cl = RtmpClient(ip=”″, port=1935, tc_url=’rtmp://localhost/myapp’, page_url=”, swf_url=”, app=’myapp’)
    cl.call(proc_name=’play’, parameters=[‘user1’])

    From the server logs I see that connect is ok, createStream is ok as well but play does not really work…

    Many Thanks,
    – Vitaliy

  2. Microsoft_Tech Says:

    How on earth do we actually install this to make it usable?

    • prekageo Says:

      You need to download and install PyAMF from its website. Then you can download the Python source code of this library from GitHub.

  3. flurbyrock Says:

    This is awesome. I’ve managed to make a client connect using some of the code found here: http://stackoverflow.com/questions/7415509/simple-rtmp-python-client

    However, I’m getting an assertion error:
    ” File “/home/pi/Desktop/python/rtmp_python/rtmp_protocol.py”, line 483, in handle_message_pre_connect
    assert msg[‘window_ack_size’] == 2500000, msg
    AssertionError: {‘msg’: 6, ‘window_ack_size’: 64000L, ‘limit_type’: 0}”

    Can’t figure out what the issue is. Any help would be greatly appreciated.

  4. flurbyrock Says:

    After a little more digging, the Red5 server logs say the client is connecting ok. Trying with a different server, ‘window_ack_size’ value changes to ‘10000000L’.

    I am trying to connect to Red5 via python, but could use the rtmp_server implementation you provide if it fully supports sharedObjects and might fix this issue.

    Again, any help would be greatly appreciated. Nice to see a library getting python talking to such a powerful server standard.

  5. flurbyrock Says:

    Sorry prekageo, didn’t see your earlier reply. I’ll give that a try as soon as I can. My hope is to get a simple python RTMP client connected to one SO on a red5 server (local network). Then I can make some magic happen with Arduino over serial🙂

    I’ll report back here how it goes with the “pass”.

  6. flurbyrock Says:

    Hey, think I might be getting somewhere. I replaced the line you suggested and then found a similar error for the lines below that:

    assert msg[‘window_ack_size’] == 2500000, msg
    assert msg[‘limit_type’] == 2, msg

    Having replaced these lines the script connected and stayed stable for a good few seconds (maybe ten) before spitting this error…

    Traceback (most recent call last):
    File “client.py”, line 4, in
    File “/home/pi/Desktop/python/rtmp_python/rtmp_protocol.py”, line 520, in handle_messages
    msg = self.reader.next()
    File “/home/pi/Desktop/python/rtmp_python/rtmp_protocol.py”, line 106, in next
    assert next_header.datatype == -1, (header, next_header)
    AssertionError: (, )

    I went to line 106 and replaced with “pass” but that just pushed the error on to line 107. These assert statements seem to be a persistent problem. Is there a general rule I can follow in trying to make this work. Happy to share back results, I think a robust RTMP client for python could be really useful – I’m trying to build a nice internet of things platform here using raspberry pi/arduino/red5.

    Appreciate your thoughts!

    • prekageo Says:

      There is some kind of error happening inside the loop that starts at line 92. You are welcome to trace it and submit a pull request in GitHub.

    • Vitaliy Says:


      Can I ask if you’ve managed to connect and play the stream using the client from this library ?

      The handshake is not a problem but playing a stream might be a brain cracker🙂. I couldn’t guess the way of specifying right parameters in call method…

      Thank you

      • flurbyrock Says:

        Hey, I’m afraid I had to give up and move on to a different solution this time. I would like to return to this in the future, but my object was not to play a stream, instead I was trying to access a remote shared object to control some gameplay variables in a multi-user scenario.

        Good luck with your efforts!

      • Vitaliy Says:

        Thank you! Good luck.

  7. Bruno Blažinč Says:

    Has anybody had success connecting to red5 server? I can connect to the rtmp-python server, but not to red5. It starts connecting but seems to suspend when it calls the handshake method from RtmpClient.connect(). More exactly at line https://github.com/prekageo/rtmp-python/blob/master/rtmp_protocol.py#L412 .
    It seems to me that it is waiting for something, but I don’t know what.
    I have also been using the same code FLURBYROCK to try to connect http://stackoverflow.com/questions/7415509/simple-rtmp-python-client.

    Any help would be appreciated.

  8. Kajari Ghosh Dastidar Says:

    Hi prekageo! First of all, thanks a lot for providing such a wonderful utility!

    I have downloaded the project from GitHub and am able to run both server side and client side code successfully, without any visible errors.

    But I can’t see anything happening on screen. I have opened the swf file in browser, and it is showing “Connecting” forever. I have run the server and client files in the command line. The cursor is just blinking and nothing is happening.

    So, I don’t know what is happening. What is supposed to happen now, and how can I see if client server communication is happening properly or not?


  9. andikirana22 Says:

    can you give me, how to implement and test your project ? thansk

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: