Skip to main content

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

Installation

pip install b3j0f.utils

Features

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).

Examples

Chaining

>>> # 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._
test
>>> # call several strings operations on several strings and get operation results in one line
>>> ListChaining("Test", "Example").upper().lower()[:]
[["TEST", "EXAMPLE"], ["test", "example"]]

Iterable

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

Path

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

Property

>>> from b3j0f.utils.property 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 b3j0f.utils.property 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

Reflect

>>> 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__
Test
>>> base_elts(FinalTest().test)[-1].im_class.__name__
BaseTest
>>> is_inherited(FinalTest.test)
True
>>> is_inherited(BaseTest.test)
False

Proxy

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

Runtime

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

Version

>>> 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.

UT

>>> 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.
True

Perspectives

  • Cython implementation.

Donation

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

Metadata

Release files for b3j0f.utils 1.4.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distributions (sdists)

Source distribution for b3j0f.utils 1.4.4
File Size Uploaded
b3j0f.utils-1.4.4.zip 64.4 kB Details
b3j0f.utils-1.4.4.tar.gz 38.3 kB Details
b3j0f.utils-1.4.4.tar.bz2 32.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for b3j0f.utils 1.4.4
File Interpreter ABI Platform
b3j0f.utils-1.4.4-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 251.6 kB

Release files / b3j0f.utils-1.4.4.zip

Download URL b3j0f.utils-1.4.4.zip
Size 64.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6eb978d4b202c2021e1e2ac989422d2fb3c781571c3814f9224d60c75e2ede1d
BLAKE2b-256 checksum
How to use checksums
4abc688a80962934ccf6b95c9c961546bda50b6dd460813fad91d0dba9220137
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / b3j0f.utils-1.4.4.tar.gz

Download URL b3j0f.utils-1.4.4.tar.gz
Size 38.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f8a0298038b5bb2971185a38a4465c3170f731f6e341209244aff4f54d7a933d
BLAKE2b-256 checksum
How to use checksums
b7167c2ea3c37801e534cd7df774950e60e69831cbef8d082300244aa83eb50b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / b3j0f.utils-1.4.4.tar.bz2

Download URL b3j0f.utils-1.4.4.tar.bz2
Size 32.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f4f58c94ae41d6aa313d4046ee4a24bd48172929c7f719c097ed9a78de87b0a1
BLAKE2b-256 checksum
How to use checksums
0860336d06bb25b5fe7da19d9ee4018cc932f4b55c7cf1ab195f1afe55c81b27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / b3j0f.utils-1.4.4-py2.py3-none-any.whl

Download URL b3j0f.utils-1.4.4-py2.py3-none-any.whl
Size 116.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
723d7bcc22edd6af3f2a068197601f4f2348305dd972183bc6c95ecab189648b
BLAKE2b-256 checksum
How to use checksums
6a73b84d8840e183bb372b254375f34c5ec6e7d01e2ef5bc0bd3f9c0b709a7a7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.4.4 This release

4 release files

1.4.3

4 release files

1.4.2

4 release files

1.4.1

4 release files

1.1.0

3 release files

1.0.0

3 release files

0.10.4

3 release files

0.10.3

3 release files

0.10.2

3 release files

0.10.1

3 release files

0.10.0

3 release files

0.9.5

3 release files

0.9.3

3 release files

0.9.1

3 release files

0.9

3 release files

0.8.8

2 release files

0.8.7

2 release files

0.8.6

2 release files

0.8.5

2 release files

0.8.4

2 release files

0.8.2

0.8.1

1 release file

0.8.0

1 release file

0.7.11

1 release file

0.7.10

1 release file

0.7.9

1 release file

0.7.8

0.7.7

1 release file

0.7.6

1 release file

0.7.5

1 release file

0.7.4

1 release file

0.7.3

1 release file

0.7.2

1 release file

0.7.0

1 release file

0.6.0

1 release file

0.5.13

1 release file

0.5.11

1 release file

0.5.10

1 release file

0.5.8

1 release file

0.5.7

1 release file

0.5.6

1 release file

0.5.4

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3

1 release file

0.2.0

1 release file

0.1.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page