Skip to main content

RTSP

CI codecov PyPI version Downloads Downloads License: MIT

        /((((((\\\\
=======((((((((((\\\\\
     ((           \\\\\\\
     ( (*    _/      \\\\\\\
       \    /  \      \\\\\\________________
        |  |   |      </    __             ((\\\\
        o_|   /        ____/ / _______       \ \\\\    \\\\\\\
             |  ._    / __/ __(_-</ _ \       \ \\\\\\\\\\\\\\\\
             | /     /_/  \__/___/ .__/       /    \\\\\\\     \\
     .______/\/     /           /_/           /         \\\
    / __.____/    _/         ________(       /\
   / / / ________/`---------'         \     /  \_
  / /  \ \                             \   \ \_  \
 ( <    \ \                             >  /    \ \
  \/      \\_                          / /       > )
           \_|                        / /       / /
                                    _//       _//
                                   /_|       /_|

A Pythonic RTSP client and microserver for video and computer vision work, from rapid prototyping to moderate-weight production. Pull frames from any RTSP stream or local capture device as Pillow images, preview streams in a window, or serve a frame buffer over RTSP with a single context manager. For multi-client distribution, pair it with a MediaMTX relay. For performance-intensive pipelines requiring high-throughput encoding or minimal latency, use OpenCV, GStreamer, or FFmpeg directly.

Features

  • read most-recent RTSP frame as Pillow Image on demand
  • preview stream in a tkinter window. 'q' or ESC to quit.
  • URI shortcuts for rapid prototyping
    • integers (or numeric strings) open a local capture device, e.g. rtsp.Client(0)
    • bare host strings default to rtsp://, e.g. rtsp.Client('192.168.1.1/stream')
    • Raspberry Pi camera: enable the V4L2 driver (dtoverlay=imx219 or similar in /boot/config.txt) and use rtsp.Client(0)
  • lightweight RTSP server
  • rtmp:// and rtmps:// URIs work with Client and Source using the same API as RTSP
  • enumerate local capture devices with rtsp.list_devices()

Examples

Client Use

Use RTSP access credentials in your connection string e.g.

RTSP_URL = f"rtsp://{USERNAME}:{PASSWORD}@192.168.1.221:554/11"

One-off Retrieval

import rtsp
client = rtsp.Client(rtsp_server_uri = 'rtsp://...', verbose=True)
client.read().show()
client.close()

Stream Preview

import rtsp
with rtsp.Client(0) as client: # previews USB webcam 0
    client.preview()

Continuous Retrieval

import rtsp

with rtsp.Client(rtsp_server_uri = 'rtsp://...') as client:
    _image = client.read()

    while True:
        process_image(_image)
        _image = client.read(raw=True)

Resize Retrieval Image

import rtsp

RTSP_URL = "rtsp://..."
client = rtsp.Client(rtsp_server_uri = RTSP_URL)

width = 640
height = 480

client.read().resize([width, height]).show()
client.close()

Rotate Retrieval Image

import rtsp

RTSP_URL = "rtsp://..."
client = rtsp.Client(rtsp_server_uri = RTSP_URL)

client.read().resize([client.read().size[0], client.read().size[0]]).rotate(90).resize([client.read().size[1], client.read().size[0]]).show()
client.close()

Save Retrieval Image (With the TimeStamp Format and Set Number of Save Image)

import rtsp
import datetime

RTSP_URL = "rtsp://..."
IMAGE_COUNT = 10

client = rtsp.Client(rtsp_server_uri = RTSP_URL)
while client.isOpened() and IMAGE_COUNT > 0:
    client.read().save("./"+ str(datetime.datetime.now()) +".jpg")
    IMAGE_COUNT = IMAGE_COUNT - 1
client.close()

Source Use

Serve frames locally and preview them. source.client_uri gives the address to connect to, and verbose=True logs the URI and fps on startup:

import rtsp

frames = ['frame1.jpg', 'frame2.jpg', 'frame3.jpg']

with rtsp.Source('rtsp://0.0.0.0:8554/live', fps=1,
                 frame_buffer=frames, verbose=True) as source:
    with rtsp.Client(source.client_uri) as client:
        client.preview()   # blocks; press q or ESC to quit

Serve without a viewer. serve_forever() blocks and loops the buffer indefinitely until Ctrl-C:

import rtsp

frames = ['frame1.jpg', 'frame2.jpg', 'frame3.jpg']

with rtsp.Source('rtsp://0.0.0.0:8554/live', frame_buffer=frames) as source:
    source.serve_forever()   # blocks; Ctrl-C to stop

Multi-client stream via MediaMTX relay. Also, frames can be added incrementally with put():

# Terminal: ./mediamtx          (listens on :8554 by default)

import rtsp

# serve=False pushes to the running MediaMTX relay.
# Any number of Client() instances can then read from the same URI.
with rtsp.Source('rtsp://localhost:8554/live', serve=False) as source:
    for frame in incoming_frames():
        source.put(frame)

# Elsewhere, any number of concurrent readers:
with rtsp.Client('rtsp://localhost:8554/live') as client:
    client.preview()

Metadata

Release files for rtsp 2.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for rtsp 2.0.3
File Size Uploaded
rtsp-2.0.3.tar.gz 66.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for rtsp 2.0.3
File Interpreter ABI Platform
rtsp-2.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 94.7 kB

Release files / rtsp-2.0.3.tar.gz

Download URL rtsp-2.0.3.tar.gz
Size 66.0 kB
Tags Source
SHA-256 checksum
How to use checksums
eb19a2104fafba1fefec5d23fb04a79441ec12f13914d3bb1c316484cee597bd
BLAKE2b-256 checksum
How to use checksums
84de168360b38a46977a6a47cb2c92475801cee416728c94c91b8d669987a623
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 16, 2026.

Transparency log

Release files / rtsp-2.0.3-py3-none-any.whl

Download URL rtsp-2.0.3-py3-none-any.whl
Size 28.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3b82f94b2d3e44bf23dbe11ba9b22e43d27ebd9381b879804473523c4ef1fd8f
BLAKE2b-256 checksum
How to use checksums
d3b362955239408ea9086c3103cb155557d257c12a587ebf05a09235e30a9e83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 16, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

2.0.3 This release

2 release files

2.0.2

2 release files

2.0.1

2 release files

2.0.0

2 release files

1.1.10

2 release files

1.1.9

2 release files

1.1.8

2 release files

1.1.7

2 release files

1.1.6

2 release files

1.1.5

2 release files

1.1.4

2 release files

1.1.3

2 release files

1.1.2

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.11

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.5

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page