{"id":5244,"library":"gviz-api","title":"Python API for Google Visualization","description":"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.","status":"active","version":"1.10.0","language":"en","source_language":"en","source_url":"https://github.com/google/google-visualization-python","tags":["google-visualization","data-table","json","charting","web-api","data-source"],"install":[{"cmd":"pip install gviz-api","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"The primary class for creating data tables.","symbol":"DataTable","correct":"from gviz_api import DataTable"},{"note":"Import the module directly to access its functions and classes.","symbol":"gviz_api","correct":"import gviz_api"}],"quickstart":{"code":"import gviz_api\nimport datetime\n\n# Define the schema of the table.\n# The structure is: [(id, type, optional_label), ...]\ndescription = [\n    (\"name\", \"string\", \"Meal\"),\n    (\"diet\", \"string\", \"Diet Type\"),\n    (\"calories\", \"number\", \"Calories\"),\n    (\"healthy\", \"boolean\", \"Healthy?\"),\n    (\"serving_date\", \"date\", \"Serving Date\")\n]\n\n# Load the data. Data rows must match the schema order.\ndata = [\n    (\"Breakfast\", \"vegan\", 250, True, datetime.date(2024, 4, 13)),\n    (\"Lunch\", \"vegetarian\", 400, True, datetime.date(2024, 4, 13)),\n    (\"Dinner\", \"carnivore\", 700, False, datetime.date(2024, 4, 12)),\n    (\"Snack\", \"omnivore\", 150, True, datetime.date(2024, 4, 13)),\n]\n\n# Create a DataTable object.\ndata_table = gviz_api.DataTable(description)\ndata_table.AppendData(data)\n\n# Output as JSON string (for embedding in a webpage)\njson_string = data_table.ToJSon(columns_order=(\"name\", \"diet\", \"calories\", \"healthy\", \"serving_date\"), order_by=\"calories\")\nprint(\"JSON String:\\n\", json_string)\n\n# Output as JSON response string (for a data source URL)\n# req_id is often 0 for simple requests.\njson_response = data_table.ToJSonResponse(columns_order=(\"name\", \"calories\"), order_by=\"calories\", req_id=0)\nprint(\"\\nJSON Response (for data source):\\n\", json_response)\n\n# Output as JavaScript string (for direct script injection, often for debugging)\njavascript_string = data_table.ToJS(table_id=\"myDataTable\", columns_order=(\"name\", \"calories\"), order_by=\"calories\")\nprint(\"\\nJavaScript String (for embedding):\\n\", javascript_string)\n","lang":"python","description":"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."},"warnings":[{"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.","message":"The 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.","severity":"gotcha","affected_versions":"1.10.0 and earlier"},{"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.","message":"The 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`.","severity":"gotcha","affected_versions":"All versions"},{"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`.","message":"Once 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"This 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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-13T00:00:00.000Z","next_check":"2026-07-12T00:00:00.000Z"}