Skip to content

feat(sdk): live logs for jobs#35

Open
tejapulagam wants to merge 3 commits into
mainfrom
tejapulagam/live-logs-python
Open

feat(sdk): live logs for jobs#35
tejapulagam wants to merge 3 commits into
mainfrom
tejapulagam/live-logs-python

Conversation

@tejapulagam

@tejapulagam tejapulagam commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Summary

Currently the SDK has no way to stream a job's logs. Job.logs only returned the finished log and raised an error while the job was running. Live logs existed in lightning deployment logs only.

This PR adds a way to stream a job's logs live from the Python SDK.
Job.stream_logs(follow=True, tail=..., rank=..., idle_timeout=...) yields log lines as a generator, backed by JobApiV2.stream_logs that follows the controlplane log websocket.

demo: https://www.loom.com/share/2017cb29696542bc96d20c91d03cb940

I will follow up with a lightning job logs CLI command.

Usage

from lightning_sdk import Job
job = Job(name="my-job")
# Follow logs live until the job finishes (Ctrl-C to stop).
for line in job.stream_logs():
    print(line)
# Only the last 100 lines, then follow.
for line in job.stream_logs(tail=100):
    print(line)
# Stop automatically after 30s with no new output (good for scripts).
for line in job.stream_logs(idle_timeout=30):
    print(line)
# A specific rank of a distributed job.
for line in job.stream_logs(rank=1):
    print(line)

@tejapulagam
tejapulagam force-pushed the tejapulagam/live-logs-python branch from 7b4ac3f to 7ffbd9c Compare July 22, 2026 18:04
@tejapulagam
tejapulagam force-pushed the tejapulagam/live-logs-python branch from 7ffbd9c to 26b0121 Compare July 22, 2026 18:36
@tejapulagam
tejapulagam marked this pull request as ready for review July 22, 2026 18:36
@tejapulagam tejapulagam changed the title wip feat(sdk): live logs for jobs feat(sdk): live logs for jobs Jul 22, 2026
Comment thread python/lightning_sdk/job.py Outdated
Comment thread python/lightning_sdk/api/job_api.py Outdated
Comment thread python/lightning_sdk/api/job_api.py

@lianakoleva lianakoleva left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

awesome! 3 comments. please add testing as well.

@justusschock justusschock left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

how does job.stream_logs() behave when calling it twice? will it only return the logs emitted after the first one or all of them?

Also should we unify this with .logs? so depending on the state, it will either do the streaming or all of them? all the flags (tail, rank & follow) should work with both of them

@tejapulagam
tejapulagam force-pushed the tejapulagam/live-logs-python branch from d8efc2a to b7e9982 Compare July 23, 2026 22:06
@tejapulagam

Copy link
Copy Markdown
Contributor Author

how does job.stream_logs() behave when calling it twice? will it only return the logs emitted after the first one or all of them?

Also should we unify this with .logs? so depending on the state, it will either do the streaming or all of them? all the flags (tail, rank & follow) should work with both of them

On calling twice: it's stateless, each call will open a fresh stream starting from the job's creation time (or the last tail N lines), so you get the full logs again, not just the delta since the last call. We don't persist a cursor between calls.

stream_logs is no longer exposed, everything is under job.logs, which dispatches on state:
finished -> saved logs
running -> live snapshot
running + follow=True → live stream
print(job.logs) gives a snapshot string; job.logs(follow=True, tail=...) returns an iterator of lines

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.

3 participants