Skip to main content

Safie Media File Downloader

Lint and Test PyPI - Python Version GitHub License

A Python library and command-line tool for downloading media files from Safie cameras.

Installation

Library with CLI Tool

If you also want to use the command-line tool:

pip install "safie-mediafile[cli]"

Library Only

If you want to use only the library functionality:

pip install safie-mediafile

Usage

Command Line Interface

You can download media files using either the device serial number or device name:

# Using serial number
safie-mediafile --serial 201055433 2024-03-22T10:00:00Z 2024-03-22T11:00:00Z --api-token YOUR_API_TOKEN

# Using device name
safie-mediafile --name "Camera Name" 2024-03-22T10:00:00Z 2024-03-22T11:00:00Z --api-token YOUR_API_TOKEN

# Specifying an output file path
safie-mediafile --serial 201055433 2024-03-22T10:00:00Z 2024-03-22T11:00:00Z --output-path output.mp4 --api-token YOUR_API_TOKEN

You can also set the API token using the SAFIE_TOKEN environment variable:

# Set API token as an environment variable
export SAFIE_TOKEN=YOUR_API_TOKEN
safie-mediafile --serial 201055433 2024-03-22T10:00:00Z 2024-03-22T11:00:00Z

Note: The command-line interface is only available if you install the package with the cli extra.

Python API

import asyncio
from datetime import datetime
from safie_mediafile import find_device_id, create_and_download_mediafile

async def download_media():
    # Set up time (ISO 8601 format)
    start = datetime.fromisoformat("2024-03-22T10:00:00+09:00")
    end = datetime.fromisoformat("2024-03-22T11:00:00+09:00")

    # Get device ID (search by serial number or name)
    device_id = await find_device_id(
        api_token="your_api_token",
        serial="201055433",  # or name="Camera Name" (use either one)
    )

    # Create and download media file
    with open("output.mp4", "wb") as f:
        await create_and_download_mediafile(
            device_id=device_id,
            start_time=start,
            end_time=end,
            file=f,  # file object opened in binary mode
            api_token="your_api_token",
        )

if __name__ == "__main__":
    asyncio.run(download_media())

Requirements

Core Library

  • Python 3.8 or later
  • httpx for HTTP requests

CLI Tool (Optional)

  • click for command-line interface
  • python-dateutil for timezone handling

Development

Setup Development Environment

# Clone the repository
git clone https://github.com/syundo0730/safie-mediafile.git
cd safie-mediafile

# Install uv if not already installed
# For macOS/Linux
curl -LsSf https://astral.sh/uv/install.sh | sh

# Install development dependencies using uv
uv pip install -e ".[dev,cli]"

Running Tests

# Run all tests
uv run pytest

# Run tests with coverage
uv run pytest --cov=safie_mediafile tests/

Code Quality

# Run linter
uv run ruff check .

# Run type checker
uv run mypy safie_mediafile

Releasing

This package uses GitHub Actions to automatically build and publish to PyPI when a new release is created.

Release Process

  1. Update the version in pyproject.toml
  2. Create and push a new tag:
    git tag v0.1.0
    git push origin v0.1.0
    
  3. Create a new release on GitHub using the tag
  4. The GitHub Actions workflow will automatically build and publish to PyPI

License

MIT License

Metadata

Release files for safie-mediafile 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for safie-mediafile 0.1.5
File Size Uploaded
safie_mediafile-0.1.5.tar.gz 43.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for safie-mediafile 0.1.5
File Interpreter ABI Platform
safie_mediafile-0.1.5-py3-none-any.whl Python 3 none any Details

Total release size: 56.3 kB

Release files / safie_mediafile-0.1.5.tar.gz

Download URL safie_mediafile-0.1.5.tar.gz
Size 43.4 kB
Tags Source
SHA-256 checksum
How to use checksums
96c40a0c053897bc732ebb1c9cce3b02f34d014a54ec8b05b7287e498acf7f1b
BLAKE2b-256 checksum
How to use checksums
3f7f3600bceba6c32a2210bbb989d4726cfe4a45159c3d9c342b3973a166d649
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 28, 2025.

Transparency log

Release files / safie_mediafile-0.1.5-py3-none-any.whl

Download URL safie_mediafile-0.1.5-py3-none-any.whl
Size 12.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1f0d7193c387d07ba8dbfd25be79a45d45e27faf5be510dc311f0e7d2905da00
BLAKE2b-256 checksum
How to use checksums
8c1f4907eb5b3179d98be8678a4101248700161e56dac232d08213512256d8f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Apr 28, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.5 This release

2 release files

0.1.4

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page