API Reference
The API reference documentation below is generated using mkdocstrings. The API reference documentation is written in docstrings and is located in the dfg_tool/ directory.
cli
Digital frame grab tool.
callback(verbose=False, log=None)
Handle the CLI callback.
Source code in dfg_tool/cli/__init__.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | |
create_app()
Create the main CLI app.
Returns:
| Type | Description |
|---|---|
Typer
|
typer.Typer: The main CLI app |
Source code in dfg_tool/cli/__init__.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
link_app(app)
Link commands and callbacks to the app.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
app |
Typer
|
The main CLI app |
required |
Source code in dfg_tool/cli/__init__.py
55 56 57 58 59 60 61 62 63 64 65 66 67 | |
commands
Command
Bases: LogMixin
Base class for CLI commands.
run()
Run the command.
Source code in dfg_tool/cli/commands/__init__.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | |
extract
Extract(imaged_moment_uuids_path, output_dir_path, raziel_api_url, username, password)
Bases: Command
Extract frames and save them to disk.
Source code in dfg_tool/cli/commands/extract.py
26 27 28 29 30 31 32 33 34 35 36 37 38 | |
upload
Upload(input_dir_path, raziel_api_url, username, password)
Bases: Command
Upload captured frame grabs and register them in VARS.
Source code in dfg_tool/cli/commands/upload.py
27 28 29 30 31 32 33 34 35 36 37 | |
log
Logging utilities
LogMixin
Mixin class to add a logger to a class.
logger: logging.Logger
property
Get the logger for the class.
get_logger(name, level=logging.DEBUG, stream=False, rich=True)
Create a new logger with the given name and level.
Attaches a NullHandler to the logger to override default behavior. Optionally attaches a StreamHandler and/or RichHandler to the logger. If the global FILE_HANDLER is set, it will also be attached to the logger.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str
|
The name of the logger. |
required |
level |
int
|
The logging level. |
DEBUG
|
stream |
bool
|
Whether to attach the module StreamHandler to the logger. |
False
|
rich |
bool
|
Whether to attach the module RichHandler to the logger. |
True
|
Returns:
| Type | Description |
|---|---|
Logger
|
logging.Logger: The created logger. |
Source code in dfg_tool/cli/log.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
set_file_handler(handler)
Set the global file handler to log to the given file.
Sets the file handler formatter to the global formatter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
handler |
FileHandler
|
The file handler to set. |
required |
Source code in dfg_tool/cli/log.py
49 50 51 52 53 54 55 56 57 58 59 60 | |
lib
constants
Application constants.
m3
MBARI Media Management (M3) REST API clients
APIKeyAuth(api_key)
Bases: Auth
API key authentication.
Source code in dfg_tool/lib/m3/__init__.py
122 123 | |
APIKeyAuthenticatedRESTClient(base_url)
Bases: RESTClient
REST client that supports API key authentication.
Source code in dfg_tool/lib/m3/__init__.py
16 17 18 | |
BearerAuth(token)
Bases: Auth
Bearer token authentication.
Source code in dfg_tool/lib/m3/__init__.py
90 91 | |
M3AuthMixin(base_url)
Bases: RESTClient
M3 client authentication mixin class.
Adds:
- an authenticate method to authenticate with an API key M3-style
- a from_raziel factory method to create a client from a Raziel endpoint configuration
Source code in dfg_tool/lib/m3/__init__.py
16 17 18 | |
authenticate(api_key)
Authenticate by posting an API key at a predefined route /auth.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
api_key |
str
|
The API key. |
required |
Raises:
| Type | Description |
|---|---|
HTTPStatusError
|
If the API returns an error. |
Source code in dfg_tool/lib/m3/__init__.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
from_raziel(endpoint)
classmethod
Create an M3Client from a Raziel endpoint configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
endpoint |
dict
|
The Raziel endpoint configuration. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
M3Client |
M3AuthMixin
|
The M3Client. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the endpoint configuration is missing the |
HTTPStatusError
|
If the API returns an error during authentication. |
Source code in dfg_tool/lib/m3/__init__.py
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
RESTClient(base_url)
RESTful HTTP client. This class is a thin wrapper around httpx.Client that provides a convenient way to interact with a RESTful API.
Source code in dfg_tool/lib/m3/__init__.py
16 17 18 | |
delete(path, **kwargs)
Send a DELETE request to the API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
str
|
The path to the resource. |
required |
**kwargs |
dict
|
Additional keyword arguments to pass to httpx.Client.delete. |
{}
|
Returns:
| Type | Description |
|---|---|
Response
|
httpx.Response: The response from the API. |
Source code in dfg_tool/lib/m3/__init__.py
71 72 73 74 75 76 77 78 79 80 81 82 | |
get(path, **kwargs)
Send a GET request to the API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
str
|
The path to the resource. |
required |
**kwargs |
dict
|
Additional keyword arguments to pass to httpx.Client.get. |
{}
|
Returns:
| Type | Description |
|---|---|
Response
|
httpx.Response: The response from the API. |
Source code in dfg_tool/lib/m3/__init__.py
32 33 34 35 36 37 38 39 40 41 42 43 | |
post(path, **kwargs)
Send a POST request to the API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
str
|
The path to the resource. |
required |
**kwargs |
dict
|
Additional keyword arguments to pass to httpx.Client.post. |
{}
|
Returns:
| Type | Description |
|---|---|
Response
|
httpx.Response: The response from the API. |
Source code in dfg_tool/lib/m3/__init__.py
58 59 60 61 62 63 64 65 66 67 68 69 | |
put(path, **kwargs)
Send a PUT request to the API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
str
|
The path to the resource. |
required |
**kwargs |
dict
|
Additional keyword arguments to pass to httpx.Client.put. |
{}
|
Returns:
| Type | Description |
|---|---|
Response
|
httpx.Response: The response from the API. |
Source code in dfg_tool/lib/m3/__init__.py
45 46 47 48 49 50 51 52 53 54 55 56 | |
url_to(path)
Get the URL to a path on the API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
str
|
The path to the resource. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The URL to the resource. |
Source code in dfg_tool/lib/m3/__init__.py
20 21 22 23 24 25 26 27 28 29 30 | |
TokenAuthenticatedRESTClient(base_url)
Bases: RESTClient
REST client that supports bearer token authentication.
Source code in dfg_tool/lib/m3/__init__.py
16 17 18 | |
annosaurus
imagedmoments
get(client, uuid)
Get an imaged moment by UUID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client |
RESTClient
|
The REST client. |
required |
uuid |
UUID
|
The imaged moment UUID. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The imaged moment. |
Raises:
| Type | Description |
|---|---|
HTTPStatusError
|
If the API returns an error. |
Source code in dfg_tool/lib/m3/annosaurus/imagedmoments.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
images
create(client, video_reference_uuid, url, timecode=None, elapsed_time_millis=None, recorded_timestamp=None, format=None, width_pixels=None, height_pixels=None, description=None)
Create an image reference.
Note: one of timecode, elapsed_time_millis, or recorded_timestamp must be provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client |
AnnosaurusClient
|
The Annosaurus client. |
required |
video_reference_uuid |
UUID
|
The video reference UUID. |
required |
url |
str
|
The image URL. |
required |
timecode |
str
|
The image timecode. |
None
|
elapsed_time_millis |
int
|
The image elapsed time in milliseconds. |
None
|
recorded_timestamp |
str
|
The image recorded timestamp. |
None
|
format |
str
|
The image format. |
None
|
width_pixels |
int
|
The image width in pixels. |
None
|
height_pixels |
int
|
The image height in pixels. |
None
|
description |
str
|
The image description. |
None
|
Source code in dfg_tool/lib/m3/annosaurus/images.py
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 | |
beholder
capture
capture(client, video_url, elapsed_time_millis)
Capture a frame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client |
RESTClient
|
The REST client. |
required |
video_url |
str
|
The video URL. |
required |
elapsed_time_millis |
int
|
The elapsed time in milliseconds. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
The raw image data. |
Raises:
| Type | Description |
|---|---|
HTTPStatusError
|
If the API returns an error. |
Source code in dfg_tool/lib/m3/beholder/capture.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | |
panoptes
images
upload(client, camera_id, deployment_id, name, file)
Upload a framegrab.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client |
PanoptesClient
|
The Panoptes client. |
required |
camera_id |
str
|
The camera ID. |
required |
deployment_id |
str
|
The deployment ID. |
required |
name |
str
|
The framegrab name. |
required |
file |
BytesIO
|
The framegrab file object. |
required |
Raises:
| Type | Description |
|---|---|
HTTPStatusError
|
If the API returns an error. |
Source code in dfg_tool/lib/m3/panoptes/images.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | |
raziel
RazielClient(base_url)
Bases: TokenAuthenticatedRESTClient
Source code in dfg_tool/lib/m3/__init__.py
16 17 18 | |
authenticate(username, password)
Authenticate the client with the Raziel API.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
username |
str
|
The username. |
required |
password |
str
|
The password. |
required |
Raises:
| Type | Description |
|---|---|
HTTPStatusError
|
If the API returns an error. |
Source code in dfg_tool/lib/m3/raziel/__init__.py
6 7 8 9 10 11 12 13 14 15 16 17 | |
auth
authenticate(client, username, password)
Authenticate with the Raziel API and return the JWT.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client |
RESTClient
|
The REST client. |
required |
username |
str
|
The username. |
required |
password |
str
|
The password. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The JWT. |
Raises:
| Type | Description |
|---|---|
HTTPStatusError
|
If the API returns an error. |
Source code in dfg_tool/lib/m3/raziel/auth.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | |
endpoints
list(client)
List all endpoints.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client |
AuthenticatedRESTClient
|
The authenticated REST client. |
required |
Returns:
| Type | Description |
|---|---|
List[dict]
|
List[dict]: The list of endpoints. |
Raises:
| Type | Description |
|---|---|
HTTPStatusError
|
If the API returns an error. |
Source code in dfg_tool/lib/m3/raziel/endpoints.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | |
vampire_squid
media
get_by_video_reference_uuid(client, video_reference_uuid)
Get a media item by video reference UUID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client |
RESTClient
|
The REST client. |
required |
video_reference_uuid |
UUID
|
The video reference UUID. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The media item. |
Raises:
| Type | Description |
|---|---|
HTTPStatusError
|
If the API returns an error. |
Source code in dfg_tool/lib/m3/vampire_squid/media.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
videoreferences
get(client, uuid)
Get a video reference by UUID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client |
RESTClient
|
The REST client. |
required |
uuid |
UUID
|
The video reference UUID. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The video reference. |
Raises:
| Type | Description |
|---|---|
HTTPStatusError
|
If the API returns an error. |
Source code in dfg_tool/lib/m3/vampire_squid/videoreferences.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
videos
get(client, uuid)
Get a video by UUID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client |
RESTClient
|
The REST client. |
required |
uuid |
UUID
|
The video UUID. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The video. |
Raises:
| Type | Description |
|---|---|
HTTPStatusError
|
If the API returns an error. |
Source code in dfg_tool/lib/m3/vampire_squid/videos.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | |
videosequences
get_by_name(client, name)
Get a video sequence by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client |
RESTClient
|
The REST client. |
required |
name |
str
|
The name of the video sequence. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict
|
The video sequence. |
Raises:
| Type | Description |
|---|---|
HTTPStatusError
|
If the API returns an error. |
Source code in dfg_tool/lib/m3/vampire_squid/videosequences.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | |
models
Application data models.
timestamps
Timestamp parsing and formatting utilities.
format_timestamp(dt)
Format a datetime object as a timestamp string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dt |
datetime
|
The datetime object. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The formatted timestamp string. |
Examples:
>>> format_timestamp(datetime(2021, 1, 1, 0, 0))
'2021-01-01T00:00:00.000000Z'
Source code in dfg_tool/lib/timestamps.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 | |
parse_timecode(timecode)
Parse a timecode string into a timedelta object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timecode |
str
|
The timecode string. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
timedelta |
timedelta
|
The parsed timedelta object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the timecode string is invalid. |
Examples:
>>> parse_timecode("00:01:23")
datetime.timedelta(seconds=83)
>>> parse_timecode("01:23:45")
datetime.timedelta(seconds=5025)
Source code in dfg_tool/lib/timestamps.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
parse_timestamp(timestamp)
Parse a timestamp string into a datetime object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timestamp |
str
|
The timestamp string. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
datetime |
datetime
|
The parsed datetime object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the timestamp string is invalid. |
Examples:
>>> parse_timestamp("2021-01-01T00:00:00Z")
datetime.datetime(2021, 1, 1, 0, 0)
>>> parse_timestamp("2021-01-01T00:00:00.123Z")
datetime.datetime(2021, 1, 1, 0, 0, 0, 123000)
Source code in dfg_tool/lib/timestamps.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |