Skip to main content

Simple object to navigate complex python objects

Project description

guide

Simple object to navigate complex python objects

To install: pip install guide

Examples

Object that provides a mapping interface to the attributes of python object.

The keys will be the names of the attributes and the values will be Attrs instances of said attributes.

>>> import guide
>>> from guide import Attrs
>>> a = Attrs(guide)
>>> sorted(a)  # you would usually use ``list`` instead of ``sorted`` but the latter is used for test consistency
['Attrs', 'ObjReader', 'base', 'util']
>>> aa = a['Attrs']
>>> sorted(aa)
['get', 'head', 'items', 'keys', 'module_from_path', 'update_keys_cache', 'values']

Here's how you could implement a generator of paths (tuples) of internal module of a given module:

from guide import Attrs
import inspect

def internal_modules(module, path=()):
    if not isinstance(module, Attrs):
        module = Attrs(module)
    prefix = module.src.__name__
    for k, v in module.items():
        if inspect.ismodule(v.src) and v.src.__name__.startswith(prefix):
            yield path + (k,)
            yield from internal_modules(v, path=path + (k,))
>>> import guide
>>> for path in internal_modules(guide):
...     print(path)
('tools',)
('tests',)
('tests', 'simple_tests')
('base',)
('util',)

Recursively collecting objects from modules, submodules, attributes...

The base function for this is guide.tools.recollect. The following submodule_callables is simply constructed from recollect.

>>> import guide
>>> print(*sorted(set(x.__name__ for x in guide.tools.submodule_callables(guide))), sep='\n')
Attrs
ObjReader
copy_attrs
internal_modules
is_an_obj_of_module
is_hashable
not_underscore_prefixed
recollect
submodule_callables

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

guide-0.0.8.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

guide-0.0.8-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file guide-0.0.8.tar.gz.

File metadata

  • Download URL: guide-0.0.8.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for guide-0.0.8.tar.gz
Algorithm Hash digest
SHA256 e4e8f585a619e226a1edd0304ec924cb03b7d70159386c6a7e84656414a4a832
MD5 900456409d09eb268b1325c3054e01e6
BLAKE2b-256 d1d8cbec04e4ad914584aeebbb9188cfcd9904adbe76e0dd5979057022954afc

See more details on using hashes here.

File details

Details for the file guide-0.0.8-py3-none-any.whl.

File metadata

  • Download URL: guide-0.0.8-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.6

File hashes

Hashes for guide-0.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 c55485d814c964bb86cc66d767d5d11a7ffd3e0f144ad6ebb632c3fad99efd71
MD5 9980c9988e8832bdcc474b4a98881297
BLAKE2b-256 64a2246c2635617b42febaa16aa5e5e7e5b5190b5846cc2475d3b7a6c52132f9

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