Command-line utility and Python library for extracting video streams from various streaming services
npx @tessl/cli install tessl/pypi-streamlink@7.5.0A command-line utility and Python library for extracting video streams from various streaming services (Twitch, YouTube, etc.) and piping them into video players. Streamlink provides a plugin-based architecture that allows easy addition of support for new streaming services, advanced stream quality selection, and both CLI and API interfaces for different use cases.
pip install streamlinkimport streamlinkCommon for direct stream extraction:
from streamlink import streamsFor advanced usage with sessions:
from streamlink import Streamlinkimport streamlink
# Simple stream extraction using the convenience function
url = "https://www.twitch.tv/example_channel"
streams_dict = streamlink.streams(url)
# Select best quality stream
if streams_dict:
best_stream = streams_dict['best']
print(f"Stream URL: {best_stream.url}")
# Open stream for reading
with best_stream.open() as stream_io:
data = stream_io.read(1024)
print(f"Read {len(data)} bytes")
# Advanced usage with session configuration
session = streamlink.Streamlink()
session.set_option('http-timeout', 30)
session.set_option('http-headers', {'User-Agent': 'My Custom Agent'})
streams_dict = session.streams(url)Streamlink's architecture centers around these key components:
Streamlink class manages plugins, HTTP sessions, and configuration optionsThis design allows Streamlink to support hundreds of streaming services through a unified interface while providing both simple convenience functions and advanced customization capabilities.
Central session management for configuring HTTP behavior, plugin loading, and stream extraction. The Streamlink class coordinates all operations and maintains state across plugin interactions.
class Streamlink:
def __init__(self, options=None, *, plugins_builtin=True, plugins_lazy=True): ...
def set_option(self, key: str, value): ...
def get_option(self, key: str): ...
def resolve_url(self, url: str, follow_redirect=True): ...
def resolve_url_no_redirect(self, url: str): ...
def streams(self, url: str, options=None, **params): ...
# Properties
@property
def version(self): ...
@property
def localization(self): ...
# Session attributes
http: HTTPSession
options: StreamlinkOptions
plugins: StreamlinkPlugins
class StreamlinkOptions(Options): ...
def streams(url: str, **params):
"""Convenience function using default session"""Multiple stream types supporting different protocols including HTTP streams, HLS (HTTP Live Streaming), DASH (Dynamic Adaptive Streaming), and muxed streams combining multiple tracks.
class Stream:
def open(self): ...
def to_url(self): ...
class StreamIO(io.IOBase): ...
class HTTPStream(Stream):
def __init__(self, session, url, buffered=True, **kwargs): ...
class HLSStream(Stream): ...
class MuxedHLSStream(Stream): ...
class DASHStream(Stream): ...
class MuxedStream(Stream):
def __init__(self, session, *substreams, **options): ...
# Stream IO Wrappers
class StreamIOWrapper: ...
class StreamIOIterWrapper(StreamIOWrapper): ...
class StreamIOThreadWrapper(StreamIOWrapper): ...Extensible plugin architecture for adding support for new streaming services. Plugins use decorators to define URL patterns and command-line arguments.
class Plugin:
def __init__(self, session, url, options=None): ...
def streams(self, stream_types=None, sorting_excludes=None): ...
def pluginmatcher(pattern, priority=20, name=None): ...
def pluginargument(name, **kwargs): ...
# Plugin configuration classes
class PluginArguments: ...
class PluginOptions(Options): ...
# Priority constants
HIGH_PRIORITY = 30
NORMAL_PRIORITY = 20
LOW_PRIORITY = 10
NO_PRIORITY = 0Flexible options system for configuring HTTP behavior, stream preferences, and plugin settings with getter/setter mappings and validation.
class Options(dict):
def __init__(self, defaults=None): ...
def get(self, key: str): ...
def set(self, key: str, value): ...
def update(self, options): ...
def clear(self): ...Schema-based validation system for parsing HTML, JSON, XML and validating data structures with combinators and type-specific validators.
def validate(obj, schema): ...
# Schema combinators
def all(*schemas): ...
def any(*schemas): ...
def none_or_all(*schemas): ...
def optional(schema): ...
def transform(func, *schemas): ...
def list(schema): ...
def union(*schemas): ...
def union_get(*schemas): ...
def regex(pattern, **kwargs): ...
def xml_element(tag=None, **kwargs): ...
# Data access validators
def attr(attr, schema, default=None): ...
def get(item, schema, default=None): ...
# String validators
def contains(item): ...
def startswith(prefix): ...
def endswith(suffix): ...
def length(min_len, max_len=None): ...
def getattr(attr, default=None): ...
def hasattr(attr): ...
def filter(func): ...
def map(func): ...
# Parsing validators
def url(**kwargs): ...
def parse_html(**kwargs): ...
def parse_json(**kwargs): ...
def parse_xml(**kwargs): ...
def parse_qsd(**kwargs): ...
# XML validators
def xml_find(tag): ...
def xml_findall(tag): ...
def xml_findtext(tag): ...
def xml_xpath(expression): ...
def xml_xpath_string(expression): ...URL manipulation, parsing utilities, caching, and system integration functions for common operations in plugin development.
# URL utilities
def absolute_url(base, url): ...
def update_qsd(url, **params): ...
def update_scheme(scheme, url, force=False): ...
# Parsing utilities
def parse_html(data, **kwargs): ...
def parse_json(data, **kwargs): ...
def search_dict(obj, key): ...
# System utilities
class NamedPipe: ...
class LRUCache: ...class StreamlinkError(Exception): ...
class PluginError(StreamlinkError): ...
class FatalPluginError(PluginError): ...
class NoPluginError(StreamlinkError): ...
class NoStreamsError(StreamlinkError): ...
class StreamError(StreamlinkError): ...
class StreamlinkWarning(UserWarning): ...
class StreamlinkDeprecationWarning(StreamlinkWarning): ...All Streamlink-specific exceptions inherit from StreamlinkError, allowing for comprehensive error handling in applications using the library.