lica-cli
Introduction
lica-cli is a startup utility for LICA Python command-line applications. It provides a small, consistent API for parsing common command-line arguments and running either synchronous or asynchronous application entry points.
The package integrates with lica-log: it creates the standard CLI logging options, parses them into an argparse.Namespace, and passes them to a logging adapter. It also returns a process exit code after handling normal completion, keyboard interruption, and unexpected errors.
Installation
Install lica-cli directly from PyPI:
pip install lica-cli
The package depends on lica-log, which is installed automatically.
If you use uv, add it to your project:
[project]
dependencies = [
"lica-cli",
]
Public API
The public API is:
from lica_cli import parse_args, run_cli
Parsing arguments
parse_args(
add_args_func: Callable[[ArgumentParser], None],
name: str,
version: str,
description: str,
) -> Namespace
parse_args() creates an ArgumentParser, adds the common LICA CLI options, calls add_args_func() so the application can add its own options, and parses sys.argv[1:].
The following common options are added automatically:
| Option | Description |
|---|---|
--version |
Prints the application name and version. |
--console |
Enables logging to the console. |
--log-file <FILE> |
Writes log messages to the given file. |
--log-level |
Sets the logging level using lica_log.LogLevel. |
--trace |
Prints the full traceback when an unexpected exception occurs. |
Running a synchronous application
run_cli(
main_func: Callable[[Namespace], None],
args: Namespace,
name: str,
version: str,
logger: Logger,
) -> int
run_cli() configures the logger, runs main_func(args), and returns 0 on success. It returns 1 after a KeyboardInterrupt or an unhandled exception. If args.trace is true, it also prints the exception traceback.
Running an asynchronous application
run_cli(
main_func: Callable[[Namespace], Coroutine[Any, Any, None]],
args: Namespace,
name: str,
version: str,
logger: AsyncLogger,
) -> int
The asynchronous variant starts the QueueListener returned by AsyncLogger.configure(), runs the application coroutine with asyncio.run(), and returns the same exit-code convention as the synchronous API.
Input validators
The package also provides reusable command-line argument validators in lica_cli.validate to be used in an ArgumentParser. To name a few:
vfile: validates an existing file.vdir: validates an existing directory.vbool: validates"True"or"False".vdate: validates several ISO-like date and datetime formats.vmac: validates and normalises a MAC address.
Example:
from lica_cli.validate import vfile
parser.add_argument(
"--config",
type=vfile,
help="Path to an existing configuration file.",
)
Usage example
Synchronous application
import logging
import sys
from argparse import ArgumentParser, Namespace
from lica_cli import parse_args, run_cli
from lica_cli.validate import vdate
from lica_log.adapters.default import DefaultLogger
from myprog import __version__
DESCRIPTION = "My program short description"
log = logging.getLogger(__name__.split(".")[-1])
def add_args(parser: ArgumentParser) -> None:
"""Add extra CLI arguments here."""
parser.add_argument(
"-d",
"--images-dir",
type=vdir,
action="store",
metavar="<path>",
help="Base directory to edit FITS files",
).
def cli_main(args: Namespace) -> None:
log.info("Hello World")
def main():
args = parse_args(add_args, __name__, __version__, DESCRIPTION)
logger = DefaultLogger(args)
logger.configure()
return_code = run_cli(cli_main, args, __name__, __version__, logger)
sys.exit(return_code)
if __name__ == "__main__":
main()
Asynchronous application
import logging
import sys
from argparse import ArgumentParser, Namespace
from lica_cli.asyncio import parse_args, run_cli
from lica_log.asyncio.adapters.default import AsyncDefaultLogger
from myprog import __version__
DESCRIPTION = "My asynchronous program"
log = logging.getLogger(__name__.split(".")[-1])
def add_args(parser: ArgumentParser) -> None:
"""Add extra CLI arguments here."""
pass
async def cli_main(args: Namespace) -> None:
log.info("Hello World")
def main():
args = parse_args(add_args, __name__, __version__, DESCRIPTION)
logger = AsyncDefaultLogger(args)
return_code = run_cli(cli_main, args, __name__, __version__, logger)
sys.exit(return_code)
if __name__ == "__main__":
main()
Metadata
Release files for lica-cli 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| lica_cli-0.1.0.tar.gz | 6.1 kB | Without provenance | Details for lica_cli-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| lica_cli-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for lica_cli-0.1.0-py3-none-any.whl |
Total release size: 14.2 kB
Release files / lica_cli-0.1.0.tar.gz
| Download URL | lica_cli-0.1.0.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
62ed3886a6d5f68a4ed181db85bdca239f3ddc5e74c475ec249b9c5802f1b67a
|
|
BLAKE2b-256 checksum How to use checksums |
b2b33e31ac3e6243e397ef66f7101f60fc8301cda2b950a2e7e1f3c666b978a7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / lica_cli-0.1.0-py3-none-any.whl
| Download URL | lica_cli-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
7365b779fab0edda4c21bf890937426dea78563382803fc07fcf6de28d0b9bde
|
|
BLAKE2b-256 checksum How to use checksums |
a8c7fd91ca918a820f8ae4b00bfe3ced53f273d82030def20dccb1c12a8049e2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for lica-cli 0.1.0
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.