Task Lineage Dependencies

How do I get the dependency (with in DAG and inter DAG) lineage for a certain arbitrary task in a programatic way and store it? Provided a task ID, I should be able to navigate through all the up-streams and down-streams and then store in a JSON or database for reference.

inside an operator is the context object. that should have a task object in it. The task object has some methods such as get_flat_relatives as shown here in the sensor. https://github.com/apache/airflow/blob/11262c6d42c4612890a6eec71783e0a6d5b22c17/airflow/sensors/base_sensor_operator.py#L136

Here is where that function is defined