My friendly library base class - for Python.
Project description
mybase
![PyPI version](https://pypi-camo.freetls.fastly.net/6edced74c6e6f24dcfc4a556bb3819475c1b4da8/68747470733a2f2f62616467652e667572792e696f2f70792f6d79626173652e737667)
My library base class - for Python.
Introduction
One in general tend to need a library specific base class, but creating one for every new library with some common logger customization means redundant work every time. This library base class right now don't do much now beside setting up a default logger, but keeps library code a bit cleaner.
Install
Install using pip:
$ pip install mybase
Use
Very basic example:
from mybase import Base
class Foo(Base):
def hello():
self.logger.log('hello from instance: `{0}`'.format(self))
foo = Foo()
# logs using default logger - with colors unless disabled via `COLORS` / `LOGGER_COLORS` env variables
foo.hello()
foo.logger.log('hello world 1')
print(foo.name)
print(repr(foo))
print(str(foo))
import logging
foo2 = Foo(logger = logging.get_logger('custom'))
# logs using custom logger
foo.hello()
foo.logger.log('hello world 2')
foo3 = Foo(logger = False)
# logs nothing
foo.hello()
foo.logger.log('hello world 3')
Test
Clone down source code:
$ make install
Run colorful tests, with only native environment (dependency sandboxing up to you):
$ make test
Run less colorful tests, with multi-environment (using tox):
$ make test-tox
Related
mybad
- "My error base class - for Python"
About
This project was mainly initiated - in lack of solid existing alternatives - to be used at our work at Markable.ai to have common code conventions between various programming environments where Python (research, CV, AI) is heavily used.
License
Released under the MIT license.
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.