Registry / gcp / gviz-api

gviz-api

JSON →
library1.10.0pypypi✓ verified 26d ago

gviz-api is a helper Python library for developers implementing data sources for visualizations built on the Google Visualization API. It allows for creating `DataTable` objects in Python and serializing them into JSON string, JSON response, or JavaScript string formats consumable by client-side Google Charts. The current version is 1.10.0, released in October 2021, and the project appears to be stable but not frequently updated.

pip install gviz-api
INSTALL
IMPORT
SIG · GVIZ-API
G
gviz-api
gcppythonv1.10.0
Install
1.6s avg
Import
47ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.10.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.046s · 17.9MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.048s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

DataTable
✓ from gviz_api import DataTable
The primary class for creating data tables.
gviz_api
✓ import gviz_api
Import the module directly to access its functions and classes.

This quickstart demonstrates how to define a table schema, populate it with data, and output the `DataTable` in different formats (JSON, JSON Response, JavaScript string) suitable for consumption by Google Charts.

import gviz_api import datetime # Define the schema of the table. # The structure is: [(id, type, optional_label), ...] description = [ ("name", "string", "Meal"), ("diet", "string", "Diet Type"), ("calories", "number", "Calories"), ("healthy", "boolean", "Healthy?"), ("serving_date", "date", "Serving Date") ] # Load the data. Data rows must match the schema order. data = [ ("Breakfast", "vegan", 250, True, datetime.date(2024, 4, 13)), ("Lunch", "vegetarian", 400, True, datetime.date(2024, 4, 13)), ("Dinner", "carnivore", 700, False, datetime.date(2024, 4, 12)), ("Snack", "omnivore", 150, True, datetime.date(2024, 4, 13)), ] # Create a DataTable object. data_table = gviz_api.DataTable(description) data_table.AppendData(data) # Output as JSON string (for embedding in a webpage) json_string = data_table.ToJSon(columns_order=("name", "diet", "calories", "healthy", "serving_date"), order_by="calories") print("JSON String:\n", json_string) # Output as JSON response string (for a data source URL) # req_id is often 0 for simple requests. json_response = data_table.ToJSonResponse(columns_order=("name", "calories"), order_by="calories", req_id=0) print("\nJSON Response (for data source):\n", json_response) # Output as JavaScript string (for direct script injection, often for debugging) javascript_string = data_table.ToJS(table_id="myDataTable", columns_order=("name", "calories"), order_by="calories") print("\nJavaScript String (for embedding):\n", javascript_string)
Debug
Known issues
gotchaThe gviz-api library is stable but has not seen significant updates since its last release in October 2021. It originated as an 'automatically exported' project, indicating limited ongoing development on GitHub.
fix
While functional for its intended purpose, users should be aware that active feature development or frequent bug fixes may not be available. Consider community forks or alternative solutions for new requirements.
affects: 1.10.0 and earlier
gotchaThe library enforces strict type checking based on the schema definition. It does not perform automatic type coercion. Providing data that does not precisely match the declared type (e.g., a string '123' for a numeric column) will raise a `TypeError`.
fix
Ensure all data elements conform exactly to their declared Python types before appending to the `DataTable`. For example, use `int(value)` or `float(value)` explicitly for numeric conversions.
affects: All versions
gotchaOnce a `DataTable` object is created with a schema, the column definitions (schema) cannot be modified. Additionally, individual rows cannot be removed, though new rows can be appended, or the entire data can be overwritten.
fix
Plan your table schema carefully before initialization. If dynamic column modification or individual row deletion is needed, preprocess your data into the final desired structure before creating the `DataTable`.
affects: All versions
gotchaThis Python library is purely for generating data in a format compatible with the Google Visualization API. It does not provide any functionality for rendering charts or visualizations itself. Rendering must be handled by client-side JavaScript in a web browser.
fix
You must include the Google Charts JavaScript library in your web page and write JavaScript code to fetch the data generated by `gviz-api` and draw the desired visualization.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'gviz_api'
The 'gviz-api' library is not installed in your Python environment or the import statement is incorrect.
fix
Install the library using pip: `pip install gviz-api`. Ensure your import statement is `import gviz_api`.
TypeError: Value ... of type ... is not valid for column ... of type ...
The `gviz-api` library enforces strict type checking; data provided for a column does not precisely match its declared Python type (e.g., a string for a numeric column).
fix
Ensure all data elements conform exactly to their declared Python types before appending to the `DataTable`. Explicitly convert values using functions like `int()`, `float()`, `str()`, or `datetime.date()` as needed.
DataTableException: Error in a column description or in the description structure.
The schema (column description) provided to `gviz_api.DataTable` is malformed, or the data being added does not conform to the defined schema.
fix
Review the `table_description` dictionary passed to the `gviz_api.DataTable` constructor, ensuring column definitions are correct and that subsequent `AppendData()` calls provide rows matching this schema.
AttributeError: 'NoneType' object has no attribute '...'
A method or attribute was accessed on a `gviz_api.DataTable` object (or a component derived from it) that was `None`, indicating it was not properly initialized or did not successfully process data.
fix
Check that the `gviz_api.DataTable` object and any intermediate results are correctly instantiated and populated with valid data before attempting to call methods or access attributes on them.
Upgrade
Version history
1.10.0latest on PyPI · released Oct 14, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
36 hits · last 30 days
node
32
OpenAI (training)
1
Resources
gviz-api — pip install gviz-api · libregistry