A Python environment detective tool that reports package versions and hardware resources.
—
Generate comprehensive environment reports showing system information, Python version, and package versions. The reporting system supports both manual package specification and automatic dependency detection.
The main reporting class that creates environment reports with customizable package lists and formatting options.
class Report:
def __init__(
self,
additional: list[str | ModuleType] | None = None,
core: list[str | ModuleType] | None = None,
optional: list[str | ModuleType] | None = None,
ncol: int = 4,
text_width: int = 80,
sort: bool = False,
extra_meta: tuple[tuple[str, str], ...] | list[tuple[str, str]] | None = None,
max_width: int | None = None
):
"""
Create an environment report.
Parameters:
- additional (list[str | ModuleType], optional): Additional packages to include
- core (list[str | ModuleType], optional): Core packages to list first
- optional (list[str | ModuleType], optional): Packages to include if available, defaults to ['numpy', 'scipy', 'IPython', 'matplotlib', 'scooby']
- ncol (int): Number of columns in HTML table, default: 4
- text_width (int): Text width for plain text output, default: 80
- sort (bool): Sort packages alphabetically, default: False
- extra_meta (tuple[tuple[str, str], ...] | list[tuple[str, str]], optional): Additional metadata key-value pairs
- max_width (int, optional): Maximum width of HTML table
"""
def __repr__(self) -> str:
"""Return plain text representation of the report."""
def _repr_html_(self) -> str:
"""Return HTML representation for Jupyter notebooks."""
def to_dict(self) -> dict[str, str]:
"""Return report data as dictionary for programmatic access."""
@property
def packages(self) -> dict[str, str]:
"""Dictionary of package names to version strings."""Automatically generate reports based on package distribution dependencies.
class AutoReport(Report):
def __init__(
self,
module: str | ModuleType,
additional: list[str | ModuleType] | None = None,
ncol: int = 3,
text_width: int = 80,
sort: bool = False
):
"""
Auto-generate report for a package and its dependencies.
Parameters:
- module (str | ModuleType): Package name or module to analyze
- additional (list[str | ModuleType], optional): Additional packages to include
- ncol (int): Number of columns in HTML table, default: 3
- text_width (int): Text width for plain text output, default: 80
- sort (bool): Sort packages alphabetically, default: False
"""The Report class provides access to detailed system information through properties:
class Report:
@property
def system(self) -> str:
"""System/OS name with version details."""
@property
def platform(self) -> str:
"""Platform string."""
@property
def machine(self) -> str:
"""Machine type (e.g., 'x86_64')."""
@property
def architecture(self) -> str:
"""Bit architecture (e.g., '64bit')."""
@property
def cpu_count(self) -> int:
"""Number of CPUs in the system."""
@property
def total_ram(self) -> str:
"""Total RAM information (requires psutil)."""
@property
def mkl_info(self) -> str | None:
"""Intel MKL version info if available."""
@property
def date(self) -> str:
"""Current date and time."""
@property
def filesystem(self) -> str | False:
"""File system type (requires psutil, not available on Windows)."""
@property
def sys_version(self) -> str:
"""Python version information."""
@property
def python_environment(self) -> str:
"""Python environment type: 'Jupyter', 'IPython', or 'Python'."""import scooby
# Create a basic report with default optional packages
report = scooby.Report()
print(report)import scooby
import numpy
# Report with specific core and additional packages
report = scooby.Report(
core=['numpy', 'scipy'],
additional=['pandas', 'matplotlib'],
optional=['seaborn', 'plotly'] # Only show if installed
)
print(report)
# Pass module objects instead of strings
report = scooby.Report(additional=[numpy])
print(report)import scooby
# Customize text formatting
report = scooby.Report(
text_width=120,
ncol=2,
sort=True
)
# Add custom metadata
report = scooby.Report(
extra_meta=[
("Project", "My Analysis"),
("Date", "2024-01-15")
]
)
# HTML formatting for Jupyter
report = scooby.Report(max_width=800)
html_output = report._repr_html_()import scooby
# Generate report for numpy and all its dependencies
auto_report = scooby.AutoReport('numpy')
print(auto_report)
# Include additional packages beyond dependencies
auto_report = scooby.AutoReport(
'matplotlib',
additional=['seaborn', 'plotly']
)
print(auto_report)import scooby
report = scooby.Report(additional=['numpy', 'pandas'])
# Access report data as dictionary
data = report.to_dict()
print(f"Python version: {data['Python']}")
print(f"NumPy version: {data.get('numpy', 'Not installed')}")
# Access individual packages
for package, version in report.packages.items():
print(f"{package}: {version}")import scooby
class ProjectReport(scooby.Report):
def __init__(self, additional=None, **kwargs):
# Define project-specific core and optional packages
core = ['numpy', 'pandas', 'matplotlib']
optional = ['seaborn', 'plotly', 'bokeh']
super().__init__(
additional=additional,
core=core,
optional=optional,
**kwargs
)
# Use custom report class
report = ProjectReport(additional=['sklearn'])
print(report)Install with Tessl CLI
npx tessl i tessl/pypi-scooby