Pygaljs

1.0.2 · maintenance · verified Thu Apr 16

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.

Common errors

Warnings

Install

Imports

Quickstart

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.

import os
import pygaljs

# The pygaljs package primarily provides static assets.
# Its main utility in Python code is often to determine the path
# to these assets for serving them in a web framework.

# Get the base directory of the installed pygaljs package
package_root = os.path.dirname(pygaljs.__file__)
print(f"Pygaljs package root: {package_root}")

# Example of how you might construct a path to a specific asset (e.g., JavaScript file)
# Note: The exact subdirectory structure depends on the pygal.js assets it bundles.
# A common pattern for such packages is to have a 'static' or 'dist' directory.

# This path might vary; typically, you'd look for a 'static' or 'dist' folder.
# For pygaljs, the assets are often directly under 'pygaljs/pygaljs/'.
# Checking the GitHub repository (https://github.com/ionelmc/python-pygaljs)
# shows assets like 'pygal-2.0.x.min.js' directly under 'pygaljs/pygaljs'.

pygaljs_assets_dir = os.path.join(package_root, 'pygaljs')
print(f"Pygaljs assets directory (potential): {pygaljs_assets_dir}")

# Verify if the directory exists and list some contents (for demonstration)
if os.path.exists(pygaljs_assets_dir):
    print("Contents of pygaljs assets directory (first 5 files):")
    for i, item in enumerate(os.listdir(pygaljs_assets_dir)):
        if i >= 5: break
        print(f"  - {item}")
else:
    print(f"Warning: {pygaljs_assets_dir} does not exist. Asset location might differ.")

# In a web framework (e.g., Flask, Django), you would configure
# a static file handler to serve files from `pygaljs_assets_dir`.
# For example, in Flask:
# app.static_folder = os.path.join(os.path.dirname(pygaljs.__file__), 'pygaljs')

view raw JSON →