### Quick Start for Kepler.gl Integration Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/visualization/maps.rst This example demonstrates the initial setup for integrating with Kepler.gl, providing a foundation for rich interactive map visualizations with multiple layers and styling. ```python import graphistry from graphistry import KeplerLayer import pandas as pd cities = pd.DataFrame({ "id": ["NYC", "LA", "London"], "latitude": [40.7128, 34.0522, 51.5074], "longitude": [-74.0060, -118.2437, -0.1278] }) ``` -------------------------------- ### Install PyGraphistry Source: https://github.com/graphistry/pygraphistry/blob/master/demos/gfql/GPU_memory_consumption_tutorial.ipynb Installs the PyGraphistry library. Use this for general setup. ```python ! pip install -q graphistry ``` -------------------------------- ### Generate Examples Source: https://github.com/graphistry/pygraphistry/blob/master/ai/prompts/GFQL_LLM_GUIDE_MAINTENANCE.md Execute the example generation script. Ensure you are in the correct directory. ```bash python3 plans/.../generate_examples.py ``` -------------------------------- ### Install pygraphistry Source: https://github.com/graphistry/pygraphistry/blob/master/demos/upload_csv_miniapp.ipynb Installs the pygraphistry library. Use the '-q' flag for quiet installation. ```python #!pip install graphistry -q ``` -------------------------------- ### Install Graphistry and Pandas Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/neo4j/official/graphistry_bolt_tutorial_public.html Install the graphistry library with bolt support and the pandas library. Use this for initial setup on a new notebook server. ```python #!pip install --user pandas #!pip install --user graphistry[bolt] ``` -------------------------------- ### Install PyGraphistry with igraph Source: https://github.com/graphistry/pygraphistry/blob/master/demos/more_examples/simple/MarvelTutorial.ipynb Installs the pygraphistry library with igraph support. Use this command in your environment before running the example. ```python # ! pip install -q graphistry[igraph] ``` -------------------------------- ### Install umap-learn and graphistry Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/umap_learn/umap_learn.ipynb Install the necessary libraries for UMAP and Graphistry. If not running a local Graphistry server, a free Hub account can be used. ```python # Already installed in Graphistry & RAPIDS distros # ! pip install --user umap-learn # ! pip install --user graphistry ``` -------------------------------- ### Install Dependencies Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/alienvault/OTXIndicators.ipynb Install the necessary libraries for Graphistry and OTX integration. ```python #!pip install graphistry -q #!pip install OTXv2 -q ``` -------------------------------- ### Install python-arango Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/arango/arango_tutorial.ipynb Installs the python-arango library. Use this command in your environment to get started. ```bash !pip install python-arango --user -q ``` -------------------------------- ### Setup and Display Pipeline Overview Source: https://github.com/graphistry/pygraphistry/blob/master/demos/gfql/benchmark_filter_pagerank_cpu_gpu.ipynb Imports necessary libraries and displays a DataFrame summarizing the graph pipeline stages and their significance. This setup is required before visualizing benchmark results. ```python from pathlib import Path import sys import pandas as pd from IPython.display import display REPO_ROOT = Path.cwd() if str(REPO_ROOT) not in sys.path: sys.path.insert(0, str(REPO_ROOT)) from benchmarks.gfql.filter_pagerank import presentation as pres pres.setup_matplotlib() display(pres.pipeline_overview_df()) ``` -------------------------------- ### Install Graphistry with NetworkX extras Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/install/extended.rst Install PyGraphistry with NetworkX integration support. ```bash pip install graphistry[networkx] ``` -------------------------------- ### Install and Import PyGraphistry Source: https://github.com/graphistry/pygraphistry/blob/master/demos/more_examples/graphistry_features/encodings-colors.ipynb Install the PyGraphistry library and import it. Optionally, register your Graphistry account details for server connection. ```python # ! pip install --user graphistry import graphistry # To specify Graphistry account & server, use: # graphistry.register(api=3, username='...', password='...', protocol='https', server='hub.graphistry.com') # For more options: https://pygraphistry.readthedocs.io/en/latest/server/register.html graphistry.__version__ ``` -------------------------------- ### Install Graphistry Library Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/tigergraph/social_raw_REST_calls.ipynb Installs the graphistry Python library. Ensure this is run before importing. ```python #!pip install graphistry ``` -------------------------------- ### Flask Example for API Integration Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/gfql/validation/production.rst Basic Flask application setup demonstrating how to integrate GFQL operations within a web API. This snippet shows the necessary imports for Flask, `Chain`, and `GFQLValidationError`. ```python from flask import Flask, request, jsonify from graphistry.compute.chain import Chain from graphistry.compute.exceptions import GFQLValidationError ``` -------------------------------- ### Create New Domain Example Source: https://github.com/graphistry/pygraphistry/blob/master/ai/prompts/GFQL_LLM_GUIDE_MAINTENANCE.md Generate a Python code example for a new domain, including search, filter, and optional algorithm/visualization. ```markdown ### [Domain] **Use case**: [Description] **Dense**: `[Python]` **JSON**: ```json {[AST]} ``` ``` -------------------------------- ### Install pygraphistry Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/neptune/neptune_cypher_viz_using_bolt.ipynb Install the pygraphistry library using pip. Ensure to restart the kernel after installation. ```python !pip install --user graphistry ``` -------------------------------- ### Update Workflow - Create Example Source: https://github.com/graphistry/pygraphistry/blob/master/ai/prompts/GFQL_LLM_GUIDE_MAINTENANCE.md Generate code examples by converting Python code to JSON format using `.to_json()`. ```plaintext Create example: Python → `.to_json()` (5-10 min) ``` -------------------------------- ### Install Splunk SDK Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/splunk/splunk_demo_public.html Installs the necessary Splunk SDK for Python. This is a prerequisite for connecting to Splunk. ```bash !pip install splunk-sdk ``` -------------------------------- ### Install Required Python Packages Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_by_use_case/logs/network-threat-hunting-masterclass-zeek-bro/graphistry_corelight_webinar.ipynb Installs the graphistry and splunk-sdk libraries using pip. The '-q' flag ensures a quiet installation. ```bash !pip install graphistry -q !pip install splunk-sdk -q ``` -------------------------------- ### Install pygraphistry Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/alienvault/usm.ipynb Installs the necessary pygraphistry library. This should be run before importing other modules. ```python !pip install requests_oauthlib -q ``` -------------------------------- ### Install pygraphistry Source: https://github.com/graphistry/pygraphistry/blob/master/demos/ai/cyber/CyberSecurity-Slim.ipynb Install the pygraphistry library with AI capabilities. This is a prerequisite for running the subsequent code. ```python #! pip install --upgrade graphistry[ai] ``` -------------------------------- ### Install HyperNetX and Graphistry Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/hypernetx/hypernetx.ipynb Install the necessary libraries for HyperNetX and Graphistry. These are often preinstalled in Graphistry Core distributions. ```python # ! pip install hypernetx -q # ! pip install graphistry -q ``` -------------------------------- ### Install PyGraphistry with Kusto Support Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/microsoft/kusto/graphistry_ADX_kusto_demo.ipynb Install the pygraphistry library. Use the `[kusto]` extra to include the Kusto Python client. ```bash pip install graphistry pip install graphistry[kusto] ``` -------------------------------- ### Clone and Install PyGraphistry Source: https://github.com/graphistry/pygraphistry/blob/master/DEVELOP.md Clone the repository, checkout a specific branch, and install the library in user mode. ```bash git clone https://github.com/graphistry/pygraphistry.git git checkout origin/my_branch pip install --user -e . git diff ``` -------------------------------- ### Install Graphistry with igraph extras Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/install/extended.rst Install PyGraphistry with support for igraph graphs. ```bash pip install graphistry[igraph] ``` -------------------------------- ### Install Graphviz and PyGraphistry Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/graphviz/graphviz.ipynb Installs the graphviz engine and pygraphviz Python bindings using apt-get and pip. Ensure both native packages and Python bindings are installed. ```bash #!apt-get install graphviz graphviz-dev ``` ```bash #!pip install -q graphistry[pygraphviz] ``` -------------------------------- ### Install and Import Graphistry Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/gpu_rapids/part_i_cpu_pandas.ipynb Installs the graphistry library and imports pandas. Use graphistry.register() to specify account and server details. ```python #!pip install graphistry -q import pandas as pd import graphistry graphistry.__version__ # To specify Graphistry account & server, use: # graphistry.register(api=3, username='...', password='...', protocol='https', server='hub.graphistry.com') # For more options: https://pygraphistry.readthedocs.io/en/latest/server/register.html ``` -------------------------------- ### Install Graphistry with pygraphviz extras Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/install/extended.rst Install PyGraphistry with pygraphviz for rendering graphs using Graphviz layouts. ```bash pip install graphistry[pygraphviz] ``` -------------------------------- ### Install all optional dependencies for Graphistry Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/install/extended.rst Install all optional dependencies for PyGraphistry. This is generally not recommended due to potential size and conflicts. ```bash pip install graphistry[all] ``` -------------------------------- ### Example Mermaid Output Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/visualization/10min.rst A basic example of Mermaid syntax for graph visualization. ```text graph LR a --> b b --> c a --> tx1 ``` -------------------------------- ### Install Graphistry with NodeXL extras Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/install/extended.rst Install PyGraphistry with openpyxl and xlrd for reading NodeXL files. ```bash pip install graphistry[nodexl] ``` -------------------------------- ### Install and Register PyGraphistry Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/databricks_pyspark/graphistry-notebook-dashboard.html Install PyGraphistry and register your API credentials. If the library is not available, install it first. For private servers, ensure the protocol is set correctly. Consider switching to 'render=False' if browser embedding prevents plots. ```python import graphistry # if not yet available, install and/or restart Python kernel using the above graphistry.register( api=2, username='MY_USERNAME', password='MY_PASSWORD', server='hub.graphistry.com', # or your private server protocol='https' # if http-only, browsers may prevent embedding plots: switch to "render=False" ) graphistry.__version__ ``` -------------------------------- ### Install Minimal PyGraphistry Source: https://github.com/graphistry/pygraphistry/blob/master/README.md Installs the core PyGraphistry library with essential components like GFQL, built-in layouts, and the visualization server client. Does not include AI features or plugins. ```bash pip install graphistry ``` -------------------------------- ### Install Git LFS on Ubuntu Source: https://github.com/graphistry/pygraphistry/blob/master/DEVELOP.md Installs Git LFS on Ubuntu systems using a script from packagecloud.io. ```bash curl -s https://packagecloud.io/install/repositories/github/git-lfs/script.deb.sh | sudo bash sudo apt-get install git-lfs ``` -------------------------------- ### Install pygraphistry and dependencies Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/neo4j/official/graphistry_bolt_tutorial_public.ipynb Install the necessary libraries for pygraphistry and Neo4j integration. Uncomment and run these lines on first use, then restart the Python kernel. ```python #!pip install --user pandas #!pip install --user graphistry[bolt] ### ADVANCED: ### If you already have the neo4j python driver, you can leave out '[bolt]': ### !pip install --user graphistry ### If you already have graphistry but not neo4j, you can reuse your existing graphistry: ### !pip install --user neo4j ``` -------------------------------- ### Build and Start Docker Compose Environment Source: https://github.com/graphistry/pygraphistry/blob/master/DEVELOP.md Builds all Docker images defined in the compose file and starts the services in detached mode. ```bash cd docker && docker compose build && docker compose up -d ``` -------------------------------- ### Install Graphistry with multiple extras Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/install/extended.rst Install PyGraphistry with multiple optional dependencies, such as NetworkX and UMAP-learn, by separating them with commas. ```bash pip install graphistry[networkx,umap-learn] ``` -------------------------------- ### Install and Register PyGraphistry Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/gpu_rapids/part_iv_gpu_cuml.ipynb Installs the PyGraphistry library and registers the Graphistry API. Ensure you replace placeholder credentials with your actual API key and server details. ```python import pandas as pd, networkx as nx # !git clone https://github.com/graphistry/pygraphistry.git from time import time !pip install -U pygraphistry/ --quiet import graphistry graphistry.register(api=3,protocol="https", server="hub.graphistry.com", username='***', password='***') graphistry.__version__ ``` -------------------------------- ### Install Graphistry and Pandas Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/nodexl/official/nodexl_graphistry.ipynb Install the necessary libraries for NodeXL to Graphistry conversion. A restart of the Python runtime may be required. ```python # ! pip install -q --user graphistry pandas ``` -------------------------------- ### Full Example Template Source: https://github.com/graphistry/pygraphistry/blob/master/ai/prompts/GFQL_LLM_GUIDE_MAINTENANCE.md Markdown template for a full code example, including a name, use case, dense code, JSON, and explanation. ```markdown **[Name] ([Use Case]):** ```python # Dense: [code] ``` ```json {[JSON]} ``` **Pattern**: [Explanation] ``` -------------------------------- ### Install pygraphistry with UMAP support Source: https://github.com/graphistry/pygraphistry/blob/master/demos/more_examples/simple/table_to_graph_three_ways.ipynb Install the pygraphistry library with optional UMAP support for advanced graph analysis. Use this command in your environment to get started. ```python ! pip install -q graphistry[umap_learn] ``` -------------------------------- ### Full Round-Trip Temporal Query Example Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/gfql/wire_protocol_examples.md Shows a complete example of creating a query with temporal predicates, serializing it to JSON, simulating wire transfer, and reconstructing the query. ```python # 1. Create a complex query with temporal predicates from graphistry import n, Chain from graphistry.compute import gt, between, is_in from datetime import datetime, date, time import pandas as pd query = Chain([ n(filter_dict={ "created": gt(pd.Timestamp("2023-01-01")), "event_date": between(date(2023, 6, 1), date(2023, 6, 30)), "event_time": is_in([time(9, 0), time(12, 0), time(17, 0)]) }) ]) # 2. Serialize to JSON json_query = query.to_json() print(json_query) # 3. Send over wire (simulated) import json wire_data = json.dumps(json_query) received_data = json.loads(wire_data) # 4. Deserialize on receiving end from graphistry import Chain reconstructed_query = Chain.from_json(received_data) # 5. Apply to graph data result = g.gfql(reconstructed_query.chain) ``` -------------------------------- ### Install pygraphistry and igraph Source: https://github.com/graphistry/pygraphistry/blob/master/demos/more_examples/graphistry_features/layout_modularity_weighted.ipynb Install the necessary libraries for graph analysis and visualization. This is a prerequisite for using pygraphistry. ```python # ! pip install -q graphistry igraph ``` -------------------------------- ### Example Command and Output Source: https://github.com/graphistry/pygraphistry/blob/master/agents/skills/plan/SKILL.md Illustrates the format for executing a command and capturing its output within a step description. ```shell $ [exact command] [output] ``` -------------------------------- ### Multi-tenant Example with Isolated Sessions Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/server/concurrency.rst Demonstrates how different users can work with their own isolated sessions by creating separate client instances with distinct credentials and settings. ```python import graphistry # Alice's client with her credentials and settings alice_g = graphistry.client() alice_g.register(api=3, username='alice', password='alice_pw') alice_g.privacy(mode='public') # Bob's client with his credentials and settings bob_g = graphistry.client() bob_g.register(api=3, username='bob', password='bob_pw') bob_g.privacy(mode='org') # Each client creates isolated plottables alice_plot = alice_g.edges(alice_data).plot(render=False) bob_plot = bob_g.edges(bob_data).plot(render=False) ``` -------------------------------- ### Install and Initialize Git LFS Source: https://github.com/graphistry/pygraphistry/blob/master/DEVELOP.md Installs Git Large File Storage (LFS) and checks out LFS files. This is a prerequisite for handling large data files. ```bash git lfs install git lfs checkout ``` -------------------------------- ### Install and Import PyGraphistry Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/splunk/splunk_demo_public.ipynb Install the pygraphistry library using pip and import it into your Python environment. Optionally, register your Graphistry account details for server configuration. ```python !pip install graphistry import graphistry graphistry.__version__ ``` ```python # To specify Graphistry account & server, use: # graphistry.register(api=3, username='...', password='...', protocol='https', server='hub.graphistry.com') # For more options: https://pygraphistry.readthedocs.io/en/latest/server/register.html ``` -------------------------------- ### Install Graphistry with AI extras Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/install/extended.rst Install PyGraphistry with AI extras for advanced AI methods. Ensure you have sufficient disk space (1GB+). ```bash pip install graphistry[ai] ``` -------------------------------- ### Check pygraphviz Availability Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/graphviz/plot_static_demo.ipynb Checks if pygraphviz is installed and prints its version. If not installed, it indicates that only code examples will be shown. ```python import pandas as pd import graphistry # Check if pygraphviz is available try: import pygraphviz HAS_PYGRAPHVIZ = True print(f'pygraphviz version: {pygraphviz.__version__}') except ImportError: HAS_PYGRAPHVIZ = False print('pygraphviz not installed - showing code examples only') ``` -------------------------------- ### Install and Register Graphistry Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/splunk/splunk_demo_public.html Install the Graphistry library using pip and register your API credentials. Ensure you have the necessary environment variables set for GRAPHISTRY. ```python !pip install graphistry import graphistry graphistry.register(**GRAPHISTRY) graphistry.__version__ ``` -------------------------------- ### Install Graphistry and AWS CLI Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_by_use_case/logs/aws_vpc_flow_cloudwatch/vpc_flow.ipynb Installs the necessary Python libraries for Graphistry and the AWS Command Line Interface. Use this to set up your environment. ```python !pip install graphistry -q !pip install awscli -q ``` -------------------------------- ### Dynamic Import Example - Before Hoisting Source: https://github.com/graphistry/pygraphistry/blob/master/ai/prompts/HOISTIMPORTS.md Illustrates a scenario where 'json' and 'uuid' are dynamically imported within a function. This example shows the 'before' state prior to applying the hoisting strategy. ```python # graphistry/compute/chain_remote.py from typing import Any, Dict import pandas as pd from graphistry.Plottable import Plottable def chain_remote_generic(self, ...): # ... 150 lines ... if 'metadata.json' in zip_ref.namelist(): try: import json # <-- DYNAMIC IMPORT import uuid # <-- DYNAMIC IMPORT metadata = json.loads(metadata_content) viztoken = str(uuid.uuid4()) ``` -------------------------------- ### Minimal GFQL RETURN Example Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/gfql/return.rst Demonstrates a minimal GFQL pipeline using rows, where_rows, return_, order_by, and limit to find top people. ```python from graphistry import n, e_forward, gt from graphistry.compute import rows, where_rows, return_, order_by, limit top_people = g.gfql([ n({"type": "Person"}), e_forward({"type": "FOLLOWS"}), n({"type": "Person", "score": gt(0)}, name="p"), rows(table="nodes", source="p"), where_rows(expr="score >= 50"), return_(["id", "name", "score"]), order_by([("score", "desc"), ("name", "asc")]), limit(10), ]) ``` -------------------------------- ### Basic SVG Rendering Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/graphviz/plot_static_demo.ipynb Renders and auto-displays the graph as an SVG. This example requires pygraphviz to be installed. ```python if HAS_PYGRAPHVIZ: # Auto-displays inline, returns SVG bytes g.plot_static() else: print('# Example code (requires pygraphviz):') print('g.plot_static()') ``` -------------------------------- ### PyGraphistry Pipeline Example Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/gfql/spec/wire_protocol.md An example of a multi-stage graph pipeline using PyGraphistry's query language, demonstrating graph definition, function calls, and result ordering. ```text GRAPH g1 = GRAPH { MATCH (a)-[r]->(b) WHERE a.score > 10 } GRAPH g2 = GRAPH { USE g1 CALL graphistry.degree.write() } USE g2 MATCH (n) RETURN n.id, n.degree ORDER BY n.degree DESC ``` -------------------------------- ### Graphistry Procedure Call - Degree Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/gfql/cypher.rst Example of calling the graphistry.degree procedure to get node degrees. ```cypher CALL graphistry.degree() ``` -------------------------------- ### Example Dynamic Import Context Source: https://github.com/graphistry/pygraphistry/blob/master/ai/prompts/HOISTIMPORTS.md Illustrates the expected output format for documenting a dynamic import, including its location, the import statement, and surrounding code context. ```text File: graphistry/compute/chain_remote.py Line: 174 Import: import json Context: Inside try block in chain_remote_generic() Reason: [Analyze why it's dynamic] Code: try: import json # <-- DYNAMIC IMPORT metadata_content = zip_ref.read('metadata.json') metadata = json.loads(metadata_content.decode('utf-8')) ``` -------------------------------- ### Check Graphistry Version Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/spanner/google_spanner_finance_graph.ipynb Verify the installed version of the Graphistry library. No setup is required beyond importing the library. ```python import os import graphistry graphistry.__version__ ``` -------------------------------- ### Import Libraries and Get Version Source: https://github.com/graphistry/pygraphistry/blob/master/demos/gfql/python_remote.ipynb Import necessary libraries for Graphistry and Pandas, and check the installed Graphistry version. ```python import pandas as pd import graphistry from graphistry import n, e_undirected, e_forward graphistry.__version__ ``` -------------------------------- ### Get Graphistry version Source: https://github.com/graphistry/pygraphistry/blob/master/demos/ai/cyber/redteam-umap-gtc-gpu.ipynb Retrieves and displays the currently installed version of the Graphistry library. This is useful for compatibility checks and debugging. ```python graphistry.__version__ ``` -------------------------------- ### Run Graph-benchmark Q1-Q9 Source: https://github.com/graphistry/pygraphistry/blob/master/benchmarks/gfql/README.md Replay queries q1-q9 from the graph-benchmark project against Graphistry. Refer to `benchmarks/gfql/graph_benchmark.md` for detailed setup instructions. ```bash uv run python benchmarks/gfql/graph_benchmark_q1_q9.py \ --graph-benchmark-root /home/lmeyerov/Work/graph-benchmark \ --runs 5 --warmup 1 \ --output-json /tmp/graph-benchmark-q1-q9.json ``` -------------------------------- ### Setup and Imports for GFQL Validation Source: https://github.com/graphistry/pygraphistry/blob/master/demos/gfql/gfql_validation_fundamentals.ipynb Imports necessary modules for PyGraphistry and GFQL operations, including exception types for error handling. Checks and prints the installed PyGraphistry version. ```python # Core imports import pandas as pd import graphistry from graphistry.compute.chain import Chain from graphistry.compute.ast import n, e_forward, e_reverse # Exception types for error handling from graphistry.compute.exceptions import \ GFQLValidationError, GFQLSyntaxError, GFQLTypeError, GFQLSchemaError, ErrorCode # Check version print(f"PyGraphistry version: {graphistry.__version__}") print("\nValidation is now built-in to GFQL operations!") ``` -------------------------------- ### Setup RAPIDS for Google Colab Source: https://github.com/graphistry/pygraphistry/blob/master/demos/gfql/GPU_memory_consumption_tutorial.ipynb Installs RAPIDS and checks GPU compatibility in Google Colab. Run this and the next cell only. Read the output carefully for any warnings or remediation steps. ```python # For freely testing on colab.research.google.com: # RAPIDS for Google Colab # This get the RAPIDS-Colab install files and test check your GPU. Run this and the next cell only. # Please read the output of this cell. If your Colab Instance is not RAPIDS compatible, it will warn you and give you remediation steps. ! git clone -q https://github.com/rapidsai/rapidsai-csp-utils.git ! python rapidsai-csp-utils/colab/pip-install.py > /dev/null 2>&1 ``` -------------------------------- ### Run HTML Documentation Build Source: https://github.com/graphistry/pygraphistry/blob/master/docs/README.md Execute this script to build the HTML documentation. The output is emitted to docs/_build/html/index.html. ```bash docs $ ./html.sh ``` -------------------------------- ### SQL Connection String Setup Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/sql/postgres.ipynb Defines user credentials and server details for establishing a SQL database connection. For enhanced security and reusability, consider storing credentials in a JSON file and reading them into the notebook. ```python user = "graphistry" pwd = "password" server = "postgres:5432" ##OPTIONAL: Mount in installation's ${PWD}/.notebooks/db_secrets.json and read in #import json #with open('/home/graphistry/notebooks/db_secrets.json') as json_file: # cfg = json.load(json_file) # user = cfg['user'] # pwd = cfg['pwd'] # server = cfg['server'] # ## .. The first time you run this notebook, save the secret cfg to the system's persistent notebook folder: #import json #with open('/home/graphistry/notebooks/db_secrets.json', 'w') as outfile: # json.dump({ # "user": "graphistry", # "pwd": "password", # "server": "postgres:5432" # }, outfile) ## Delete ^^^ after use db_string = "postgres://" + user + ":" + pwd + "@" + server ### Take care not to save a print of the result ``` -------------------------------- ### Local Development Environment Setup Source: https://github.com/graphistry/pygraphistry/blob/master/ai/README.md Commands for setting up a local development environment, including linting, type checking, and running tests. Note that direct script execution requires a local environment setup. ```bash # ./bin/lint.sh && ./bin/mypy.sh && ./bin/pytest.sh ``` -------------------------------- ### Basic GFQL WHERE Usage Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/gfql/where.rst Use `g.gfql` with the `where` parameter to add constraints between named steps in a chain. This example relates attributes across the same path, such as ensuring the owner ID of a start node matches the owner ID of an end node. ```python from graphistry import n, e_forward, col, compare g_filtered = g.gfql( [ n({"type": "account"}, name="a"), e_forward(name="e"), n({"type": "user"}, name="c"), ], where=[ compare(col("a", "owner_id"), "==", col("c", "owner_id")), compare(col("e", "org_id"), "==", col("a", "org_id")), ], ) g_filtered.plot() ``` -------------------------------- ### Run Full Documentation Build (CI Mimic) Source: https://github.com/graphistry/pygraphistry/blob/master/docs/README.md Mimic the CI runner to generate all documentation types, including epub and pdf. This command can also be run from the repo root with an explicit format. ```bash docs $ ./ci.sh ``` ```bash DOCS_FORMAT=html ./docs/ci.sh ``` -------------------------------- ### Calculate Explicit Timestamps for Duration Queries Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/gfql/datetime_filtering.md When duration or interval types are not supported, calculate explicit start and end timestamps for your queries. This example shows how to find events within the last 7 days and filter for events within a specific year. ```python from datetime import datetime, timedelta # Find events within last 7 days now = datetime.now() week_ago = now - timedelta(days=7) recent_events = g.gfql([ n(filter_dict={"timestamp": gt(pd.Timestamp(week_ago))}) ]) # For recurring intervals, use multiple conditions business_days = g.gfql([ n(filter_dict={ "timestamp": between( pd.Timestamp("2023-01-01"), pd.Timestamp("2023-12-31") ) }) ]) ``` -------------------------------- ### Complete KeplerLayer Example Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/api/kepler/layer_format.rst Demonstrates the creation of a KeplerLayer with point configuration, data mapping, and visual channels for color and size. ```python from graphistry import KeplerLayer layer = KeplerLayer({ "id": "city-points", "type": "point", "config": { "dataId": "cities", "label": "City Locations", "color": [255, 140, 0], "columns": { "lat": "latitude", "lng": "longitude" }, "isVisible": True, "visConfig": { "radius": 10, "opacity": 0.8, "outline": True, "thickness": 2 } }, "visualChannels": { "colorField": { "name": "population", "type": "real" }, "colorScale": "quantile", "sizeField": { "name": "gdp", "type": "real" }, "sizeScale": "sqrt" } }) ``` -------------------------------- ### Multi-Policy Server Pattern Example Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/gfql/policy.rst Shows how multiple orthogonal policies can be composed using shortcuts for server-side scenarios like telemetry, security, and resource limits. ```python # Server scenario: telemetry + security + resource limits policy = { 'pre': create_otel_span, # OpenTelemetry tracing 'post': end_otel_span, # Span cleanup 'postload': check_size_limits, # Resource limits after data load 'precall': validate_jwt_token # Security validation before operations } # This composes cleanly: # - All pre* hooks get telemetry spans # - postload gets both telemetry cleanup + size checking # - precall gets telemetry + JWT validation # - Other post* hooks get just telemetry cleanup ``` -------------------------------- ### Import Libraries and Initialize Graphistry Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/neptune/neptune_cypher_viz_using_bolt.ipynb Import necessary libraries and initialize Graphistry. Configure your Graphistry account details using graphistry.register(). ```python import awswrangler as wr import pandas as pd import graphistry graphistry.__version__ ``` ```python # To specify Graphistry account & server, use: # graphistry.register(api=3, username='...', password='...', protocol='https', server='hub.graphistry.com') # To run from a graphistry-host jupyter notebook: # graphistry.register(api=3, username="...", password="...", protocol="http", server="nginx") # to use personal keys: # graphistry.register(api=3, protocol="...", server="...", personal_key_id='pkey_id', personal_key_secret='pkey_secret') # Key instead of username+password+org_name # For more options: https://pygraphistry.readthedocs.io/en/latest/server/register.html graphistry.register(api=3, username="...", password="...", protocol="...", server="...") ``` -------------------------------- ### Install PyGraphistry and Bolt Driver Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/memgraph/visualizing_iam_dataset.ipynb Install the PyGraphistry library and the Neo4j Bolt drivers using pip. Ensure you uncomment these lines to execute the installation. ```python #!pip install --user graphistry #!pip install --user graphistry[bolt] ``` -------------------------------- ### Install PyGraphistry Without Dependencies Source: https://github.com/graphistry/pygraphistry/blob/master/README.md Installs PyGraphistry at the user level without installing any additional dependencies. Useful for environments where dependency management is handled separately. ```bash pip install --no-deps --user graphistry ``` -------------------------------- ### Policy Composition with Shortcuts Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/gfql/policy.rst Demonstrates how multiple shortcuts and specific hook handlers compose together, showing the execution order. ```python from graphistry.compute.gfql.policy import expand_policy, debug_policy def auth_check(ctx): """General authentication check""" pass def rate_limit(ctx): """Rate limiting for calls""" pass def validate_params(ctx): """Specific parameter validation""" pass policy = { 'pre': auth_check, # Applies to ALL pre* hooks 'call': rate_limit, # Applies to precall + postcall 'precall': validate_params # Applies only to precall } # At precall, handlers execute in order: auth_check → rate_limit → validate_params # At postcall, handlers execute in reverse (LIFO): rate_limit → auth_check ``` -------------------------------- ### Initialize Logging and Import Graphistry Source: https://github.com/graphistry/pygraphistry/blob/master/DEVELOP.md Set up basic logging to DEBUG level and import the graphistry library to check its version. ```python import logging logging.basicConfig(level=logging.DEBUG) import graphistry graphistry.__version__ ``` -------------------------------- ### Format New Algorithm Example Source: https://github.com/graphistry/pygraphistry/blob/master/ai/prompts/GFQL_LLM_GUIDE_MAINTENANCE.md Standard format for documenting a new algorithm, including dense and JSON representations, and a use case explanation. ```markdown **[Name] ([Use Case]):** ```python # Dense: call('fn', {'param': val}) ``` ```json {"type": "Call", "function": "fn", "params": {"param": val}} ``` **Use case**: [One-line explanation] ``` -------------------------------- ### Install PyGraphistry from Git repository Source: https://github.com/graphistry/pygraphistry/blob/master/demos/talks/infosec_jupyterthon2022/rgcn_login_anomaly_detection/advanced-identity-protection-40m.ipynb Installs PyGraphistry by directly cloning and installing from specific commits in its GitHub repository. This is useful for testing development versions or specific bug fixes. ```python #! pip cache remove graphistry #! pip install --no-cache --user https://github.com/graphistry/pygraphistry/archive/heteroembed.zip #! pip install --user git+https://github.com/graphistry/pygraphistry.git@fe894b556d078a35d1109c5cb78150818950d66d #! pip install --user git+https://github.com/graphistry/pygraphistry.git@d7e87c0faf762be5c8779c71caf8da13fae48041 #! pip install --user git+https://github.com/graphistry/pygraphistry.git@6f47e034dcf8e96f241be66aca6a6a6374e7bf83 ``` -------------------------------- ### Basic Geographic Visualization Setup Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/api/kepler/index.rst Prepare node data with latitude and longitude, then bind these columns to enable automatic geographic visualization. Requires pandas and graphistry. ```python import graphistry import pandas as pd # Prepare data nodes_df = pd.DataFrame({ 'id': ['NYC', 'LA', 'Chicago'], 'lat': [40.7128, 34.0522, 41.8781], 'lon': [-74.0060, -118.2437, -87.6298] }) # Automatic geographic visualization g = graphistry.nodes(nodes_df, 'id') g = g.bind(point_longitude='lon', point_latitude='lat') g.plot() ``` -------------------------------- ### Apply Layout Algorithms with GFQL Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/gfql/quick.rst Example snippet showing the import of necessary functions for applying layout algorithms within GFQL queries. ```python from graphistry import call, let, ref, n, e_forward, is_in ``` -------------------------------- ### Add Docstring and Examples for Predicate Function Source: https://github.com/graphistry/pygraphistry/blob/master/ai/docs/gfql/predicates_checklist.md Write a clear docstring for the predicate function in Python, including arguments, return types, and progressive examples. This follows the template for Args, Returns, and Examples. ```python def startswith(pat: Union[str, tuple], case: bool = True, na: Optional[bool] = None) -> Startswith: """Return whether pattern(s) match at start of string Args: pat: Pattern or tuple. Tuple uses OR logic (any match = True) case: Case-sensitive if True (default: True) na: Fill value for missing (default: None) Returns: Startswith predicate Examples: >>> n({"name": startswith("John")}) # Basic >>> n({"name": startswith("john", case=False)}) >>> n({"filename": startswith(("test_", "demo_"))}) # Multiple patterns """ return Startswith(pat, case, na) ``` -------------------------------- ### Initialize Graphistry and Register API Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/gpu_rapids/cugraph.ipynb Import necessary libraries, print the Graphistry version, and register your API credentials. Ensure you have your username and password ready. ```python import graphistry, pandas as pd print(graphistry.__version__) graphistry.register(api=3, username='...', password='...') ``` -------------------------------- ### Install awswrangler Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/neptune/neptune_cypher_viz_using_bolt.ipynb Install the awswrangler library for interacting with AWS services like Neptune. ```python !pip install --user awswrangler ``` -------------------------------- ### Install neo4j driver Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/neptune/neptune_cypher_viz_using_bolt.ipynb Install the neo4j Python driver, which is required for the Bolt connector. ```python !pip install --user neo4j ``` -------------------------------- ### Example DOT Output Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/visualization/10min.rst A basic example of DOT language syntax for graph representation. ```dot digraph G { a -> b; b -> c; a -> tx1; } ``` -------------------------------- ### Install Graphistry with Jupyter extras Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/install/extended.rst Install PyGraphistry with ipython for enhanced Jupyter notebook integration. ```bash pip install graphistry[jupyter] ``` -------------------------------- ### Initialize UnimatrixClient and Graphistry Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/alienvault/usm.ipynb Initializes the UnimatrixClient for data retrieval and sets up Graphistry for visualization. Ensure your Graphistry credentials and server details are correctly configured. ```python from unimatrix import UnimatrixClient import graphistry # To specify Graphistry account & server, use: # graphistry.register(api=3, username='...', password='...', protocol='https', server='hub.graphistry.com') # For more options: https://pygraphistry.readthedocs.io/en/latest/server/register.html client = UnimatrixClient("my_subdomain", "client_id", "client_secret") ``` -------------------------------- ### Set up Local AI Skill Paths Source: https://github.com/graphistry/pygraphistry/blob/master/CLAUDE.md Use these commands to create symbolic links for local AI skill path conventions. This setup is useful for aligning your local development environment with different AI agent frameworks. ```bash ln -s agents .agents mkdir -p .claude ln -s ../.agents/skills .claude/skills ``` -------------------------------- ### Install Graphistry with Gremlin extras Source: https://github.com/graphistry/pygraphistry/blob/master/docs/source/install/extended.rst Install PyGraphistry with gremlinpython for working with Gremlin graph databases. ```bash pip install graphistry[gremlin] ``` -------------------------------- ### Initialize OTX and Graphistry Connector Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_databases_apis/alienvault/OTXIndicators.ipynb Initialize the OTXv2 client with your API key and the Graphistry OTX connector. Configure Graphistry account and server details if not using defaults. ```python # To specify Graphistry account & server, use: # graphistry.register(api=3, username='...', password='...', protocol='https', server='hub.graphistry.com') # For more options: https://pygraphistry.readthedocs.io/en/latest/server/register.html otx = OTXv2("MY_KEY") g_otx = G_OTX(graphistry, otx) ``` -------------------------------- ### Install PyGraphistry with IGraph Support Source: https://github.com/graphistry/pygraphistry/blob/master/demos/demos_by_use_case/social/Twitter.ipynb Install the pygraphistry library with the necessary dependencies for igraph integration. ```python #! pip install graphistry[igraph] ```