Various utilities for common tasks
Project description
shinyutils
Various utilities for common tasks. :sparkles: :sparkles: :sparkles:
Setup
Install with pip
.
pip install shinyutils
matwrap
Wrapper around matplotlib
and seaborn
.
Usage
from shinyutils import MatWrap as mw # do not import `matplotlib`, `seaborn`
fig = mw.plt().figure()
ax = fig.add_subplot(111) # `ax` can be used normally now
# Use class methods in `MatWrap` to access `matplotlib`/`seaborn` functions.
mw.mpl() # returns `matplotlib` module
mw.plt() # returns `matplotlib.pyplot` module
mw.sns() # returns `seaborn` module
# Use `set_size_tight` to set size with a tight layout.
mw.set_size_tight(fig, (4, 3))
subcls
Utility functions for dealing with subclasses.
Functions
get_subclasses(cls)
: returns a list of all the subclasses ofcls
.get_subclass_names(cls)
: returns a list of names of all subclasses ofcls
.get_subclass_from_name(base_cls, cls_name)
: return the subclass ofbase_cls
namedcls_name
.build_subclass_object(base_cls, cls_name, kwargs)
: return an instance ofget_subclass_from_name
initialized usingkwargs
.
argp
Utilities for argument parsing.
LazyHelpFormatter
HelpFormatter
with sane defaults, and colors (courtesy of crayons
)! To use, simply pass formatter_class=LazyHelpFormatter
when creating ArgumentParser
instances.
arg_parser = ArgumentParser(formatter_class=LazyHelpFormatter)
sub_parsers = arg_parser.add_subparsers(dest="cmd")
sub_parsers.required = True
# `formatter_class` needs to be set for sub parsers as well.
cmd1_parser = sub_parsers.add_parser("cmd1", formatter_class=LazyHelpFormatter)
comma_separated_ints
ArgumentParser
type representing a comma separated list of ints (example 1,2,3,4
).
arg_parser.add_argument("--csi", type=comma_separated_ints)
logng
Utilities for logging.
build_log_argp
Creates an argument group with logging arguments.
>>> arg_parser = ArgumentParser()
>>> log_parser = build_log_argp(arg_parser)
>>> arg_parser.print_help()
usage: python [-h] [--log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}]
[--log-file LOG_FILE]
optional arguments:
-h, --help show this help message and exit
logging:
--log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}
--log-file LOG_FILE
conf_logging
Configures global logging (and adds colors!) using arguments returned by ArgumentParser.parse_args
. Both log_level
and log_file
can be over-ridden with keyword arguments to the function. Colors are not enabled if logging to a file.
args = arg_parser.parse_args()
conf_logging(args)
conf_logging(args, log_level="INFO") # override `log_level`
conf_logging(log_level="ERROR", log_file="log.out") # `args` is also optional
logging.info("this won't be logged")
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 shinyutils-0.1.0-py34.py35.py36.py37-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 200c9e0f17a22e4340e3e75b52ced6d898af147c8dcbb6920667a7934d3db4a9 |
|
MD5 | a58e74c64d16032989d47d963d6bc81a |
|
BLAKE2b-256 | 8c4aaeb1857d03b27a62365aab4d814fee650944fa0997efbeb7a1e01c7f5edc |