Skip to content

feat: add shared HTTP sessions and configurable timeouts - #255

Closed
Mattsface wants to merge 1 commit into
release/0.8.0from
cursor/shared-http-session-415a
Closed

feat: add shared HTTP sessions and configurable timeouts#255
Mattsface wants to merge 1 commit into
release/0.8.0from
cursor/shared-http-session-415a

Conversation

@Mattsface

@Mattsface Mattsface commented Aug 1, 2026

Copy link
Copy Markdown
Member

Why

The HTTP adapter used module-level requests.get(), which prevented connection reuse, made timeouts/session injection awkward, and left no clear cleanup path. Every request also needs an explicit timeout so the library cannot hang indefinitely waiting on the MLB API.

What

  • Route all adapter HTTP calls through a requests.Session
  • Share one session between the Mlb client's v1 and v1.1 adapters
  • Add a default timeout of (3.05, 30.0) and allow scalar/tuple overrides
  • Support optional session= injection on Mlb / MlbDataAdapter
  • Track session ownership: library-created sessions are closed; injected sessions are not
  • Add Mlb.close() plus context-manager support (with Mlb() as mlb:)
  • Keep existing constructor positional args and adapter response behavior intact
  • Add offline coverage in tests/test_mlb_session.py

Tests

  • poetry run pytest tests/ --ignore=tests/external_tests — 116 passed
  • poetry run pytest tests/external_tests/mlbdataadapter/ — 3 passed

Risk and impact

  • Normal — transport plumbing changes, but endpoint signatures, return types, and 404/exception behavior are unchanged
  • If something goes wrong: requests could fail on timeout/session mishandling, or callers with custom sessions could see unexpected close behavior (mitigated by ownership tests)

Intentionally left out

  • Retries / backoff
  • New exception subclasses
  • Async client
  • Caching / rate limiting
  • Endpoint return-type changes
Open in Web Open in Cursor 

Use a shared requests.Session for v1 and v1.1 adapters, require an
explicit timeout on every request, support session injection with clear
ownership rules, and add close()/context-manager cleanup on Mlb.

Co-authored-by: Matthew Spah <spahmatthew@gmail.com>
@Mattsface Mattsface closed this Aug 1, 2026
@cursor
cursor Bot deleted the cursor/shared-http-session-415a branch August 1, 2026 05:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants