Python utility for Tetra Task Scripts
Project description
ts-task-script-utils
Version
v1.6.0
Table of Contents
Summary
Utility functions for Tetra Task Scripts
Installation
pip install ts-task-script-utils
Usage
Parsing Numbers
from task_script_utils.parse import to_int
string_value = '1.0'
int_value = to_int(string_value)
# `int_value` now has the parsed value of the string
assert isinstance(int_value, int)
assert int_value == 1
# it returns `None` if the value is unparseable
string_value = 'not an int'
int_value = to_int(string_value)
assert int_value is None
Parsing Datetimes
DEPRECATION WARNING!
- Do not use the old datetime parser:
convert_datetime_to_ts_format
(fromtask_script_utils.convert_datetime_to_ts_format
) - Instead, use the newer
parse
fromtask_script_utils.datetime_parser
parse
Usage
from task_script_utils.datetime_parser import parse
parse("2004-12-23T12:30 AM +05:30")
parse("2004-12-23T12:30 AM +05:30", <format_list>)
parse("2004-12-23T12:30 AM +05:30", <format_list>, <datetime_config>)
parse()
returns a TSDatetime
Object. You can use TSDatetime.tsformat()
and
TSDatetime.isoformat()
to get datetime string. You can also use
TSDatetime.datetime()
to access python datetime object.
You can read more about the datetime parser here.
Generating Random UUIDs for Task Scripts
To generate standard and random UUIDs, Python's uuid
module can be used (uuid1
for standard and uuid4
for random).
However, to get UUIDs that are reproducible for a given task script and input file, a custom UUID generator is provided:
task_script_utils.random.TaskScriptUUIDGenerator
.
from pathlib import Path
from task_script_utils.random import TaskScriptUUIDGenerator
input_file = Path(...)
file_content = input_file.read_bytes()
rand = TaskScriptUUIDGenerator("common/my-task-script:v1.0.0", file_content)
# Get 3 random bytes:
random_bytes = rand.randbytes(3)
# Get a random UUID:
uuid = rand.uuid()
It's also possible to use a class method and provide the task script identifiers separately:
from pathlib import Path
from task_script_utils.random import TaskScriptUUIDGenerator
input_file = Path(...)
file_content = input_file.read_bytes()
rand = TaskScriptUUIDGenerator.from_task_script_identifier_parts("common", "my-task-script", "v1.0.0", file_content)
This is a singleton class, meaning creating multiple instances of the class with the same arguments results in getting the identical object back, e.g.:
from pathlib import Path
from task_script_utils.random import TaskScriptUUIDGenerator
input_file = Path(...)
file_content = input_file.read_bytes()
rand1 = TaskScriptUUIDGenerator("common/my-task-script:v1.0.0", file_content)
rand2 = TaskScriptUUIDGenerator("common/my-task-script:v1.0.0", file_content)
assert rand1 is rand2
It's also possible to get the most-recently-created instance through the get_last_created
method:
from pathlib import Path
from task_script_utils.random import TaskScriptUUIDGenerator
input_file = Path(...)
file_content = input_file.read_bytes()
rand1 = TaskScriptUUIDGenerator("common/my-task-script:v1.0.0", file_content)
rand2 = TaskScriptUUIDGenerator.get_last_created()
assert rand1 is rand2
Creating datacube Parquet files
Changelog
v1.6.0
- Add
task_script_utils.datacubes.parquet
for creating Parquet file representations of datacubes
v1.5.0
- Add
TaskScriptUUIDGenerator
class for generating random UUIDs and random bytes.
v1.4.0
- Add
extract-to-decorate
functions
v1.3.1
- Update datetime parser usage in README.md
v1.3.0
- Added string parsing functions
v1.2.0
- Add boolean config parameter
require_unambiguous_formats
toDatetimeConfig
- Add logic to
parser._parse_with_formats
to be used whenDatetimeConfig.require_unambiguous_formats
is set toTrue
AmbiguousDatetimeFormatsError
is raised if mutually ambiguous formats are detected and differing datetimes are parsed
- Add parameter typing throughout repository
- Refactor
datetime_parser
package - Add base class
DateTimeInfo
- Segregate parsing logic into
ShortDateTimeInfo
andLongDateTimeInfo
v1.1.1
- Remove
convert_to_ts_iso8601()
method
v1.1.0
- Add
datetime_parser
package
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for ts_task_script_utils-1.6.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ca3d5c9f4f3d07e5f6d17f199b1b47fbcf331314b6e5e72aa8ba477408edf3bc |
|
MD5 | 5329438b010244182dc14f705b29b66d |
|
BLAKE2b-256 | 49747223f98e11af322d0cd4650c4af98f2a13aa15e605f6a80f808451702e90 |
Hashes for ts_task_script_utils-1.6.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fc8723ed5ee99d5a5ffadb21b0b4dbb9c7e5656634e6603433909a6e4853285 |
|
MD5 | e2fbab81e859a710661646b3a273d5d2 |
|
BLAKE2b-256 | 8715391b78d928f60a46bbffcd73164ba702d0e66b5e8161a02db4c73348ade3 |