Skip to content

AlgoGraph v1.2.0 - Fluent Builder API

Choose a tag to compare

@queelius queelius released this 13 Nov 17:10
· 12 commits to main since this release

AlgoGraph v1.2.0 - Fluent Builder API

Phase 1 of the v2.0 roadmap is complete! This release dramatically improves developer ergonomics with a fluent builder API that reduces code by up to 92% for common graph construction patterns.

🎉 New Features

GraphBuilder - Fluent Chainable API

# Clean, expressive syntax
g = (Graph.builder()
     .add_vertices('A', 'B', 'C')
     .add_edge('A', 'B', weight=5)
     .add_path('B', 'C', 'D')
     .build())

Pattern Methods

  • add_path() - Create paths with one method call
  • add_cycle() - Create cycles instantly
  • add_complete() - Complete graphs (cliques) in one line
  • add_star() - Star topology in one line
  • add_bipartite() - Bipartite structures with optional complete edges

Convenience Classmethods

  • Graph.builder() - Create a GraphBuilder
  • Graph.from_edges() - Build from edge tuples
  • Graph.from_vertices() - Build from vertex IDs

Auto-Creation

Vertices are automatically created when you add edges - no more boilerplate!

📊 Code Reduction

Pattern Before After Reduction
Complete K5 13 lines 1 line 92%
Star (5 nodes) 8 lines 1 line 88%
Path (4 nodes) 7 lines 1 line 86%
Simple graph 7 lines 4 lines 43%
Average 8.2 lines 1.5 lines 82%

💡 Examples

Before (v1.1.0):

vertices = {Vertex('A'), Vertex('B'), Vertex('C')}
edges = {
    Edge('A', 'B', weight=5),
    Edge('B', 'C', weight=3),
    Edge('C', 'A', weight=2)
}
g = Graph(vertices, edges)

After (v1.2.0):

g = Graph.builder().add_cycle('A', 'B', 'C').build()

86% less code!

Real-World Examples:

Social Network:

network = (Graph.builder()
          .add_vertex('Alice', age=30, city='NYC')
          .add_vertex('Bob', age=25, city='Boston')
          .add_edge('Alice', 'Bob', directed=False, relationship='friend')
          .build())

Dependency Graph:

deps = (Graph.builder()
       .add_vertices('app', 'lib1', 'lib2', 'utils')
       .add_edge('app', 'lib1')
       .add_edge('lib1', 'utils')
       .build())

Complete Graph:

k5 = Graph.builder().add_complete('A', 'B', 'C', 'D', 'E').build()

🧪 Testing

  • 33 new tests for builder functionality
  • 98/98 tests passing (13 skipped for optional AlgoTree)
  • 100% backward compatible - all existing code works unchanged
  • 0 regressions

📚 Documentation

New comprehensive documentation:

  • PHASE1_SUMMARY.md - Complete Phase 1 overview with examples
  • ARCHITECTURAL_REVIEW.md - Full architectural analysis (21,000 words)
  • API_COMPARISON.md - Before/after code examples with metrics

🚀 Quick Start

# Install/update
export PYTHONPATH=/path/to/released:$PYTHONPATH

# Try the new API
python3
>>> from AlgoGraph import Graph
>>> g = Graph.builder().add_cycle('A', 'B', 'C').build()
>>> g.vertex_count
3

🔧 Technical Details

New Files:

  • builder.py (340 lines) - GraphBuilder implementation
  • test/test_builder.py (314 lines) - Comprehensive tests

Modified Files:

  • graph.py - Added builder(), from_edges(), from_vertices()
  • __init__.py - Export GraphBuilder, bump to v1.2.0

Total: ~700 lines of new functionality

🎯 What's Next

Phase 1 is complete! Next up:

  • Phase 2: Core missing algorithms (flow networks, centrality, matching, coloring)
  • Phase 3: Advanced features (transformers, selectors, generic types)

See ARCHITECTURAL_REVIEW.md for the complete roadmap.

📦 Files in This Release

  • All Phase 1 builder functionality
  • Comprehensive test suite
  • Full documentation
  • Architectural review documents

🔗 Links


Full Changelog: v1.1.0...v1.2.0