This directory contains 250+ example scripts demonstrating various features of py3plex. Examples are organised by topic to provide an intuitive learning path.
Choose your learning style:
For experienced developers who want to dive straight in:
- DSL Patterns Quick Reference - 8 essential patterns (5 minutes)
- Ergonomics Demo - Interactive query building with
.hint() - AGENTS.md - Comprehensive documentation
For learners who prefer a guided introduction:
- 10-Minute Tutorial - Complete workflow demonstration
- Built-in Datasets - Load and analyse sample networks
- DSL Patterns Quick Reference - Copy-paste patterns
For learning by browsing real code:
- Browse by topic below (e.g., Network Analysis)
- Run examples that match your use case
- Adapt patterns to your data
The dsl_patterns_quick_reference.py file provides executable, copy-paste ready patterns that cover 80% of use cases:
| Pattern | Code Snippet | Use Case |
|---|---|---|
| Basic Filtering | Q.nodes().where(degree__gt=5) |
Filter nodes by properties |
| Cross-Layer Hubs | .per_layer().top_k(10).coverage(mode="all") |
Nodes in multiple layers |
| Uncertainty | .uq(method="bootstrap", n_samples=100, seed=42) |
Confidence intervals |
| Layer Algebra | .from_layers(L["social"] + L["work"]) |
Combine layers |
| Custom Metrics | .mutate(normalized=lambda r: r["x"]/max(r["x"], 1)) |
Derive new metrics |
| Aggregation | .per_layer().aggregate(avg="mean(degree)") |
Layer statistics |
| Export | .to_pandas(), .to_networkx(), .to_arrow() |
Save results |
Run the file: python getting_started/dsl_patterns_quick_reference.py to see all patterns with live output.
New to py3plex? Start here.
- 10-minute tutorial covering essentials
- Creating and manipulating networks
- Basic NetworkX integration
- 15 examples - All fast and beginner-friendly
Load, save, and manage network data.
- Load from multiple formats (edgelist, GML, GraphML, etc.)
- Save networks in various formats
- Data validation and schema checking
- Performance optimisation (caching, lazy evaluation)
- 11 examples
Analyse network properties and compute metrics.
- Network statistics and metrics
- Centrality measures (degree, betweenness, eigenvector, etc.)
- Community detection (Louvain, Leiden, label propagation, SBM, AutoCommunity)
- Temporal network queries and windowed analysis
- Uncertainty quantification and bootstrap methods
- Node and layer similarity
- Statistical reports and comparisons
- Case studies (social networks, transportation, master regulators)
- 100+ examples - Comprehensive analysis toolkit
Minimal, copy-paste DSL patterns.
- 60+ standalone one-purpose scripts
- Covers filtering, grouping, coverage, UQ, export, temporal, community, semiring, etc.
- Each file is self-contained and fast to run
- 65 examples
Create network visualisations.
- Multiple layout styles (diagonal, hairball, radial, etc.)
- Interactive visualisations with Plotly
- Community colouring
- Animations and dynamic views
- 18 examples
Specialised techniques for power users.
- Network embeddings (Node2Vec)
- Dynamics and spreading processes (SIR, SIS, random walks)
- Network decomposition and classification
- Tensor operations and matrix methods
- Geometric analysis (Ricci curvature)
- 34 examples
Automation, workflows, and plugins.
- Config-driven workflows (YAML/JSON)
- Sklearn-style pipelines
- Plugin development and usage
- Null models and uncertainty workflows
- 12 examples
Run any example directly with Python:
python examples/network_analysis/example_multilayer_statistics.pyExamples are marked with runtime characteristics:
- FAST (< 5 seconds) - Quick to run, great for learning
- SKIP_CI: slow - Takes 10+ seconds to complete
- SKIP_CI: external_deps - Requires external dataset files
- SKIP_CI: interactive - Requires user interaction or displays GUI
See Getting Started for guided learning paths.
The examples CI workflow runs all fast standalone examples to ensure they work correctly.
Test examples locally as CI does:
python .github/scripts/run_examples.py --fast-only --timeout 30- API Documentation: https://skblaz.github.io/py3plex/
- Plugin Guide: Plugin System Documentation
- CLI Tutorial: Run
py3plex quickstartfor interactive demo
When creating a new example:
- Place it in the right category based on its primary purpose
- Add a descriptive docstring explaining what it demonstrates
- Mark runtime characteristics:
Runtime: FAST (< 5 seconds)for fast examplesSKIP_CI: slowif it takes 10+ secondsSKIP_CI: external_depsif it needs dataset filesSKIP_CI: interactiveif it requires user interaction
- Use environment checks for visualisations:
import os if os.environ.get('MPLBACKEND') != 'Agg': network.visualize_network(show=True)
Examples are organised by user goals rather than technical features:
- Good: Topic-based - "I want to detect communities"
- Avoid: Feature-based - "centrality_and_statistics"
This makes it easier for users to find relevant examples for their specific use case.