=============== LIBRARY RULES =============== From library maintainers: - Install with pip install pypi-package-stats and import from pypipackagestats; the CLI needs pip install "pypi-package-stats[cli]". - get_package_stats(name) returns a frozen PackageStats dataclass; call .to_dict() for JSON-ready output. - Results are cached on disk for 3600 seconds by default; pass no_cache=True or cache_ttl=0 to bypass the cache. ### Install library with CLI support Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/README.md Install the library with CLI support using the [cli] extra. ```bash pip install pypi-package-stats[cli] ``` -------------------------------- ### Package statistics examples Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/CLI.md Examples of fetching package statistics with different options: human-friendly output, JSON, bypass cache, and custom TTL. ```bash # Human-friendly Rich table output pypi-package-stats package requests ``` ```bash # Machine-readable JSON output pypi-package-stats package requests --json ``` ```bash # Fresh data (bypass cache) pypi-package-stats package django --no-cache ``` ```bash # Custom cache TTL (5 minutes) pypi-package-stats package flask --cache-ttl 300 ``` -------------------------------- ### CLI command example: pypi-package-stats package nestedutils --json Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/README.md Run the CLI to get package metadata and download statistics in JSON format. Requires the 'cli' extra: pip install pypi-package-stats[cli]. ```bash pypi-package-stats package nestedutils --json ``` -------------------------------- ### Show help Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/CLI.md Command to show help for the CLI. ```bash pypi-package-stats --help ``` -------------------------------- ### CLI dependencies not installed error Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/CLI.md Error message shown when CLI dependencies are missing, with installation instruction. ```text Error: CLI dependencies not installed. Install with: pip install pypi-package-stats[cli] ``` -------------------------------- ### Example JSON output from pypi-package-stats Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/README.md Sample JSON response showing package metadata, download counts, Python version distribution, and operating system breakdown. ```json { "package": { "name": "nestedutils", "version": "1.1.7", "upload_time": "2026-01-25", "description": "The lightweight Python library for safe, simple, dot-notation access to nested dicts and lists. Effortlessly get, set, and delete values deep in your complex JSON, API responses, and config files without verbose error-checking or handling KeyError exceptions.", "author": "ysskrishna ", "license": "MIT", "home_page": "https://pypi.org/project/nestedutils/", "pypi_url": "https://pypi.org/project/nestedutils/" }, "downloads": { "last_day": 1, "last_week": 112, "last_month": 307, "last_180d": 1142 }, "python_versions": [ { "version": "null", "downloads": 278, "percentage": 92.4 }, { "version": "3.10", "downloads": 8, "percentage": 2.7 }, { "version": "3.11", "downloads": 4, "percentage": 1.3 }, { "version": "3.12", "downloads": 4, "percentage": 1.3 }, { "version": "3.13", "downloads": 4, "percentage": 1.3 } ], "operating_systems": [ { "os": "null", "downloads": 278, "percentage": 92.4 }, { "os": "Linux", "downloads": 19, "percentage": 6.3 }, { "os": "Darwin", "downloads": 4, "percentage": 1.3 } ] } ``` -------------------------------- ### Install library without CLI dependencies Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/README.md Install the core library without CLI dependencies using pip. ```bash pip install pypi-package-stats ``` -------------------------------- ### Show cache statistics Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/CLI.md Command to show cache statistics. ```bash pypi-package-stats cache-info ``` -------------------------------- ### Fetch package statistics command Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/CLI.md Base command to fetch package statistics with options for JSON output, cache bypass, and custom TTL. ```bash pypi-package-stats package [OPTIONS] ``` -------------------------------- ### pypi-package-stats package [OPTIONS] Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/CLI.md Fetches package statistics for a specified PyPI package. Supports human-readable Rich table output by default, or machine-readable JSON output with the --json flag. Includes caching options to control data freshness and cache behavior. ```APIDOC ## [CLI] pypi-package-stats package [OPTIONS] ### Description Fetches package statistics for a specified PyPI package. Supports human-readable Rich table output by default, or machine-readable JSON output with the --json flag. Includes caching options to control data freshness and cache behavior. ### Command pypi-package-stats package [OPTIONS] ### Parameters #### Positional Arguments - **name** (string) - Required - The name of the PyPI package to fetch statistics for #### Options - **--json, -j** (flag) - Optional - Output as machine-readable JSON - **--no-cache** (flag) - Optional - Bypass cache for this request - **--cache-ttl ** (integer) - Optional - Set custom cache TTL (default: 3600) ### Examples ```bash # Human-friendly Rich table output pypi-package-stats package requests # Machine-readable JSON output pypi-package-stats package requests --json # Fresh data (bypass cache) pypi-package-stats package django --no-cache # Custom cache TTL (5 minutes) pypi-package-stats package flask --cache-ttl 300 ``` ### Request Example ```bash pypi-package-stats package nestedutils --json ``` ### Response Example ```json { "package": { "name": "nestedutils", "version": "1.1.7", "upload_time": "2026-01-25", "description": "The lightweight Python library for safe, simple, dot-notation access to nested dicts and lists. Effortlessly get, set, and delete values deep in your complex JSON, API responses, and config files without verbose error-checking or handling KeyError exceptions.", "author": "ysskrishna ", "license": "MIT", "home_page": "https://pypi.org/project/nestedutils/", "pypi_url": "https://pypi.org/project/nestedutils/" }, "downloads": { "last_day": 1, "last_week": 112, "last_month": 307, "last_180d": 1142 }, "python_versions": [ { "version": "null", "downloads": 278, "percentage": 92.4 }, { "version": "3.10", "downloads": 8, "percentage": 2.7 }, { "version": "3.11", "downloads": 4, "percentage": 1.3 }, { "version": "3.12", "downloads": 4, "percentage": 1.3 }, { "version": "3.13", "downloads": 4, "percentage": 1.3 } ], "operating_systems": [ { "os": "null", "downloads": 278, "percentage": 92.4 }, { "os": "Linux", "downloads": 19, "percentage": 6.3 }, { "os": "Darwin", "downloads": 4, "percentage": 1.3 } ] } ``` ``` -------------------------------- ### Clear cached responses Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/CLI.md Command to clear cached responses. ```bash pypi-package-stats cache-clear ``` -------------------------------- ### Get cache info with get_cache_info Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/API.md Returns a dictionary with the number of cached entries and the path of the on-disk cache. Useful for monitoring cache usage. ```python from pypipackagestats import get_cache_info info = get_cache_info() print(info["size"], info["cache_dir"]) ``` -------------------------------- ### Get package statistics with get_package_stats Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/API.md Fetches PyPI package statistics for a given package name. Thread-safe and can be used in concurrent environments. Raises PackageNotFoundError if the package is not found, APIError on network issues, and ValueError for invalid names. ```python from pypipackagestats import get_package_stats stats = get_package_stats("requests") print(f"Downloads: {stats.downloads.last_month:,}") ``` -------------------------------- ### pypi-package-stats --help Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/README.md Shows the help message for the CLI tool, listing all available commands and options. ```APIDOC ## [CLI] pypi-package-stats --help ### Description Shows the help message for the CLI tool, listing all available commands and options. ### Method CLI ### Endpoint pypi-package-stats --help ### Parameters None ### Response #### Success Response No response body specified. ``` -------------------------------- ### Basic library usage Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/README.md Fetch package statistics for a PyPI package and access structured data. The returned PackageStats object provides package_info and downloads attributes, and to_dict() converts it to a dictionary for JSON serialization. ```python from pypipackagestats import get_package_stats # Get package statistics stats = get_package_stats("requests") # Access structured data print(stats.package_info.name) # "requests" print(stats.downloads.last_month) # 123456789 # Convert to dictionary (for JSON serialization) data = stats.to_dict() ``` -------------------------------- ### get_package_stats(name, *, no_cache=False, cache_ttl=None) Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/README.md Fetches all statistics for a PyPI package. Returns a PackageStats object with structured data including package info and download counts. ```APIDOC ## get_package_stats(name, *, no_cache=False, cache_ttl=None) ### Description Fetches all statistics for a PyPI package. Returns a `PackageStats` object. ### Parameters - **name** (str) - Required - The name of the PyPI package. - **no_cache** (bool) - Optional - Disable caching for fresh data. - **cache_ttl** (int) - Optional - Custom cache TTL in seconds. ### Returns - **PackageStats** - Object with `package_info` and `downloads` attributes, and a `to_dict()` method. ### Request Example ```python from pypipackagestats import get_package_stats stats = get_package_stats("requests") ``` ### Response Example ```python print(stats.package_info.name) # "requests" print(stats.downloads.last_month) # 123456789 data = stats.to_dict() ``` ``` -------------------------------- ### pypi-package-stats package Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/README.md Retrieves package metadata and download statistics for a specified PyPI package. Supports optional flags for JSON output, cache bypass, and custom cache TTL. ```APIDOC ## [CLI] pypi-package-stats package ### Description Retrieves package metadata and download statistics for a specified PyPI package. Supports optional flags for JSON output, cache bypass, and custom cache TTL. ### Method CLI ### Endpoint pypi-package-stats package ### Parameters #### Arguments - **name** (string) - Required - The name of the PyPI package to query. #### Options - **--json** (flag) - Optional - Output in machine-friendly JSON format. - **--no-cache** (flag) - Optional - Bypass cache for this request. - **--cache-ttl ** (integer) - Optional - Set a custom cache TTL. ### Response #### Success Response - **package** (object) - Package metadata including name, version, upload_time, description, author, license, home_page, and pypi_url. - **downloads** (object) - Download counts for last_day, last_week, last_month, and last_180d. - **python_versions** (array) - List of Python versions with download counts and percentages. - **operating_systems** (array) - List of operating systems with download counts and percentages. ### Request Example ```bash pypi-package-stats package nestedutils --json ``` #### Response Example ```json { "package": { "name": "nestedutils", "version": "1.1.7", "upload_time": "2026-01-25", "description": "The lightweight Python library for safe, simple, dot-notation access to nested dicts and lists. Effortlessly get, set, and delete values deep in your complex JSON, API responses, and config files without verbose error-checking or handling KeyError exceptions.", "author": "ysskrishna ", "license": "MIT", "home_page": "https://pypi.org/project/nestedutils/", "pypi_url": "https://pypi.org/project/nestedutils/" }, "downloads": { "last_day": 1, "last_week": 112, "last_month": 307, "last_180d": 1142 }, "python_versions": [ { "version": "null", "downloads": 278, "percentage": 92.4 }, { "version": "3.10", "downloads": 8, "percentage": 2.7 }, { "version": "3.11", "downloads": 4, "percentage": 1.3 }, { "version": "3.12", "downloads": 4, "percentage": 1.3 }, { "version": "3.13", "downloads": 4, "percentage": 1.3 } ], "operating_systems": [ { "os": "null", "downloads": 278, "percentage": 92.4 }, { "os": "Linux", "downloads": 19, "percentage": 6.3 }, { "os": "Darwin", "downloads": 4, "percentage": 1.3 } ] } ``` ``` -------------------------------- ### pypi-package-stats cache-info Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/README.md Displays cache statistics, such as the number of cached entries and cache size. Helps monitor cache usage and effectiveness. ```APIDOC ## [CLI] pypi-package-stats cache-info ### Description Displays cache statistics, such as the number of cached entries and cache size. Helps monitor cache usage and effectiveness. ### Method CLI ### Endpoint pypi-package-stats cache-info ### Parameters None ### Response #### Success Response No response body specified. ``` -------------------------------- ### get_cache_info() Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/README.md Returns cache size and directory information. Useful for monitoring cache usage. ```APIDOC ## get_cache_info() ### Description Return cache size and directory information. ### Returns - **dict** - Contains `size` (number of entries) and `cache_dir` (path to cache directory). ### Request Example ```python from pypipackagestats import get_cache_info cache_info = get_cache_info() ``` ### Response Example ```python print(f"Cache size: {cache_info['size']} entries") print(f"Cache directory: {cache_info['cache_dir']}") ``` ``` -------------------------------- ### Advanced options for caching Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/README.md Use advanced options to control caching behavior: disable caching with no_cache=True, set a custom cache TTL with cache_ttl, clear all cached responses with clear_cache(), and retrieve cache statistics with get_cache_info(). ```python from pypipackagestats import get_package_stats, clear_cache, get_cache_info # Disable caching for fresh data stats = get_package_stats("requests", no_cache=True) # Custom cache TTL (5 minutes = 300 seconds) stats = get_package_stats("django", cache_ttl=300) # Clear all cached responses clear_cache() # Get cache statistics cache_info = get_cache_info() print(f"Cache size: {cache_info['size']} entries") print(f"Cache directory: {cache_info['cache_dir']}") ``` -------------------------------- ### Convert PackageStats to dict with to_dict Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/API.md Converts the PackageStats object to a dictionary suitable for JSON serialization. The output includes keys for package, downloads, python_versions, and operating_systems. ```python from pypipackagestats import get_package_stats stats = get_package_stats("requests") data = stats.to_dict() data["package"] # name, version, upload_time (date part only), description, author, license, home_page, pypi_url data["downloads"] # last_day, last_week, last_month, last_180d data["python_versions"] # list of {"version", "downloads", "percentage"} data["operating_systems"] # list of {"os", "downloads", "percentage"} ``` -------------------------------- ### get_cache_info() -> Dict[str, Any] Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/API.md Returns cache information including the number of cached entries and the path of the on-disk cache. ```APIDOC ## get_cache_info() -> Dict[str, Any] ### Description Get cache information. Returns a dict with `size` (number of cached entries) and `cache_dir` (path of the on-disk cache). ### Request Example ```python from pypipackagestats import get_cache_info info = get_cache_info() print(info["size"], info["cache_dir"]) ``` ``` -------------------------------- ### clear_cache() -> None Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/API.md Clears all cached data. ```APIDOC ## clear_cache() -> None ### Description Clear all cached data. ``` -------------------------------- ### PackageStats.to_dict(self) -> Dict[str, Any] Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/API.md Converts the PackageStats object to a dictionary suitable for JSON serialization. ```APIDOC ## PackageStats.to_dict(self) -> Dict[str, Any] ### Description Convert to dict for JSON. ### Request Example ```python from pypipackagestats import get_package_stats stats = get_package_stats("requests") data = stats.to_dict() data["package"] # name, version, upload_time (date part only), description, author, license, home_page, pypi_url data["downloads"] # last_day, last_week, last_month, last_180d data["python_versions"] # list of {"version", "downloads", "percentage"} data["operating_systems"] # list of {"os", "downloads", "percentage"} ``` ``` -------------------------------- ### get_package_stats(package_name: str, *, no_cache: bool = False, cache_ttl: Optional[int] = None) -> PackageStats Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/API.md Retrieves PyPI package statistics for a given package name. This function is thread-safe and supports optional caching control. ```APIDOC ## get_package_stats(package_name: str, *, no_cache: bool = False, cache_ttl: Optional[int] = None) -> PackageStats ### Description Get PyPI package statistics (thread-safe). ### Parameters - `package_name` (str) - Required - Package name - `no_cache` (bool) - Optional - Whether to disable caching (default: False). If True, sets cache_ttl=0 to disable caching. - `cache_ttl` (Optional[int]) - Optional - Time-to-live for cache entries in seconds. Positive integer → cache with that TTL (seconds); 0 → disable caching completely; None or omitted → use default (3600 seconds). ### Returns - `PackageStats` - Package statistics ### Raises - `PackageNotFoundError` - If package not found - `APIError` - If API/network error - `ValueError` - If invalid package name ### Request Example ```python from pypipackagestats import get_package_stats stats = get_package_stats("requests") print(f"Downloads: {stats.downloads.last_month:,}") ``` ### Notes Thread Safety: This function is fully thread-safe and can be used safely in concurrent environments like ThreadPoolExecutor. ``` -------------------------------- ### clear_cache() Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/README.md Clears all cached API responses. Useful when you need to force fresh data retrieval. ```APIDOC ## clear_cache() ### Description Clear all cached API responses. ### Request Example ```python from pypipackagestats import clear_cache clear_cache() ``` ``` -------------------------------- ### pypi-package-stats cache-clear Source: https://github.com/ysskrishna/pypi-package-stats/blob/main/README.md Removes all cached responses from the local cache. Useful for forcing fresh data retrieval on subsequent requests. ```APIDOC ## [CLI] pypi-package-stats cache-clear ### Description Removes all cached responses from the local cache. Useful for forcing fresh data retrieval on subsequent requests. ### Method CLI ### Endpoint pypi-package-stats cache-clear ### Parameters None ### Response #### Success Response No response body specified. ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.