I have a network dataset with roads and junctions.
I am wondering what class I can use in ArcPy to extract FromJunctionId and the ToJunctionId for each road segment in the network dataset.
You need to create topology rules where input feature class operations equal output feature class operations where you are creating true nodes and filtering out false nodes.
A feature similar is point intersection. You could also create a convex hull to incorporate your to and from edges, (not segments) where the true node is all positive and negative edge (to-from) pairs contained by points following programmetric rules centred on a central point within the the topologic figure which would function as the lat long of the true node.
A secondary operation could associate street names or classes with associated pairs as a name feature class and could be programmaticaly linked to create an routing association using either and nor loops associating names and node associations for the purpose of determining the two and from segments or nodes.
Points and lines and value schemas would seem useful as a more specific answer to the way your question is posed.
these first point and last point are the toJunctionId and fromJunctionId. To know more about polyline properties you may read this