---
title: "Path Finding Functions"
component: "pytigergraph"
version: "1.8"
module: "core-functions"
html_url: "/pytigergraph/1.8/core-functions/path"
canonical_url: "https://www.tigergraph.com/docs/pytigergraph/1.8/core-functions/path"
markdown_url: "https://www.tigergraph.com/docs/pytigergraph/1.8/core-functions/path.md"
---

[View as HTML](https://www.tigergraph.com/docs/pytigergraph/1.8/core-functions/path)

# Path Finding Functions

The functions on this page find paths between vertices within the graph. All functions in this module are called as methods on a [TigerGraphConnection object](https://www.tigergraph.com/docs/pytigergraph/1.8/core-functions/base.md).

## Methods

### shortestPath()

`shortestPath(sourceVertices: Union[dict, tuple, list], targetVertices: Union[dict, tuple, list], maxLength: int = None, vertexFilters: Union[list, dict] = None, edgeFilters: Union[list, dict] = None, allShortestPaths: bool = False) → dict`

Finds the shortest path (or all shortest paths) between the source and target vertex sets.

A vertex set is a set of dictionaries that each has three top-level keys: `v_type`, `v_id`, and `attributes` (also a dictionary).

#### Parameters:

* `sourceVertices`: A vertex set (a list of vertices) or a list of `(vertexType, vertexID)` tuples; the source vertices of the shortest paths sought.
* `targetVertices`: A vertex set (a list of vertices) or a list of `(vertexType, vertexID)` tuples; the target vertices of the shortest paths sought.
* `maxLength`: The maximum length of a shortest path. Optional, default is 6.
* `vertexFilters`: An optional list of `(vertexType, condition)` tuples or`{"type": <str>, "condition": <str>}` dictionaries.
* `edgeFilters`: An optional list of `(edgeType, condition)` tuples or`{"type": <str>, "condition": <str>}` dictionaries.
* `allShortestPaths`: If `True`, the endpoint will return all shortest paths between the source and target. Default is `False`, meaning that the endpoint will return only one path.

#### Returns:

The shortest path between the source and the target. The returned value is a subgraph: all vertices and edges that are part of the path(s); i.e. not a (list of individual) path(s).

#### Examples:

```python
path = conn.shortestPath(("account", 10), ("person", 50), maxLength=3)

path = conn.shortestPath(("account", 10), ("person", 50), allShortestPaths=True,
vertexFilters=("transfer", "amount>950"), edgeFilters=("receive", "type=4"))
```

#### Endpoint:

* `POST /shortestpath/{graphName}`See [Find the shortest path](https://www.tigergraph.com/docs/tigergraph-server/4.3/API/built-in-endpoints.md#_find_shortest_path).

### allPaths()

`allPaths(sourceVertices: Union[dict, tuple, list], targetVertices: Union[dict, tuple, list], maxLength: int, vertexFilters: Union[list, dict] = None, edgeFilters: Union[list, dict] = None) → dict`

Find all possible paths up to a given maximum path length between the source and target vertex sets.

A vertex set is a dict that has three top-level keys: v\_type, v\_id, attributes (a dict).

#### Parameters:

* `sourceVertices`: A vertex set (a list of vertices) or a list of `(vertexType, vertexID)` tuples; the source vertices of the shortest paths sought.
* `targetVertices`: A vertex set (a list of vertices) or a list of `(vertexType, vertexID)` tuples; the target vertices of the shortest paths sought.
* `maxLength`: The maximum length of the paths.
* `vertexFilters`: An optional list of `(vertexType, condition)` tuples or`{"type": <str>, "condition": <str>}` dictionaries.
* `edgeFilters`: An optional list of `(edgeType, condition)` tuples or`{"type": <str>, "condition": <str>}` dictionaries.

#### Returns:

All paths between a source vertex (or vertex set) and target vertex (or vertex set). The returned value is a subgraph: all vertices and edges that are part of the path(s); i.e. not a (list of individual) path(s).

#### Example:

```python
path = conn.allPaths(("account", 10), ("person", 50), allShortestPaths=True,
vertexFilters=("transfer", "amount>950"), edgeFilters=("receive", "type=4"))
```

#### Endpoint:

* `POST /allpaths/{graphName}`See [Find all paths](https://www.tigergraph.com/docs/tigergraph-server/4.3/API/built-in-endpoints.md#_find_all_paths)
