Metadata-Version: 2.5
Name: kymoscope
Version: 0.8.0.post1
Summary: Stream live, end-to-end encrypted telemetry to Kymoscope
Project-URL: Homepage, https://kymoscope.com
Project-URL: Documentation, https://kymoscope.com/docs/live
License: # Kymoscope Software License
        
        Copyright © 2026 Kymoscope. All rights reserved.
        
        This license covers the Kymoscope software package it comes with (the "Software"), including its templates and bundled documentation. By installing or using the Software you accept these terms. If you accept them for an organization, you confirm that you may bind it, and "you" means that organization.
        
        "Kymoscope" in this license means the owner of the Kymoscope software and service.
        
        ## 1. What you may do
        
        At no charge, you may install, run and copy the Software to connect systems you are entitled to use to a Kymoscope account, and to operate that connection. You may:
        
        1. use it for your internal business, in production, with no license key;
        2. keep copies in your organization's internal package mirrors and on the machines that need them;
        3. let your employees and the contractors working for you do the same, for your benefit; you are responsible for their use.
        
        ## 2. What your connectors are
        
        You or your AI assistant may use the Software to write adapters, configuration and related files ("Connectors"). As between you and Kymoscope, Connectors are yours, and Kymoscope claims no ownership of them. You may use the templates, examples and any part of the Software that appears in a Connector, as part of that Connector, without restriction.
        
        Connectors are not supported or warranted by Kymoscope. Your rights in what an AI assistant produces also depend on that assistant's terms and on applicable law.
        
        ## 3. What you may not do
        
        You may not:
        
        1. sell, rent or sublicense the Software, or publish it or offer it for download to others outside your organization, except as a Connector under section 2;
        2. use the Software or a modified copy of it to connect to a service other than Kymoscope. Reading from your own systems and writing to your own sinks, as the Software provides, is allowed;
        3. remove copyright or license notices from copies of the Software;
        4. reverse engineer the Software, except to the extent the law allows this regardless of this license. Reading and auditing its source is allowed.
        
        ## 4. Other terms
        
        Your Kymoscope account and its hosted services are governed by your account terms. Dependencies the Software installs come under their own licenses. An AI assistant you use is governed by its provider's terms.
        
        ## 5. Your responsibility
        
        You choose what to connect and which changes to approve. In particular:
        
        1. **Code you add or generate runs on your systems**, with the permissions of the account that runs it, which can be an operating system's highest. Tests the Software performs help to review it and do not isolate it.
        2. **If you use the Software with an AI assistant, what it returns reaches your AI provider**, as described in the documentation at kymoscope.com/docs. Choosing that provider, and what you share with it, is your decision and your responsibility.
        3. **Not for safety functions.** Don't use the Software or a Connector as part of a safety function, a control function or anything else whose failure could harm people, property or the environment. Use read-only access to the systems you connect.
        
        ## 6. No warranty and limitation of liability
        
        The Software is provided free of charge and "as is", without warranties of any kind, to the maximum extent the law allows.
        
        To the maximum extent the law allows, Kymoscope isn't liable for indirect or consequential damages, loss of data, loss of production or loss of profit arising from the Software or a Connector.
        
        Nothing in this license limits liability that the law doesn't allow to be limited, such as for willful misconduct or gross negligence, or rights you have as a consumer that can't be waived.
        
        ## 7. Ending
        
        You may stop using the Software at any time. This license ends automatically if you materially breach it and don't correct the breach within 30 days of notice; you must then stop using the Software and delete your copies. Sections 2, 5 and 6 and your rights in Connectors continue. A version of the Software you already received stays under this license even if later versions change it.
        
        ## 8. Law
        
        Mandatory law of the place where you have your seat or residence applies. Otherwise, this license is governed by the law of Spain.
        
        ## 9. Contact
        
        hola@kymoscope.com
License-File: LICENSE.md
Requires-Python: >=3.9
Requires-Dist: cryptography>=41
Requires-Dist: requests>=2.28
Requires-Dist: websocket-client>=1.6
Provides-Extra: test
Requires-Dist: pytest>=7; extra == 'test'
Provides-Extra: viewer
Requires-Dist: msgpack>=1.0; extra == 'viewer'
Description-Content-Type: text/markdown

# kymoscope

Stream live, end-to-end encrypted telemetry to [Kymoscope](https://kymoscope.com) from Python.

Requires Python 3.9 or later.

```bash
pip install kymoscope
```

## Example

```python
import math, time
from kymoscope import LiveStream

API_KEY = "kymoscope_..."   # Account -> API & real-time streaming, or a project's API key
# state_path keeps this sender's identity, so a restart needs no new approval
with LiveStream(API_KEY, "Rig A", state_path="kymoscope-state.json") as stream:
    print("stream id:", stream.stream_id)
    while True:
        t = time.time()           # absolute (Unix seconds)
        stream.send([{"t": t, "signals": [
            {"name": "speed", "unit": "m/s", "value": 50 + 10 * math.sin(t)},
        ]}])
        time.sleep(1 / 60)
```

In an end-to-end encrypted project, the first run waits until a project member's browser
approves the sender; after that it publishes on its own.
`LiveStream.project_key` gives a collector the current project key so it can seal keys of its own (day history);
never log or persist it.

## Keep every sample when the connection drops

```python
with LiveStream(API_KEY, "Rig A", state_path="kymoscope-state.json",
                buffer_path="kymoscope-buffer", buffer_max_mb=2048) as stream:
    ...
```

With `buffer_path` (a folder), the stream always sends, also with nobody watching, so a cloud
recording keeps everything. While the relay is unreachable it keeps the encrypted messages on disk, then sends
them in order when the relay is back, with the bandwidth live data leaves spare. Viewers see that data in the
recording, not in the live view. A crash can send a few messages twice.
`buffer_max_mb` caps the disk used; when it is full, new samples are dropped and counted in `stream.buffer_dropped`.
`buffer_min_free_mb` (default 0, off) also stops buffering when the disk has less free space than that.
Since 0.3.0 the stream sends the compact format by default (4–8× less data); `block_format=False` sends the
classic format for viewers on SDK versions before 0.2.0 or self-hosted relays before 0.2.0 (`buffer_path` always
uses the compact one). With `buffer_path`, send absolute times (`time.time()`), so data sent after a restart lands
in the right place in the recording.

## Cameras

A camera is a channel of a stream: whoever opens the stream sees its cameras. It needs
[ffmpeg](https://ffmpeg.org) on PATH.

```python
with LiveStream(API_KEY, "Rig A", state_path="kymoscope-state.json") as stream:
    stream.add_camera("Front", "video=Integrated Camera", input_format="dshow")   # a webcam on Windows
    stream.add_camera("Bay", "/dev/video0", input_format="v4l2", size="1280x720") # a webcam on Linux
    stream.add_camera("Door", "rtsp://user:pass@10.0.0.7/stream1", copy=True)     # an H.264 IP camera, as is
    stream.add_camera("Test", "testsrc=size=1280x720:rate=30", input_format="lavfi")  # a test pattern
    while True:
        stream.send(...)    # keep sending (or call stream.tick()): the cameras heartbeat with the stream
```

ffmpeg re-encodes to H.264 (`fps` 30, `kbps` 2000 by default, a keyframe every 2 s) unless `copy=True`.
Video goes out only while someone watches the camera; a new viewer starts at the next keyframe.
Use the same API key for the cameras as for their stream; in an encrypted project they need no extra approval.

`low=True` also publishes a 360p copy (640x360 for 16:9, 15 fps, 400 kbit/s, a keyframe every 2 s) as the camera's
low layer. Viewers play it in small panels and camera walls, and switch to full quality when a camera is enlarged;
it also suits viewers on slow links. It goes out only while someone watches it, isn't recorded, and doesn't count
as a camera of your plan.

```python
stream.add_camera("Bay", "/dev/video0", input_format="v4l2", low=True)
stream.add_camera("Door", "rtsp://user:pass@10.0.0.7/stream1", copy=True, low=True)
```

One ffmpeg writes both layers. With `copy=True` the full layer is still forwarded as is; only the low layer is decoded
and encoded, which costs the CPU of one 360p libx264 encode (plus decoding the camera's stream). On Windows a
second ffmpeg encodes the low layer and opens the input again: fine for an IP camera or a file, but a webcam
(`dshow`) can't be opened twice, so `low=True` with `input_format="dshow"` raises an error; run that sender on
Linux or macOS, or use an IP camera.

Credentials in a camera URL (`rtsp://user:pass@host/...`) are passed to ffmpeg on its command line, so other users
of the same machine can read them in the process list. Kymoscope hides them (`rtsp://***@host`) in everything it
prints, ffmpeg's own error lines included. Give the sender a camera account that can only view the stream, and run
it on a machine (or under an account) nobody else uses.

The headless viewer (`kymoscope.viewer`) needs msgpack: `pip install 'kymoscope[viewer]'`.

Full documentation: https://kymoscope.com/docs/live
