Metadata-Version: 2.4
Name: current-data-py
Version: 0.1.21
Summary: Current Data protobuf messages and schema metadata
Requires-Python: >=3.9
Description-Content-Type: text/markdown
Requires-Dist: protobuf>=3.20
Requires-Dist: turbodata==0.1.0
Requires-Dist: grpcio>=1.51.1
Requires-Dist: alibabacloud-oss-v2<2,>=1.4.0
Requires-Dist: tos<3,>=2.9
Requires-Dist: av>=12
Requires-Dist: pillow>=9

# current-data-py

Python SDK for robotics Protobuf messages, TD files, and platform service clients.
Run shell commands from the repository root in the shared development environment.

## Use locally

Run the bundled examples to write and read a local TD file using the installed SDK:

```sh
python -I -m current_data_py.examples.write_td /tmp/current-data-example.td
python -I -m current_data_py.examples.read_td /tmp/current-data-example.td
```

`-I` avoids importing the unbuilt source directory in place of the installed package.
See [examples](examples) for other entry points.

For a minimal read-only service call, run this snippet with `python -I` so it uses
the installed SDK:

```python
from contextlib import closing
import os
os.environ["ENV"] = "test"

from current_data_py.management import ManagementClient, MetadataFilter

with ManagementClient() as client:
    with closing(client.stream_data_references(MetadataFilter(), timeout=30)) as records:
        record = next(records, None)
        print(record.id if record is not None else "No matching data")
```

Set `ENV=test` before the first SDK import to select the test service; an unset or
empty value defaults to production. An explicit client `address=` overrides the
default. Remote examples require service connectivity and accessible data.

Downloads and remote reads default to the storage provider's
internal endpoint (`OSSClient` / `TOSClient` read permission, `download_data`,
`open_data`, and `open_td`). Outside that cloud network, pass
`use_internal_endpoint=False`; there is no automatic public fallback. A supplied
TOS `endpoint` selects that public address unless internal networking is explicitly
requested, which remains an error. Uploads still default to public networking.
OSS `open_td` without `bucket` infers the selected provider's unique bucket from
metadata; multiple buckets require an explicit selection. The SDK manages temporary
credentials for uploads, downloads and remote TD reads.

Calibration workers can import `GLOVE_CALIBRATION_REPORT_URL` from
`current_data_py` for the environment's HTTPS Collection callback endpoint on
`DEFAULT_ADDRESS` (port 443).
Processing supplies `ENV` to the Job; set it before the first SDK import.
The worker needs network access to that platform domain.

## Upload files

Use `OSSClient` or `TOSClient` with upload permission. The management service
selects the bucket and allowed object prefix. Both clients
require `data_type` and `data_kind`; keep the management client open during transfers:

```python
from current_data_py.management import ManagementClient
from current_data_py.tos import TOSClient

with ManagementClient() as management:
    with TOSClient(management, permission="upload", data_type="YAM",
                   data_kind="CONVERTED") as storage:
        storage.upload_file(storage.object_prefix + "recording.td", "/data/recording.td",
                            multipart_threshold=100 * 1024**2,
                            part_size=16 * 1024**2, max_workers=4)
```

Both clients accept the same transfer options. Files at or above
`multipart_threshold` use multipart upload; `0` forces multipart for nonempty
files. Empty files always use PutObject. Sizes are in bytes. `part_size` must be
5 MiB–5 GiB, and the file must fit within 10,000 parts; increase it for larger
files. `max_workers` controls parallel requests (1–64); part buffers use roughly
`part_size * max_workers` memory, plus SDK overhead. Do not modify the source
file during upload.

Uploads reject existing objects by default, including when completing multipart
uploads. Set `forbid_overwrite=False` to replace one. Content type and metadata
are preserved. The return value is the provider's PutObject result for small
files or CompleteMultipartUpload result for multipart files.

Failed multipart transfers attempt to abort and delete incomplete parts. A failed
cleanup emits a warning; check the bucket's incomplete uploads. The upload role
and its scoped STS policy must allow `oss:AbortMultipartUpload` or
`tos:AbortMultipartUpload` in addition to PutObject. Deploy the management-service
policy update and ensure the underlying cloud role permits cleanup before use.
There is no persistent checkpoint: a later call starts a new upload. Uploading
does not register the data; call `ManagementClient.register_data` separately.

## URDF packages

Use `ManagementClient.upload_urdf(directory, entrypoint, info=...)` to check local
dependencies, upload source files without overwriting objects, and register one
asset under a new UUID on each call. Keep the directory unchanged throughout the
call; validation, hashing and upload read the source directly without private
copies. Failed calls leave uploaded objects in place and do not resume or recover
registration on a later call.
STL, static COLLADA, OBJ/MTL and PNG/JPEG references are supported; rendering is
checked in preview. The result is the locally generated asset UUID; model lists
provide URDF URLs. See the
[URDF guide](docs/urdf.md) and run `python -I -m current_data_py.examples.upload_urdf --help`.

## Test changes

The package bundles generated Protobuf modules during its build. After protocol
changes, [regenerate the bindings](../README.md#protobuf) first.
Build into a fresh temporary directory, validate the artifacts, and install this
checkout's wheel before running its checks. Only the local package is installed;
shared dependencies are left unchanged:

```sh
(
  set -e
  sdk_dist=$(mktemp -d)
  trap 'rm -rf "$sdk_dist"' EXIT
  (cd current_data_py && python -m build --no-isolation --outdir "$sdk_dist")
  python current_data_py/tests/check_distribution.py --dist-dir "$sdk_dist"
  python -m pip install --no-deps --force-reinstall "$sdk_dist"/*.whl
  for check in package environment management labeling remote remote_v2 oss tos decoding multipart urdf urdf_validation docs; do
    python -I "current_data_py/tests/check_${check}.py"
  done
)
```

These checks cover packaging, environment selection, clients, and media decoding
using local fixtures and mocked services. They do not require production credentials
or prove connectivity to a deployed service.

## Publish to PyPI

Ordinary CI builds a temporary package and tests the installed wheel. It does not
retain SDK release artifacts or upload to a package index.

1. Run **Release** from `main`, select `environment=test`, and check
   `current_data_py`. Leave service selections, `commit`, and `sdk_version` empty.
   It creates a PR that increases `project.version` to the next unused patch
   version (for example, `0.1.20` → `0.1.21`). Review and merge it to start
   **SDK Publish**. Major/minor version changes can still use a manual version PR.
2. The workflow checks generated Protobuf files, builds and tests the wheel/sdist,
   retains them for 90 days, and uploads them to TestPyPI. `verify_test` checks
   remote SHA-256 digests and installs the package in a clean environment.
3. Complete functional testing against the test services. TestPyPI publication
   does not update existing SDK consumers; install the exact version and set
   `ENV=test` before importing the SDK. Registry selection and service environment
   selection are independent.
4. Run **Release** from `main`, select `environment=prod`, check `current_data_py`,
   and enter the verified `sdk_version`.
   Leave service selections and `commit` empty. It creates a PR containing the
   tested version, source SHA, run/attempt, artifact ID and file digests.
5. Obtain owner approval on the release PR's latest commit and merge it. The
   workflow downloads those exact distributions and publishes them to PyPI;
   it does not rebuild them or use newer SDK source. `verify_prod` checks remote
   digests and installation. Production consumers must explicitly upgrade.

A test version with code changes needs a new version number. Re-run failed jobs
for upload or verification failures: matching existing files are accepted and
only missing files are uploaded. Conflicting files, expired artifacts, and
unverified test releases block promotion. Do not delete and recreate artifacts
or rebuild an expired candidate under the same version; publish a new test version.
Versions that fail testing may be absent from production PyPI.

See [CI/CD configuration](../.github/CI-CD.md#sdk-publishing) for publisher setup,
permissions and workflow tests. Review package metadata and bundled documentation
for public distribution before merging a version update.
