# 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.
```python
>>> 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
```pydocstring
>>> 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).
```pydocstring
>> 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
```pydocstring
>>> 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>
```
Raw data
{
"_id": null,
"home_page": "https://github.com/thorwhalen/tec",
"name": "tec",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "Thor Whalen",
"author_email": "",
"download_url": "https://files.pythonhosted.org/packages/84/5e/39f52efd41a5b9a3502bbaf61d193b2eb2a6d4baac0317897638f3ee0209/tec-0.0.17.tar.gz",
"platform": "any",
"description": "\n# tec\nTools to inspect python objects\n\n\nTo install:\t```pip install tec```\n\n\n# Examples\n\n## Counting imported names\n\n``modules_imported`` is a generator of module names from obj. \nIt uses string parsing, so is not as accurate as some other methods, but is fast and flexible, \nand doesn't require actually running any of the code analyzed.\n \n```python\n>>> from tec import modules_imported\n>>> import os.path # single module\n>>> list(modules_imported(os.path)) # list of names in the order they were found\n['os', 'sys', 'stat', 'genericpath', 'genericpath', 'pwd', 'pwd', 're', 're']\n>>> import os # package with several modules\n>>> from collections import Counter\n>>> Counter(modules_imported(os, only_base_name=True)).most_common() #doctest: +ELLIPSIS\n[('nt', 5), ('posix', 4), ... ('warnings', 1), ('subprocess', 1)]\n```\n\n## Modules\n\n```pydocstring\n>>> from tec import modules\n>>> sorted(modules.second_party_names(modules))[:5]\n['DOTPATH', 'FILEPATH', 'FOLDERPATH', 'LOADED', 'ModuleSpecKind']\n>>> sorted(modules.second_party_names(modules, callable))[:4]\n['ModuleSpecKind', 'coerce_module_spec', 'filepath_to_dotpath', 'finding_objects_of_module_with_given_methods']\n>>> sorted(modules.second_party_names(modules, lambda obj: isinstance(obj, type)))\n['ModuleSpecKind']\n```\n\n## Packages\n\nA few functions to investigate what objects can be imported from a module\n(and the depth of the dot-path to import those objects directly).\n\nThe main function, ``print_top_level_diagnosis``,\nprints a diagnosis of the imports that can be optained from the (top level) module.\nThat is, those objects that can by imported by doing:\n```\nfrom module import obj\n```\nthough the object's code may be several package levels down (say module.sub1.sub2.obj).\n\n\n```pydocstring\n>> import numpy, pandas, scipy\n>> print_top_level_diagnosis(numpy)\n--------- numpy ---------\n601 objects can be imported from top level numpy:\n 20 modules\n 300 functions\n 104 types\n\ndepth\tcount\n0\t163\n1\t406\n2\t2\n3\t29\n4\t1\n\n>> print_top_level_diagnosis(pandas)\n--------- pandas ---------\n115 objects can be imported from top level pandas:\n 12 modules\n 55 functions\n 40 types\n\ndepth\tcount\n0\t12\n3\t37\n4\t65\n5\t1\n\n>> print_top_level_diagnosis(scipy)\n--------- scipy ---------\n582 objects can be imported from top level scipy:\n 9 modules\n 412 functions\n 96 types\n\ndepth\tcount\n0\t61\n1\t395\n2\t4\n3\t122\n```\n\n\n## Peek\n\n```pydocstring\n>>> from tec.peek import print_signature\n>>> print_signature(print_signature)\nfunc\nsep: Union[str, NoneType] = '\\\\n'\nprefix: str = ''\nsuffix: str = ''\n>>> print_signature(print_signature, None)\n(func, sep: Union[str, NoneType] = '\\\\n', prefix: str = '', suffix: str = '')\n>>> print_signature(print_signature, '\\\\n * ', prefix=' * ', suffix='\\\\n')\n * func\n * sep: Union[str, NoneType] = '\\\\n'\n * prefix: str = ''\n * suffix: str = ''\n<BLANKLINE>\n```\n",
"bugtrack_url": null,
"license": "apache-2.0",
"summary": "Tools to inspect python objects",
"version": "0.0.17",
"project_urls": {
"Homepage": "https://github.com/thorwhalen/tec"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "88252fbf74d5854c751f13741784bf2c65df00705639f9f2ec4e423dd01b2434",
"md5": "610c294d7957b222a0c5ae4b2b88a6fe",
"sha256": "36af93eb44c2ba101474fb7eabad0a94ca7a54ee665b67742782be8f257fdefb"
},
"downloads": -1,
"filename": "tec-0.0.17-py3-none-any.whl",
"has_sig": false,
"md5_digest": "610c294d7957b222a0c5ae4b2b88a6fe",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 43257,
"upload_time": "2023-10-20T12:53:36",
"upload_time_iso_8601": "2023-10-20T12:53:36.337366Z",
"url": "https://files.pythonhosted.org/packages/88/25/2fbf74d5854c751f13741784bf2c65df00705639f9f2ec4e423dd01b2434/tec-0.0.17-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "845e39f52efd41a5b9a3502bbaf61d193b2eb2a6d4baac0317897638f3ee0209",
"md5": "4ce1482d6066687b777d906d2a13a659",
"sha256": "7eaf5eee31055ef521c6f118f7c71c5120839e14079c97abf44480629b3ddb56"
},
"downloads": -1,
"filename": "tec-0.0.17.tar.gz",
"has_sig": false,
"md5_digest": "4ce1482d6066687b777d906d2a13a659",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 39758,
"upload_time": "2023-10-20T12:53:39",
"upload_time_iso_8601": "2023-10-20T12:53:39.503887Z",
"url": "https://files.pythonhosted.org/packages/84/5e/39f52efd41a5b9a3502bbaf61d193b2eb2a6d4baac0317897638f3ee0209/tec-0.0.17.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-10-20 12:53:39",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "thorwhalen",
"github_project": "tec",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "tec"
}