Skip to content

code-node

Point it at a Python project and it draws what one function does when it runs: the functions it calls, and the AWS services, HTTP endpoints and environment variables those reach. It reads the source with ast, so nothing is imported or run.

pip install code-node-graph
code-node path/to/your/repo
orders/handler.py
30def lambda_handler(event, context): 31 saved = 0 32 for record in event["Records"]: 33 bucket = record["s3"]["bucket"]["name"] 34 key = record["s3"]["object"]["key"] 35 for order in read_orders(bucket, key): 36 if not check(order): 37 log.warning("skipping %s", order.get("id")) 38 continue 39 store.save(order) 40 announce(order) 41 saved += 1 42 return {"saved": saved}
COMES INENTRYCALLSREACHESAn S3 eventRecords[] · keyEnvironment4 variableslambda_handler()handler.py line 30read_orders()handler.py line 19OrderStore.save()store.py line 16announce()notify.py line 14post_to_chat()notify.py line 20S3reads · writesDynamoDBwritesSNSsendsThe webPOST · no timeout
The graph for examples/orders-service in this repository, starting from its Lambda handler. Select a highlighted line to see the path it takes, or point at a box.

The page

The graph is one of two tabs on an HTML page. The other walks through each call step by step. It's one file that works offline, and everything on it but opening a box's hidden calls works without JavaScript.

A code-node page: the graph in its tab A code-node page: the graph in its tab

Running it

$ code-node examples/orders-service --list
1 entry point in examples/orders-service:
   1. orders.handler.lambda_handler  a Lambda handler (event, context)  (orders/handler.py:30)
$ code-node examples/orders-service
orders.handler.lambda_handler: 8 functions, 4 AWS calls

With no arguments it looks for places your code starts: console scripts, Lambda handlers, FastAPI, Flask and Django routes, Typer commands and if __name__ == "__main__": blocks. If it finds more than one, it asks. code-node --serve keeps the page open and redraws it each time you save a file.

Start has every option. Read the map explains the boxes and colours.

What it won't do

It never imports your modules, runs them, or calls AWS, and nothing leaves your machine. To name AWS operations, it reads botocore's service files from disk.

Some calls can't be known without running the code, like a function picked out of a dict or a client a library hands back. Those are left off the graph, and the page says where it stopped following.