adafruit_connection_manager

A urllib3.poolmanager/urllib3.connectionpool-like library for managing sockets and connections

  • Author(s): Justin Myers

Implementation Notes

Software and Dependencies:

class adafruit_connection_manager.ConnectionManager(socket_pool: ModuleType)

A library for managing sockets across multiple hardware platforms and libraries.

property available_socket_count: int

Get the count of available (freed) managed sockets.

close_socket(socket: LegacyCircuitPythonSocketType | CircuitPythonSocketType | StandardPythonSocketType) None

Close a previously managed and connected socket.

  • socket_pool (SocketType) – The socket you want to close

free_socket(socket: LegacyCircuitPythonSocketType | CircuitPythonSocketType | StandardPythonSocketType) None

Mark a managed socket as available so it can be reused. The socket is not closed.

get_socket(host: str, port: int, proto: str, session_id: str | None = None, *, timeout: float = 1.0, is_ssl: bool = False, ssl_context: SSLContext | _FakeSSLContext | None = None) CircuitPythonSocketType

Get a new socket and connect to the given host.

Parameters:
  • host (str) – host to connect to, such as "www.example.org"

  • port (int) – port to use for connection, such as 80 or 443

  • proto (str) – connection protocol: "http:", "https:", etc.

  • Optional[str] – unique session ID, used for multiple simultaneous connections to the same host

  • timeout (float) – how long to wait to connect

  • is_ssl (bool) – True If the connection is to be over SSL; automatically set when proto is "https:"

  • Optional[SSLContextType] – SSL context to use when making SSL requests

property managed_socket_count: int

Get the count of managed sockets.

adafruit_connection_manager.connection_manager_close_all(socket_pool: ModuleType | None = None, release_references: bool = False) None

Close all open sockets for pool, optionally release references.

Parameters:
  • socket_pool (Optional[SocketpoolModuleType]) – a specific socket pool whose sockets you want to close; None means all socket pools

  • release_references (bool) – True if you also want the ConnectionManager to forget all the socket pools and SSL contexts it knows about

adafruit_connection_manager.create_fake_ssl_context(socket_pool: ModuleType, iface: InterfaceType) _FakeSSLContext

Method to return a fake SSL context for when ssl isn’t available to import

For example when using a:

adafruit_connection_manager.get_connection_manager(socket_pool: ModuleType) ConnectionManager

Get or create the ConnectionManager singleton for the given pool.

adafruit_connection_manager.get_radio_socketpool(radio)

Helper to get a socket pool for common boards.

Currently supported:

  • Boards with onboard WiFi (ESP32S2, ESP32S3, Pico W, etc)

  • Using the ESP32 WiFi Co-Processor (like the Adafruit AirLift)

  • Using a WIZ5500 (Like the Adafruit Ethernet FeatherWing)

adafruit_connection_manager.get_radio_ssl_context(radio)

Helper to get ssl_contexts for common boards.

Currently supported:

  • Boards with onboard WiFi (ESP32S2, ESP32S3, Pico W, etc)

  • Using the ESP32 WiFi Co-Processor (like the Adafruit AirLift)

  • Using a WIZ5500 (Like the Adafruit Ethernet FeatherWing)