Skip to content

Session


class linescope.api.Session(config=None, **options)[source]

Collect one source profiling run and render portable HTML.

Parameters

config : Config | None, default=None

Prevalidated configuration. Mutually exclusive with keyword options.

**options

Explicit Config fields overriding project settings.

Attributes

config : Config

Validated options retained for this profiling session.

result : ProfileResult

Complete normalized result containing captured source, the run tree, measurements, capabilities, and diagnostics. Finalized by stop().

state : SessionState

Lifecycle state; a session starts once and remains stopped.


See Also

Config

Configure a single profiling session.

profile

Create a context-managed session using explicit Config options.

ProfileResult

Combine portable source snapshots with backend-independent run data.


Example

>>> from linescope import Session

>>> with Session(
...     backend="trace", display="none", notebooks=False, spark=False
... ) as session:
...     value = sum(range(10))
>>> value
45
>>> str(session.state)
'stopped'


Methods

start Begin collection and install configured notebook and Spark observers.
stop Finalize measurements and restore instrumentation.
html Return the complete self-contained report as HTML.
save Write an HTML snapshot without opening a browser.
show Open a browser report or display it inside a notebook cell.


method start()[source]

Begin collection and install configured notebook and Spark observers.

Returns

Session

This running session.



method stop()[source]

Finalize measurements and restore instrumentation.

Display the completed report when configured and retain the complete result on session.result. Return None so notebook cells add no result representation. Repeated calls do nothing without redisplay.

The completed result remains accessible if report display fails.



method html()[source]

Return the complete self-contained report as HTML.

Returns

str

Report containing the captured source and current measurements.



method save(path)[source]

Write an HTML snapshot without opening a browser.

Parameters

path : str | Path

Destination filename. Missing parent directories are created.

Returns

Path

Absolute path to the saved report.



method show(inline=None)[source]

Open a browser report or display it inside a notebook cell.

Return None so notebook cells display only the report. Use html() to retrieve the self-contained HTML without displaying it.

Detect notebook kernels for automatic inline display. Scripts and terminal IPython open a browser.

Parameters

inline : bool | None, default=None

Choose the display destination for this report. None detects the environment; False opens a browser tab, and True displays an isolated iframe in the current notebook cell.