Skip to content

HTTP Streams#91

Merged
michael-pisman merged 5 commits intomainfrom
streams
Jul 30, 2025
Merged

HTTP Streams#91
michael-pisman merged 5 commits intomainfrom
streams

Conversation

@michael-pisman
Copy link
Member

This pull request introduces server-sent events (SSE) functionality to the project, enabling real-time updates via a new /updates endpoint. The changes include adding a new dependency, creating a new route and utility for handling SSE, and integrating the new route into the existing router setup.

SSE Functionality Implementation:

  • Added sse-starlette dependency to the pyproject.toml file to support server-sent events. (pyproject.toml, pyproject.tomlR24)
  • Created a new streams route in src/unipoll_api/routes/streams.py, which defines an SSE endpoint (/updates) using EventSourceResponse. (src/unipoll_api/routes/streams.py, src/unipoll_api/routes/streams.pyR1-R13)
  • Implemented the update_generator utility in src/unipoll_api/utils/streams.py to generate real-time updates for the SSE endpoint. (src/unipoll_api/utils/streams.py, src/unipoll_api/utils/streams.pyR1-R16)

Router Integration:

  • Integrated the streams route into the router by importing it in src/unipoll_api/routes/__init__.py and including it in the main router with the tag "Streams". (src/unipoll_api/routes/__init__.py, [1] [2]

Copilot AI review requested due to automatic review settings July 30, 2025 06:20
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This pull request introduces server-sent events (SSE) functionality to enable real-time updates via a new /updates endpoint. The implementation adds SSE support through a new dependency and creates the necessary routing and utility components.

  • Added sse-starlette dependency for SSE functionality
  • Created a new /updates endpoint with EventSourceResponse for real-time streaming
  • Implemented a basic update generator utility that yields incremental data

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

File Description
pyproject.toml Adds sse-starlette dependency for SSE support
src/unipoll_api/utils/streams.py Implements update generator utility for SSE data
src/unipoll_api/routes/streams.py Creates new streams route with /updates endpoint
src/unipoll_api/routes/init.py Integrates streams router into main router configuration
Comments suppressed due to low confidence (2)

src/unipoll_api/utils/streams.py:8

  • The variable name 'i' is too generic for a counter variable. Consider using a more descriptive name like 'counter' or 'update_count'.
    i = 0

src/unipoll_api/routes/streams.py:11

  • The function name 'event_log' doesn't clearly describe its purpose of streaming updates. Consider renaming to 'stream_updates' or 'get_updates_stream'.
async def event_log():

while True:
i += 1
yield dict(data=i)
await asyncio.sleep(0.2)
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sleep duration of 0.2 seconds is a magic number. Consider defining this as a named constant to improve maintainability and make it configurable.

Suggested change
await asyncio.sleep(0.2)
await asyncio.sleep(SLEEP_DURATION)

Copilot uses AI. Check for mistakes.
Comment on lines +6 to +11
# async def update_generator(resource: Resource):
async def update_generator():
i = 0
try:
while True:
i += 1
Copy link

Copilot AI Jul 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This commented-out code should be removed if it's not needed, or properly implemented if it represents the intended functionality with Resource parameter.

Suggested change
# async def update_generator(resource: Resource):
async def update_generator():
i = 0
try:
while True:
i += 1
async def update_generator(resource: Resource):
"""
A generator function that yields data and interacts with a Resource object.
Args:
resource (Resource): The resource object to interact with.
"""
i = 0
try:
while True:
i += 1
# Example interaction with the resource object
resource.update_last_accessed() # Placeholder for actual logic

Copilot uses AI. Check for mistakes.
@michael-pisman michael-pisman merged commit 13b0e11 into main Jul 30, 2025
1 check failed
@michael-pisman michael-pisman deleted the streams branch July 30, 2025 06:21
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.

1 participant