From 3b2750fc2c028bb45c1a6a6523396dbcb56ba74c Mon Sep 17 00:00:00 2001 From: Andrey Rakhmatullin Date: Wed, 12 Aug 2026 19:41:14 +0500 Subject: [PATCH] Rough basic docs. --- docs/topics/extensions.rst | 8 +----- scrapy/extensions/remote_control.py | 41 +++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/docs/topics/extensions.rst b/docs/topics/extensions.rst index 18dc1b769..1a589b8e5 100644 --- a/docs/topics/extensions.rst +++ b/docs/topics/extensions.rst @@ -502,10 +502,4 @@ Remote control extension .. module:: scrapy.extensions.remote_control :synopsis: Remote control extension -.. class:: RemoteControl - -Provides an HTTP server - -The telnet console must be enabled by the :setting:`TELNETCONSOLE_ENABLED` -setting, and the server will listen in the port specified in -:setting:`TELNETCONSOLE_PORT`. +.. autoclass:: RemoteControl diff --git a/scrapy/extensions/remote_control.py b/scrapy/extensions/remote_control.py index 0d84fb59a..0e0b5dbc3 100644 --- a/scrapy/extensions/remote_control.py +++ b/scrapy/extensions/remote_control.py @@ -40,6 +40,47 @@ STOP_TIMEOUT = 2.0 class RemoteControl: + """Provides an HTTP server that can run Python code passed to it in HTTP requests + and return the output in responses. + + The code runs inside the Scrapy process and has access to the + :class:`~scrapy.crawler.Crawler` instance in the ``crawler`` variable and + to a persistent dictionary in the ``stash`` variable. + + This extension can be disabled by setting the + :setting:`REMOTE_CONTROL_ENABLED` setting to ``False``. It requires + :ref:`asyncio support ` and will be disabled without it. + + The HTTP server listens on a random port on ``localhost`` and requires a + ``Bearer`` token for authentication. The token and port are written to a + job file in the user's profile directory so that other processes can + discover and use them to connect to the server. + + Available endpoints: + + - ``/execute``: expects a ``POST`` request with a JSON object containing + the following keys: + + - ``code`` (string): Python code to execute. + - ``timeout_sec`` (number, optional): the maximum number of seconds + to allow the code to run. + + The response is a JSON object with the following keys: + + - ``status`` (string): one of ``"ok"``, ``"compile_error"``, + ``"error"``, or ``"timeout"``. + - ``output`` (string): the output of the code. + - ``traceback`` (string or null): the traceback if an exception was + raised. + - ``elapsed_sec`` (number): the number of seconds the code took to run. + - ``output_truncated`` (boolean, optional): whether the output was + truncated. + - ``traceback_truncated`` (boolean, optional): whether the traceback + was truncated. + + .. versionadded:: VERSION + """ + def __init__(self, crawler: Crawler): if not crawler.settings.getbool("REMOTE_CONTROL_ENABLED"): raise NotConfigured