Skip to main content

nan-graph (Python)

Port en Python del core @carloscortezcloud/nan-graph (TypeScript) — el motor del grafo de SOFE Architecture Graph (fusión Ñan × BYaML v2). OSS, Apache-2.0, bajo breakingthecloud.

Misma API que el core TS; se mantiene en sync manual (patrón styrrstyrr-py).

Grafo dirigido en memoria con relaciones tipadas: traversal BFS/DFS, blast radius, cost chain, fan-in / SPOF, y filtrado por tipo de relación.

Install

pip install nan-graph

Uso

from nangraph import NanGraph, blast_radius, cost_chain, from_yaml

g = (
    NanGraph()
    .add_node({"id": "api", "type": "aws.apigateway", "attrs": {"monthly_cost": 20}})
    .add_node({"id": "lambda", "type": "aws.lambda", "attrs": {"monthly_cost": 5}})
    .add_node({"id": "ddb", "type": "aws.dynamodb", "attrs": {"monthly_cost": 30}})
    .add_edge("api", "lambda", "routes_to")
    .add_edge("lambda", "ddb", "reads_writes")
)

blast_radius(g, "api")   # ['lambda', 'ddb'] — qué se cae si api falla
cost_chain(g, "api")     # 55.0 — costo downstream total

Importar desde YAML / JSON

from nangraph import from_yaml, from_object

# estilo dependency-graph.yaml
g = from_yaml("""
nodes:
  sofe-engine: { type: python-library }
  sofe-server: { type: python-api }
edges:
  - { from: sofe-engine, to: sofe-server, relType: bundles }
""")

# estilo BYaML v0.3 (components + relationships)
g2 = from_object({
    "components": [{"id": "api", "type": "aws.apigateway", "monthly_cost": 20}],
    "relationships": [{"from": "api", "to": "lambda", "type": "routes_to"}],
})

API

Función Descripción
NanGraph() Grafo dirigido multi-borde en memoria
add_node(dict) / add_edge(from, to, rel_type) Añadir nodo/arista (auto-crea nodos)
get_related(id, rel_type?, direction?) Vecinos outgoing/incoming/both, con filtro
traverse_bfs(g, start, rel_types?, max_depth?, direction?) BFS
traverse_dfs(g, start, ...) DFS
blast_radius(g, start) Nodos afectados downstream si start falla
cost_chain(g, start) Suma attrs.monthly_cost de start + downstream
team_cost(g, owner) Suma de costo por attrs.owner
fan_in(g, id) / single_points_of_failure(g, threshold) SPOF por alta dependencia entrante
from_object(dict) / from_yaml(str) / from_json(str) Construir grafo desde input

Paridad con el core TS

TS (@carloscortezcloud/nan-graph) Python (nan-graph)
new NanGraph() NanGraph()
g.addNode / g.addEdge g.add_node / g.add_edge
g.getRelated g.get_related
traverseBFS / traverseDFS traverse_bfs / traverse_dfs
blastRadius / costChain blast_radius / cost_chain
teamCost / fanIn / singlePointsOfFailure team_cost / fan_in / single_points_of_failure
fromObject / fromYaml / fromJson from_object / from_yaml / from_json

Licencia

Apache-2.0. Ver LICENSE.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nan_graph-0.1.0.tar.gz (17.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nan_graph-0.1.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file nan_graph-0.1.0.tar.gz.

File metadata

  • Download URL: nan_graph-0.1.0.tar.gz
  • Upload date:
  • Size: 17.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for nan_graph-0.1.0.tar.gz
Algorithm Hash digest
SHA256 501104a9815b18a3c286cfc26022c26b2e1889a92b8bda6bd543a9417581ec9d
MD5 d6cf55d7691f472c5b7993c2b14eb1f2
BLAKE2b-256 f0700c60ed94730b818ed658807c59b80464bc15972eb83d8cd8885027d4066d

See more details on using hashes here.

File details

Details for the file nan_graph-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: nan_graph-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.17

File hashes

Hashes for nan_graph-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e84fbb391d8f22a0d22ecc2d9642453cfc1a0525a3fc54a6703369035dcb53dc
MD5 31fe31cc0fb1af86323005096af2ce76
BLAKE2b-256 a6ecae3cef7010cc19150b7fc8e5908e7688572f479fa6d47116159cf854770a

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page