Skip to main content

Set of tools and utilities useful in python projects

Project description


Utilities for Python.

License Development Status Latest release Supported Python versions Supported Python implementations Download format Build status Code test coverage Downloads Documentation Status Code Health


pip install b3j0f.utils


This library provides a set of generic tools in order to ease development of projects in python >= 2.6.

Provided tools are:

  • chaining: chain object methods calls in a dedicated Chaining object. Such method calls return the Chaining object itself, allowing multiple calls to object methods to be invoked in a concise statement.

  • iterable: tools in order to manage iterable elements.

  • path: python object path resolver, from object to absolute/relative path or the inverse.

  • property: (un)bind/find properties in reflective and oop concerns.

  • reflect: tools which ease development with reflective concerns.

  • runtime: ease runtime execution (transform dynamic variable to static variable in function, provide safe eval/exec functions).

  • proxy: create proxy (from design pattern) objects from a routine or an object which respects the signature and description of the proxified element.

  • ut: improve unit tests.

  • version: ease compatibility between python version (from 2.x to 3.x).



>>> # add characters to a string in one line
>>> from b3j0f.utils.chaining import Chaining, ListChaining
>>> c = Chaining("te").__iadd__("s").__iadd__("t")
>>> # display content of Chaining
>>> c._
>>> # call several strings operations on several strings and get operation results in one line
>>> ListChaining("Test", "Example").upper().lower()[:]
[["TEST", "EXAMPLE"], ["test", "example"]]


>>> from b3j0f.utils.iterable import is_iterable, first, last, itemat, sliceit, hashiter
>>> is_iterable(1)
>>> is_iterable('aze')
>>> is_iterable('aze', exclude=str)
>>> from b3j0f.utils.version import OrderedDict
>>> od = OrderedDict((('1', 2), ('3', 4), ('5', 6)))
>>> first(od)
>>> first({}, default='test')
>>> last(od)
>>> last('', default='test')
>>> itemat(od, -1)
>>> itemat(od, 1)
>>> sliceit(od, -2, -1)
>>> hashiter([1, 2])


>>> from b3j0f.utils.path import lookup, getpath
>>> getpath(lookup)
>>> getpath(lookup("b3j0f.utils.path.getpath"))


>>> from import put_properties, get_properties, del_properties
>>> put_properties(min, {'test': True})
>>> assert get_properties(min) == {'test': True}
>>> del_properties(min)
>>> assert get_properties(min) is None
>>> from import addproperties
>>> def before(self, value, name):  # define a before setter
>>>     self.before = value if hasattr(self, 'after') else None
>>> def after(self, value, name):
>>>     self.after = value + 2  # define a after setter
>>> @addproperties(['test'], bfset=before, afset=after)  # add python properties
>>> class Test(object):
>>>     pass
>>> assert isinstance(Test.test, property)  # assert property is bound
>>> test = Test()
>>> test.test = 2
>>> assert test.update is None  # assert before setter
>>> assert test.test == test._test == 2  # assert default setter
>>> assert test.after == 4


>>> from b3j0f.utils.reflect import base_elts, is_inherited
>>> class BaseTest(object):
>>>     def test(self): pass
>>> class Test(BaseTest): pass
>>> class FinalTest(Test): pass
>>> base_elts(FinalTest().test, depth=1)[-1].im_class.__name__
>>> base_elts(FinalTest().test)[-1].im_class.__name__
>>> is_inherited(FinalTest.test)
>>> is_inherited(BaseTest.test)


>>> from b3j0f.utils.proxy import get_proxy, proxified_elt
>>> l = lambda: 2
>>> proxy = get_proxy(l, lambda: 3)
>>> proxy()
>>> assert proxified_elt(proxy) is l
>>> proxified_elt(proxy)()
>>> proxy = get_proxy(l)
>>> proxy()
>>> assert proxy is not l
>>> assert proxified_elt(proxy) is l


>>> from b3j0f.utils.runtime import safe_eval
>>> try:
>>>     safe_eval('open')
>>> except NameError:
>>>     print('open does not exist')
open does not exist


>>> from b3j0f.utils.version import getcallargs
>>> # getcallargs is same function from python>2.7 for python2.6
>>> from b3j0f.utils.version import PY3, PY2, PY26, PY27
>>> # PY3 is True if python version is 3, etc.


>>> from b3j0f.utils.ut import UTCase  # class which inherits from unittest.TestCase
>>> UTCase.assertIs and True  # all methods of python2/3 TestCase are implemented in the UTCase for python v>2.


  • Cython implementation.


I'm grateful for gifts, but don't have a specific funding goal.

Download files

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

Source Distributions (64.4 kB view hashes)

Uploaded source

b3j0f.utils-1.4.4.tar.gz (38.3 kB view hashes)

Uploaded source

b3j0f.utils-1.4.4.tar.bz2 (32.5 kB view hashes)

Uploaded source

Built Distribution

b3j0f.utils-1.4.4-py2.py3-none-any.whl (116.4 kB view hashes)

Uploaded 2 7

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