Skip to main content

pyTooling is a powerful collection of arbitrary useful classes, decorators, meta-classes and exceptions.

Project description

Sourcecode on GitHub Sourcecode License Documentation Documentation License
PyPI PyPI - Status PyPI - Python Version
GitHub Workflow - Build and Test Status Libraries.io status for latest release Codacy - Quality Codacy - Coverage Codecov - Branch Coverage

pyTooling

pyTooling is a powerful collection of arbitrary useful abstract data models, classes, decorators, meta-classes and exceptions. It also provides lots of helper functions e.g. to ease the handling of package descriptions.

It's useful for any Python-base project independent if it's a library, framework or CLI tool.

Introduction

pyTooling is a basic collection of powerful helpers needed by almost any Python project. More specialized helpers can be found in sub-namespaces like:

In addition, pyTooling provides a collection of CI job templates for GitHub Actions. This drastically simplifies GHA-based CI pipelines for Python projects.

Package Details

Common Helper Functions

This is a set of useful helper functions:

  • getsizeof calculates the "real" size of a data structure.
  • isnestedclass checks if a class is nested inside another class.
  • mergedicts merges multiple dictionaries into a new dictionary.
  • zipdicts iterate multiple dictionaries simultaneously.

Common Classes

  • Python doesn't provide call-by-reference parameters for simple types. This behavior can be emulated with classes provided by the pyTooling.CallByRef module.
  • Setuptools, PyPI, and others have a varying understanding of license names. The pyTooling.Licensing module provides unified license names as well as license name mappings or translations.
  • Python has many ways in figuring out the current platform using APIs from sys, platform, os, …. Unfortunately, none of the provided standard APIs offers a comprehensive answer. pyTooling provides a unified platform and environment description by summarizing multiple platform APIs into a single class instance.
  • While Python itself has a good versioning schema, there are no classes provided to abstract version numbers. pyTooling provides such a representations of version numbers following semantic versioning (SemVer) and calendar versioning (CalVer) schemes. It's provided by the pyTooling.Versioning module.

Configuration

Various file formats suitable for configuration information share the same features supporting: key-value pairs (dictionaries), sequences (lists), and simple types like string, integer and float. pyTooling provides an abstract configuration file data model supporting these features. Moreover, concrete configuration file format reader implementations are provided as well.

Data Structures

pyTooling also provides fast and powerful data structures offering object-oriented APIs:

Decorators

  • Abstract Methods
    • Methods marked with abstractmethod are abstract and need to be overwritten in a derived class.
      An abstract method might be called from the overwriting method.
    • Methods marked with mustoverride are abstract and need to be overridden in a derived class.
      It's not allowed to call a mustoverride method.
  • Documentation
    • Copy the doc-string from given base-class via InheritDocString.
  • Visibility
    • Register the given function or class as publicly accessible in a module via export.
  • Documentation
  • Visibility
    • @export
      → Register the given function or class as publicly accessible in a module.

Exceptions

Meta-Classes

pyTooling provides an enhanced meta-class called ExtendedType. This meta-classes allows to implement abstract methods, singletons, slotted types and combinations thereof.

class MyClass(metaclass=ExtendedType): A class definition using that meta-class can implement abstract methods using decorators @abstractmethod or @mustoverride.

class MyClass(metaclass=ExtendedType, singleton=True): A class defined with enabled singleton behavior allows only a single instance of that class to exist. If another instance is going to be created, a previously cached instance of that class will be returned.

class MyClass(metaclass=ExtendedType, useSlots=True): A class defined with enabled useSlots behavior stores instance fields in slots. The meta-class, translates all type-annotated fields in a class definition into slots. Slots allow a more efficient field storage and access compared to dynamically stored and accessed fields hosted by __dict__. This improves the memory footprint as well as the field access performance of all class instances. This behavior is automatically inherited to all derived classes.

class MyClass(ObjectWithSlots): A class definition deriving from ObjectWithSlots will bring the slotted type behavior to that class and all derived classes.

Packaging

A set of helper functions to describe a Python package for setuptools.

  • Helper Functions:
    • loadReadmeFile
      Load a README.md file from disk and provide the content as long description for setuptools.
    • loadRequirementsFile
      Load a requirements.txt file from disk and provide the content for setuptools.
    • extractVersionInformation
      Extract version information from Python source files and provide the data to setuptools.
  • Package Descriptions
    • DescribePythonPackage
      tbd
    • DescribePythonPackageHostedOnGitHub
      tbd

Examples

@export Decorator

from pyTooling.Decorators import export

@export
class MyClass:
  pass

CallByRefIntParam

from pyTooling.CallByRef import CallByRefIntParam

# define a call-by-reference parameter for integer values
myInt = CallByRefIntParam(3)

# a function using a call-by-reference parameter
def func(param: CallByRefIntParam):
  param <<= param * 4

# call the function and pass the wrapper object
func(myInt)

print(myInt.Value)

Contributors

License

This Python package (source code) licensed under Apache License 2.0.
The accompanying documentation is licensed under Creative Commons - Attribution 4.0 (CC-BY 4.0).


SPDX-License-Identifier: Apache-2.0

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

pyTooling-2.8.0.tar.gz (54.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyTooling-2.8.0-py3-none-any.whl (62.3 kB view details)

Uploaded Python 3

File details

Details for the file pyTooling-2.8.0.tar.gz.

File metadata

  • Download URL: pyTooling-2.8.0.tar.gz
  • Upload date:
  • Size: 54.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for pyTooling-2.8.0.tar.gz
Algorithm Hash digest
SHA256 3e58a3fcb36a1eba859b11fcc81c6d979e2131c76150b8a86df7758406687d40
MD5 79bf212d2f9a5307a369def52941560c
BLAKE2b-256 74ded1fd7747613796cd4640cd4b97bbb8b59ba88a464f5c21d480f3aed79798

See more details on using hashes here.

File details

Details for the file pyTooling-2.8.0-py3-none-any.whl.

File metadata

  • Download URL: pyTooling-2.8.0-py3-none-any.whl
  • Upload date:
  • Size: 62.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for pyTooling-2.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 63a4eb44a76e884cd1838e15cc50b5c3a647ba094f97ca0c8c2df15a88396a67
MD5 0f2269a73ae8306977bfde0f532bc5e8
BLAKE2b-256 6e2ed7618b4ae3a6e8852af1fda22119859306bc2d0c10e9baf05fc8e373f8ac

See more details on using hashes here.

Supported by

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