myke.io¶
myke.echo¶
Functions¶
json
classmethod
¶
json(
obj: Any,
print_kwargs: Optional[Dict[str, Any]] = None,
**kwargs: Any
) -> None
Prints a dictionary as a JSON string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
Any
|
object to convert to JSON and print. |
required |
print_kwargs |
Optional[Dict[str, Any]]
|
kwargs passed to |
None
|
**kwargs |
Any
|
kwargs passed to |
{}
|
Examples:
>>> import myke
...
>>> myke.echo.json(
... {'Messages': ['Hello World.', 'Goodbye World.']},
... indent=4,
... )
{
"Messages": [
"Hello World.",
"Goodbye World."
]
}
lines
classmethod
¶
lines(
seq: Sequence[Optional[str]],
linesep: str = os.linesep,
print_kwargs: Optional[Dict[str, Any]] = None,
) -> None
Prints lines of text.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
seq |
Sequence[Optional[str]]
|
lines of text to print. |
required |
linesep |
str
|
line separator. |
linesep
|
print_kwargs |
Optional[Dict[str, Any]]
|
kwargs passed to |
None
|
Examples:
>>> import myke
...
>>> myke.echo.lines(['Hello World.', 'Goodbye World.'])
Hello World.
Goodbye World.
pretty
classmethod
¶
pretty(
obj: Any,
print_kwargs: Optional[Dict[str, Any]] = None,
**kwargs: Any
) -> None
Pretty-print objects.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
Any
|
object to print. |
required |
print_kwargs |
Optional[Dict[str, Any]]
|
kwargs passed to |
None
|
**kwargs |
Any
|
kwargs passed to |
{}
|
Examples:
>>> import myke
...
>>> myke.echo.pretty('Hello World.')
'Hello World.'
table
classmethod
¶
table(
obj: Union[
Iterable[Iterable[Any]], Mapping[str, Iterable[Any]]
],
print_kwargs: Optional[Dict[str, Any]] = None,
**kwargs: Any
) -> None
Prints a dictionary as a table.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj |
Union[Iterable[Iterable[Any]], Mapping[str, Iterable[Any]]]
|
list of dicts print. |
required |
print_kwargs |
Optional[Dict[str, Any]]
|
kwargs passed to |
None
|
**kwargs |
Any
|
kwargs passed to |
{}
|
Examples:
>>> import myke
...
>>> myke.echo.table([
... {'row': 1, 'Message': 'Hello World.'},
... {'row': 2, 'Message': 'Goodbye World.'},
... ])
row Message
----- --------------
1 Hello World.
2 Goodbye World.
tasks
classmethod
¶
tasks(
prog: Optional[str] = None,
tablefmt: Optional[str] = None,
) -> None
Print a table of registered myke tasks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prog |
Optional[str]
|
... |
None
|
tablefmt |
Optional[str]
|
table format to use (from |
None
|
Examples:
>>> import myke
...
>>> @myke.task
... def say_hello(name):
... print(f"Hello {name}.")
...
>>> @myke.task
... def say_goodbye(name):
... print(f"Goodbye {name}.")
>>> myke.echo.tasks()
========= =========== ==========
Parents Task Source
========= =========== ==========
- say-goodbye myke.tasks
- say-hello myke.tasks
========= =========== ==========
To view task parameters, see:
$ myke <task-name> --help
text
classmethod
¶
text(*args: Any, **kwargs: Any) -> None
Prints text.
Equivalent to base print
command; only exists for consistency.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
Any
|
... |
()
|
**kwargs |
Any
|
... |
{}
|
Examples:
>>> import myke
...
>>> myke.echo.text('Hello World.')
Hello World.
myke.read¶
Functions¶
cfg
classmethod
¶
cfg(*args: str, **kwargs: str) -> Dict[str, Any]
Parse object(s) from a INI/CFG text file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
str
|
... |
()
|
**kwargs |
str
|
... |
{}
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
... |
Examples:
>>> import myke
...
>>> myke.read.cfg('/path/to/file.cfg')
dotfile
classmethod
¶
dotfile(*args: str, **kwargs: str) -> Dict[str, str]
Parse key-value pairs from a dotfile (aka "envfile").
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
str
|
... |
()
|
**kwargs |
str
|
... |
{}
|
Returns:
Type | Description |
---|---|
Dict[str, str]
|
... |
Examples:
>>> import myke
...
>>> myke.read.dotfile('/path/to/vars.env')
envfile
classmethod
¶
envfile(*args: str, **kwargs: str) -> Dict[str, str]
Parse key-value pairs from a dotfile (aka "envfile").
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
str
|
... |
()
|
**kwargs |
str
|
... |
{}
|
Returns:
Type | Description |
---|---|
Dict[str, str]
|
... |
Examples:
>>> import myke
...
>>> myke.read.envfile('/path/to/vars.env')
ini
classmethod
¶
ini(*args: str, **kwargs: str) -> Dict[str, Any]
Parse object(s) from a INI/CFG text file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
str
|
... |
()
|
**kwargs |
str
|
... |
{}
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
... |
Examples:
>>> import myke
...
>>> myke.read.ini('/path/to/file.ini')
json
classmethod
¶
json(*args: str, **kwargs: str) -> Dict[str, Any]
Parse object(s) from a JSON text file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
str
|
... |
()
|
**kwargs |
str
|
... |
{}
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
... |
Examples:
>>> import myke
...
>>> myke.read.json('/path/to/file.json')
lines
classmethod
¶
lines(*args: str, **kwargs: str) -> List[str]
Read lines from a text file, strip whitespace from each line, and return list of non-empty elements.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
str
|
... |
()
|
**kwargs |
str
|
... |
{}
|
Returns:
Type | Description |
---|---|
List[str]
|
... |
Examples:
>>> import myke
...
>>> myke.read.lines('/path/to/file.txt')
text
staticmethod
¶
text(
path: Union[str, Path], encoding: str = "utf-8"
) -> str
Read text file contents and strip surrounding whitespace.
Equivalent to: Path(path).read_text().strip()
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Union[str, Path]
|
... |
required |
encoding |
str
|
... |
'utf-8'
|
Returns:
Type | Description |
---|---|
str
|
... |
Examples:
>>> import myke
...
>>> myke.read.text('/path/to/file.txt')
toml
classmethod
¶
toml(*args: str, **kwargs: str) -> Dict[str, Any]
Parse object(s) from a TOML text file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
str
|
... |
()
|
**kwargs |
str
|
... |
{}
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
... |
Examples:
>>> import myke
...
>>> myke.read.toml('/path/to/file.toml')
url
classmethod
¶
url(addr: str, **kwargs: Any) -> str
Return text from HTTP GET response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
addr |
str
|
URL of the remote file. |
required |
**kwargs |
Any
|
passed to |
{}
|
Returns:
Type | Description |
---|---|
str
|
... |
Examples:
>>> import myke
...
>>> myke.read.url('https://github.com/.../README.md')
url_json
classmethod
¶
url_json(addr: str, **kwargs: Any) -> Dict[str, Any]
Parse JSON from HTTP GET response.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
addr |
str
|
URL of the remote file. |
required |
**kwargs |
Any
|
passed to |
{}
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
... |
Examples:
>>> import myke
...
>>> myke.read.url_json('https://github.com/.../data.json')
yaml
classmethod
¶
yaml(*args: str, **kwargs: str) -> Dict[str, Any]
Parse object(s) from a YAML text file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
str
|
... |
()
|
**kwargs |
str
|
... |
{}
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
... |
Examples:
>>> import myke
...
>>> myke.read.yaml('/path/to/file.yaml')
yaml_all
classmethod
¶
yaml_all(*args: str, **kwargs: str) -> List[Dict[str, Any]]
Parse object(s) from multiple documents in a single YAML text file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
str
|
... |
()
|
**kwargs |
str
|
... |
{}
|
Returns:
Type | Description |
---|---|
List[Dict[str, Any]]
|
... |
Examples:
>>> import myke
...
>>> myke.read.yaml_all('/path/to/file.yaml')
myke.write¶
Functions¶
lines
classmethod
¶
lines(
content: List[Optional[str]],
path: Union[str, Path],
append: bool = False,
overwrite: bool = False,
**kwargs: Any
) -> None
Write lines of text to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content |
List[Optional[str]]
|
... |
required |
path |
Union[str, Path]
|
... |
required |
append |
bool
|
... |
False
|
overwrite |
bool
|
... |
False
|
**kwargs |
Any
|
... |
{}
|
Raises:
Type | Description |
---|---|
FileExistsError
|
if file exists and overwrite is False. |
Examples:
>>> import myke
...
>>> myke.write.text(['hello', 'world'], '/path/to/file.txt')
mykefile
classmethod
¶
mykefile(path: Union[None, str, Path] = None) -> None
Create a new Mykefile.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Union[None, str, Path]
|
... |
None
|
Raises:
Type | Description |
---|---|
FileExistsError
|
if file exists and overwrite is False. |
Examples:
>>> import myke
...
>>> myke.write.mykefile('/path/to/Mykefile')
text
staticmethod
¶
text(
content: Union[str, bytes],
path: Union[str, Path],
append: bool = False,
overwrite: bool = False,
encoding: str = "utf-8",
**kwargs: Any
) -> None
Write text to a file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
content |
Union[str, bytes]
|
... |
required |
path |
Union[str, Path]
|
... |
required |
append |
bool
|
... |
False
|
overwrite |
bool
|
... |
False
|
encoding |
str
|
... |
'utf-8'
|
**kwargs |
Any
|
... |
{}
|
Raises:
Type | Description |
---|---|
FileExistsError
|
if file exists and overwrite is False. |
Examples:
>>> import myke
...
>>> myke.write.text('hello world', '/path/to/file.txt')