Skip to main content

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>

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.18.tar.gz (43.1 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.18-py3-none-any.whl (45.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tec-0.0.18.tar.gz
  • Upload date:
  • Size: 43.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for tec-0.0.18.tar.gz
Algorithm Hash digest
SHA256 08ca1d359700220279958c1b500c3b0c65dcc28def7ca01dff85029079fd2983
MD5 66786b7b63ef0e9aec8198d3897a42a0
BLAKE2b-256 4658040f13858e827ac136e2338bd96931b7b744d6611a4ba4cfba28cfc3c8b3

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tec-0.0.18-py3-none-any.whl
  • Upload date:
  • Size: 45.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for tec-0.0.18-py3-none-any.whl
Algorithm Hash digest
SHA256 de9a0949fe1e4a2a0d82f0d6e779b81670b84b4429590a7ed08db3a10bd21bfd
MD5 2837d24f40cc4997f4588d4272d1fe6e
BLAKE2b-256 63642c8f393f4d9a81b3a278adcfdefd182ed44030fc42148617d005b8bf11dc

See more details on using hashes here.

Release history Release notifications | RSS feed

0.0.20

2 files

0.0.19

2 files

This release

0.0.18 This release

2 files

0.0.17

2 files

0.0.16

2 files

0.0.15

2 files

0.0.12

2 files

0.0.11

2 files

0.0.10

2 files

0.0.9

2 files

0.0.8

2 files

0.0.7

2 files

0.0.6

2 files

0.0.5

2 files

0.0.4

2 files

0.0.3

2 files

0.0.2

2 files

0.0.1

2 files

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