Functions and script to peek into the callable/argument structure of a set of callables
Project description
na
Functions and script to peek into the callable/argument structure of a set of callables
To install: pip install na
Overview
The na
package provides a suite of tools designed to analyze and visualize the structure of callables (functions, classes, methods) within Python modules, classes, or any iterable collection of callables. It enables users to inspect callable signatures, filter callables based on their type, and generate detailed reports and visualizations of argument usage and defaults across a collection of callables.
Key Features
- Filtering Callables: Select callables based on type (functions, classes, methods, or any callable).
- Signature Extraction: Retrieve the argument names and default values from callables.
- Visualization: Generate heatmaps and bar graphs to visualize the usage and defaults of callable arguments.
- Data Frame Conversion: Convert callable signature data into pandas DataFrames for further analysis or reporting.
Installation
To install the package, use the following pip command:
pip install na
Usage Examples
Getting Callable Signatures as DataFrame
To retrieve and display the signatures of callables within a module as a DataFrame:
import na
import sys # Example module
# Get DataFrame of callable signatures in the sys module
df_signatures = na.callables_signatures_df(sys.modules[__name__])
print(df_signatures)
Visualizing Callable Signatures
To visualize the signatures of callables using a heatmap:
import na
import sys # Example module
# Visualize signatures as a heatmap
na.heatmap_of_signatures(sys.modules[__name__])
Plotting Non-Null Counts of Signatures
To plot the count of non-null/default arguments for callables:
import na
import sys # Example module
# Plot non-null counts of signatures
na.plot_nonnull_counts_of_signatures(sys.modules[__name__])
API Reference
callables_of_module(module, callable_filt='callable')
Retrieve callables from a specified module.
- module: The module from which to retrieve callables.
- callable_filt: Filter criterion for what type of callables to retrieve (e.g., 'callable', 'class', 'function').
callables_of_class(cls, callable_filt='function')
Retrieve callables from a specified class.
- cls: The class from which to retrieve callables.
- callable_filt: Filter criterion for what type of callables to retrieve.
get_callables_from(callables, callable_filt='callable')
Get a generator of callable objects from various types of inputs like modules, classes, or lists of callables.
- callables: Input from which to extract callables.
- callable_filt: Filter criterion for what type of callables to retrieve.
SignatureExtractor(normalize_var_names=True)
Class to extract and normalize parameter names and defaults from callables.
- normalize_var_names: Whether to normalize variable names like
*args
and**kwargs
.
arg_default_dict_of_callables(callables, callable_filt='callable')
Get a dictionary with callable names as keys and another dictionary of argument names and their default values as values.
- callables: Input from which to extract callables.
- callable_filt: Filter criterion for what type of callables to retrieve.
heatmap(...)
Function to create a heatmap from a matrix or DataFrame.
- X: Data to plot as a heatmap.
- other parameters: Customization options for the heatmap appearance.
heatmap_of_signatures(callables, callable_filt='callable', ...)
Visualize the argument structure of callables as a heatmap.
- callables: Input from which to extract callables.
- callable_filt: Filter criterion for what type of callables to retrieve.
plot_nonnull_counts_of_signatures(callables, callable_filt='callable', ...)
Plot the count of non-null/default arguments for callables.
- callables: Input from which to extract callables.
- callable_filt: Filter criterion for what type of callables to retrieve.
Contributing
Contributions to the na
package are welcome! Please feel free to fork the repository, make changes, and submit pull requests. For major changes, please open an issue first to discuss what you would like to change.
License
This project is licensed under the MIT License - see the LICENSE file for details.
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
Built Distribution
File details
Details for the file na-0.0.6.tar.gz
.
File metadata
- Download URL: na-0.0.6.tar.gz
- Upload date:
- Size: 9.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
a384f991e24be80bbb1d6856949739bd0ae902c33ad22f7681570a694c3e899e
|
|
MD5 |
a5b6fa52000237eccf7c4df86dd29203
|
|
BLAKE2b-256 |
a9fa7566673e01eae90f82c3817e148570d11206c6aa98cc7eef37c04fbae4c2
|
File details
Details for the file na-0.0.6-py3-none-any.whl
.
File metadata
- Download URL: na-0.0.6-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.13
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
99d7176220ed936605e25b574245e358fbc06de2aad7e5bef704156b1472cee2
|
|
MD5 |
6cf8eabfd89d295c39e0644321773913
|
|
BLAKE2b-256 |
f8221e1358b7d01734af7ee1a388b5a8eef39259f5d9ff68c028caa1a3b5f04f
|