{"id":7558,"library":"pygaljs","title":"Pygaljs","description":"Pygaljs is a Python package designed to provide static assets (JavaScript, CSS, fonts, etc.) for the pygal.js JavaScript charting library. It acts as a wrapper, making these web assets easily discoverable and servable within Python-based web applications. The current version is 1.0.2, and its release cadence is infrequent, with the last release in April 2020, indicating a stable but not actively developed state.","status":"maintenance","version":"1.0.2","language":"en","source_language":"en","source_url":"https://github.com/ionelmc/python-pygaljs","tags":["web assets","javascript","charting","static files","pygal.js"],"install":[{"cmd":"pip install pygaljs","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"note":"The primary import is for the top-level package. Individual charting components are not imported from here as pygaljs provides static assets for a JavaScript library, not a Python charting API.","symbol":"pygaljs","correct":"import pygaljs"}],"quickstart":{"code":"import os\nimport pygaljs\n\n# The pygaljs package primarily provides static assets.\n# Its main utility in Python code is often to determine the path\n# to these assets for serving them in a web framework.\n\n# Get the base directory of the installed pygaljs package\npackage_root = os.path.dirname(pygaljs.__file__)\nprint(f\"Pygaljs package root: {package_root}\")\n\n# Example of how you might construct a path to a specific asset (e.g., JavaScript file)\n# Note: The exact subdirectory structure depends on the pygal.js assets it bundles.\n# A common pattern for such packages is to have a 'static' or 'dist' directory.\n\n# This path might vary; typically, you'd look for a 'static' or 'dist' folder.\n# For pygaljs, the assets are often directly under 'pygaljs/pygaljs/'.\n# Checking the GitHub repository (https://github.com/ionelmc/python-pygaljs)\n# shows assets like 'pygal-2.0.x.min.js' directly under 'pygaljs/pygaljs'.\n\npygaljs_assets_dir = os.path.join(package_root, 'pygaljs')\nprint(f\"Pygaljs assets directory (potential): {pygaljs_assets_dir}\")\n\n# Verify if the directory exists and list some contents (for demonstration)\nif os.path.exists(pygaljs_assets_dir):\n    print(\"Contents of pygaljs assets directory (first 5 files):\")\n    for i, item in enumerate(os.listdir(pygaljs_assets_dir)):\n        if i >= 5: break\n        print(f\"  - {item}\")\nelse:\n    print(f\"Warning: {pygaljs_assets_dir} does not exist. Asset location might differ.\")\n\n# In a web framework (e.g., Flask, Django), you would configure\n# a static file handler to serve files from `pygaljs_assets_dir`.\n# For example, in Flask:\n# app.static_folder = os.path.join(os.path.dirname(pygaljs.__file__), 'pygaljs')","lang":"python","description":"The `pygaljs` library is primarily an asset provider for the `pygal.js` JavaScript charting library. The most common 'use case' in Python code is to programmatically locate the installation path of these static assets so that a web framework can serve them. This example demonstrates how to find the root directory of the installed package and a likely location for its JavaScript and CSS files."},"warnings":[{"fix":"If you intend to generate charts directly in Python, consider libraries like `pygal` (the Python charting library) or `matplotlib`, `plotly`, etc. `pygaljs` is for providing the frontend assets if you're using `pygal.js` in a web context.","message":"Pygaljs provides assets for a JavaScript library (`pygal.js`), it is not a Python charting library itself. You cannot create charts directly by calling functions from `pygaljs` in Python.","severity":"gotcha","affected_versions":"1.0.x"},{"fix":"Inspect the installed `pygaljs` package directory (e.g., `os.path.dirname(pygaljs.__file__)`) to confirm the asset layout. Common subdirectories are 'static' or a direct package subfolder with the library name, like 'pygaljs/pygaljs/'.","message":"The exact subdirectory structure where `pygal.js` assets (JavaScript, CSS) are stored within the `pygaljs` package might not be immediately obvious or explicitly documented. This can lead to issues when configuring static file serving in web frameworks.","severity":"gotcha","affected_versions":"1.0.x"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Run `pip install pygaljs` in your terminal to install the package.","cause":"The `pygaljs` package is not installed in the active Python environment.","error":"ModuleNotFoundError: No module named 'pygaljs'"},{"fix":"Use the `pygal` Python library (note: `pygal` not `pygaljs`) for generating SVG charts from Python, or use `pygal.js` (the JavaScript library) on the frontend if you are serving its assets via `pygaljs`.","cause":"`pygaljs` is an asset package for a JavaScript library, not a Python charting API. It does not expose charting classes or functions directly.","error":"Attempting to create a chart like: pygaljs.Line().add('series', [1, 2, 3]) results in AttributeError: module 'pygaljs' has no attribute 'Line'"}]}