Skip to main content

Tools to inspect python objects

Project description

tec

Tools to inspect python objects

To install: pip install tec

Examples

Counting imported names

modules_imported is a generator of module names from obj. It uses string parsing, so is not as accurate as some other methods, but is fast and flexible, and doesn't require actually running any of the code analyzed.

>>> from tec import modules_imported
>>> import os.path  # single module
>>> list(modules_imported(os.path))  # list of names in the order they were found
['os', 'sys', 'stat', 'genericpath', 'genericpath', 'pwd', 'pwd', 're', 're']
>>> import os  # package with several modules
>>> from collections import Counter
>>> Counter(modules_imported(os, only_base_name=True)).most_common()  #doctest: +ELLIPSIS
[('nt', 5), ('posix', 4), ... ('warnings', 1), ('subprocess', 1)]

Modules

>>> from tec import modules
>>> sorted(modules.second_party_names(modules))[:5]
['DOTPATH', 'FILEPATH', 'FOLDERPATH', 'LOADED', 'ModuleSpecKind']
>>> sorted(modules.second_party_names(modules, callable))[:4]
['ModuleSpecKind', 'coerce_module_spec', 'filepath_to_dotpath', 'finding_objects_of_module_with_given_methods']
>>> sorted(modules.second_party_names(modules, lambda obj: isinstance(obj, type)))
['ModuleSpecKind']

Packages

A few functions to investigate what objects can be imported from a module (and the depth of the dot-path to import those objects directly).

The main function, print_top_level_diagnosis, prints a diagnosis of the imports that can be optained from the (top level) module. That is, those objects that can by imported by doing:

from module import obj

though the object's code may be several package levels down (say module.sub1.sub2.obj).

>> import numpy, pandas, scipy
>> print_top_level_diagnosis(numpy)
--------- numpy ---------
601 objects can be imported from top level numpy:
  20 modules
  300 functions
  104 types

depth	count
0	163
1	406
2	2
3	29
4	1

>> print_top_level_diagnosis(pandas)
--------- pandas ---------
115 objects can be imported from top level pandas:
  12 modules
  55 functions
  40 types

depth	count
0	12
3	37
4	65
5	1

>> print_top_level_diagnosis(scipy)
--------- scipy ---------
582 objects can be imported from top level scipy:
  9 modules
  412 functions
  96 types

depth	count
0	61
1	395
2	4
3	122

Peek

>>> from tec.peek import print_signature
>>> print_signature(print_signature)
func
sep: Union[str, NoneType] = '\\n'
prefix: str = ''
suffix: str = ''
>>> print_signature(print_signature, None)
(func, sep: Union[str, NoneType] = '\\n', prefix: str = '', suffix: str = '')
>>> print_signature(print_signature, '\\n * ', prefix=' * ', suffix='\\n')
 * func
 * sep: Union[str, NoneType] = '\\n'
 * prefix: str = ''
 * suffix: str = ''
<BLANKLINE>

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

tec-0.0.17.tar.gz (39.8 kB view details)

Uploaded Source

Built Distribution

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

tec-0.0.17-py3-none-any.whl (43.3 kB view details)

Uploaded Python 3

File details

Details for the file tec-0.0.17.tar.gz.

File metadata

  • Download URL: tec-0.0.17.tar.gz
  • Upload date:
  • Size: 39.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for tec-0.0.17.tar.gz
Algorithm Hash digest
SHA256 7eaf5eee31055ef521c6f118f7c71c5120839e14079c97abf44480629b3ddb56
MD5 4ce1482d6066687b777d906d2a13a659
BLAKE2b-256 845e39f52efd41a5b9a3502bbaf61d193b2eb2a6d4baac0317897638f3ee0209

See more details on using hashes here.

File details

Details for the file tec-0.0.17-py3-none-any.whl.

File metadata

  • Download URL: tec-0.0.17-py3-none-any.whl
  • Upload date:
  • Size: 43.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.8

File hashes

Hashes for tec-0.0.17-py3-none-any.whl
Algorithm Hash digest
SHA256 36af93eb44c2ba101474fb7eabad0a94ca7a54ee665b67742782be8f257fdefb
MD5 610c294d7957b222a0c5ae4b2b88a6fe
BLAKE2b-256 88252fbf74d5854c751f13741784bf2c65df00705639f9f2ec4e423dd01b2434

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