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
*argsand**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.
Release files for na 0.0.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| na-0.0.7.tar.gz | 10.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| na-0.0.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.3 kB
Release files / na-0.0.7.tar.gz
| Download URL | na-0.0.7.tar.gz |
|---|---|
| Size | 10.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
012707694e14d6272af0906791daf7b7df87bf3bc435a23559760147f9c3728c
|
|
BLAKE2b-256 checksum How to use checksums |
0d34a43727d15734f708d308b3d2a2ceba034ee489c434ebf9a1b2f45968eeda
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / na-0.0.7-py3-none-any.whl
| Download URL | na-0.0.7-py3-none-any.whl |
|---|---|
| Size | 10.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2f4ec9fcd38925fad3f64a07a81994aad98b045ee9f71619e36f734cce1ca27c
|
|
BLAKE2b-256 checksum How to use checksums |
b448960bacc99b6d71ef233c968804567b454e522aa4e16a285ecc59b996d922
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|