I am trying to calculate shortest path between 2 points using Dijkstra and A Star algorithms (in a directed NetworkX graph). 
At the moment it works fine and I can see the calculated path but I would like to find a way of restricting certain paths.
For example if we have following nodes:
nodes = [1,2,3,4]
With these edges:
edges = ( (1,2),(2,3),(3,4) )
Is there a way of blocking/restricting  1 -> 2 -> 3 but still allow 2 -> 3 & 1 -> 2.
This would mean that: 

can travel from 1 to 2
can travel from 2 to 3
cannot travel from 1 to 3 .. directly or indirectly (i.e. restrict 1->2->3 path).

Can this be achieved in NetworkX.. if not is there another graph library in Python that would allow this ?
Thanks.
You could set your node data {color=['blue']} for node 1, node 2 has {color=['red','blue']} and node3 has {color=['red']}.  Then use an networkx.algorithms. astar_path() approach setting the 

heuristic is set to a function which returns a might_as_well_be_infinity when it encountered an node without the same color you are searching for
weight=less_than_infinity.
How to restrict certain paths in NetworkX graphs?