Skip to main content

Custom brainelectronics python helper modules

Project description

BE Helpers

Downloads Release Python License: MIT codecov

Custom brainelectronics python helper modules


General

Collection of custom brainelectronics specific python helper modules.

Installation

pip install be-helpers

Usage

from be_helpers import ModuleHelper
import time
from pathlib import Path

# default name is 'be_helpers.module_helper'
my_logger = ModuleHelper.create_logger()

# set logger level to INFO
ModuleHelper.set_logger_verbose_level(logger=my_logger, verbose_level=3)

# check 'a' to be an option of ['a', 'b', 'c'], result will be True
result = ModuleHelper.check_option_values(options=['a', 'b', 'c'], option='a')
print('"a" is an option of ["a", "b", "c"]: {}'.format(result))
# "a" is an option of ["a", "b", "c"]: True

# get current unix timestamp and format it
now = ModuleHelper.get_unix_timestamp()
time_format = "%H:%M:%S"
print('{}'.format(ModuleHelper.format_timestamp(timestamp=now, format=time_format)))
# 11:30:01

# create a random character number string of length 10
print('{}'.format(ModuleHelper.get_random_string(length=10)))
# 235LS5AY6BPC

# convert a string to a "uint16_t" list, useful for Modbus communications
result = ModuleHelper.convert_string_to_uint16t(content="test")
print('"test" as uint16_t: {}'.format(result))
# "test" as uint16_t: [29797, 29556]

# check for valid files or folders
here = ModuleHelper.get_full_path('.')
ModuleHelper.check_file(here / 'README.md', '.md')
# True

ModuleHelper.check_folder(here)
# True

# load YAML or JSON files as dictionaries
config = ModuleHelper.load_dict_from_file(here / 'tests/data/valid.json')
config = ModuleHelper.load_dict_from_file(here / 'tests/data/valid.yaml')
# {'key': 'val', 'key2': {'key_nested': 'val_nested'}, 'key3': ['asdf', 123, {'key4': 'val4'}]}

# save dictionaries as JSON or YAML files
ModuleHelper.save_dict_to_file(path=here / 'example/cfg.json', content=config)
ModuleHelper.save_dict_to_file(path=here / 'example/cfg.yaml', content=config)
# True

Contributing

Unittests

Run the unittests locally with the following command after installing this package in a virtual environment

# run all tests
nose2 --config tests/unittest.cfg

# run only one specific tests
nose2 tests.test_module_helper.TestModuleHelper.test_set_logger_verbose_level

Generate the coverage files with

python create_report_dirs.py
coverage html

The coverage report is placed at be-helpers/reports/coverage/html/index.html

Credits

Based on the PyPa sample project.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

be-helpers-0.1.0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

be_helpers-0.1.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file be-helpers-0.1.0.tar.gz.

File metadata

  • Download URL: be-helpers-0.1.0.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for be-helpers-0.1.0.tar.gz
Algorithm Hash digest
SHA256 d23f8ea1e72acdf1281b7808165140625620bfd07cdfaa5a8d72bbe972b4f942
MD5 943a49d9404eecc5b4774a4523f9039e
BLAKE2b-256 51c1ab693587774117e3d1f8426b65f7685c69a6ccdc61d3ba6ea69725217444

See more details on using hashes here.

File details

Details for the file be_helpers-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: be_helpers-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.14

File hashes

Hashes for be_helpers-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5c9a78325967fac71d6da16bc18be7114f52e02c6e4eb3c8d8cb0fe8548acaba
MD5 839daa9fd3ea0a4c6d419c7eda770f55
BLAKE2b-256 a972705d21fb0ad31ffb1ff8f82533b4c65aa81622edeb3232ef86464a1d71ce

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page