def to_pypsa(network, mode, timesteps):
    """
    Translate graph based grid representation to PyPSA Network

    For details from a user perspective see API documentation of
    :meth:`~.grid.network.EDisGo.analyze` of the API class
    :class:`~.grid.network.EDisGo`.

    Translating eDisGo's grid topology to PyPSA representation is structured
    into translating the topology and adding time series for components of the
    grid. In both cases translation of MV grid only (`mode='mv'`), LV grid only
    (`mode='lv'`), MV and LV (`mode=None`) share some code. The
    code is organized as follows:

    * Medium-voltage only (`mode='mv'`): All medium-voltage grid components are
      exported by :func:`mv_to_pypsa` including the LV station. LV grid load
      and generation is considered using :func:`add_aggregated_lv_components`.
      Time series are collected by `_pypsa_load_timeseries` (as example
      for loads, generators and buses) specifying `mode='mv'`). Timeseries
      for aggregated load/generation at substations are determined individually.
    * Low-voltage only (`mode='lv'`): LV grid topology including the MV-LV
      transformer is exported. The slack is defind at primary side of the MV-LV
      transformer.
    * Both level MV+LV (`mode=None`): The entire grid topology is translated to
      PyPSA in order to perform a complete power flow analysis in both levels
      together. First, both grid levels are translated seperately using
      :func:`mv_to_pypsa` and :func:`lv_to_pypsa`. Those are merge by
      :func:`combine_mv_and_lv`. Time series are obtained at once for both grid
      levels.

    This PyPSA interface is aware of translation errors and performs so checks
    on integrity of data converted to PyPSA grid representation

    * Sub-graphs/ Sub-networks: It is ensured the grid has no islanded parts
    * Completeness of time series: It is ensured each component has a time
      series
    * Buses available: Each component (load, generator, line, transformer) is
      connected to a bus. The PyPSA representation is check for completeness of
      buses.
    * Duplicate labels in components DataFrames and components' time series
      DataFrames

    Parameters
    ----------
    network : :class:`~.grid.network.Network`
        eDisGo grid container
    mode : str
        Determines grid levels that are translated to
        `PyPSA grid representation
        <https://www.pypsa.org/doc/components.html#network>`_. Specify

        * None to export MV and LV grid levels. None is the default.
        * ('mv' to export MV grid level only. This includes cumulative load and
          generation from underlying LV grid aggregated at respective LV
          station. This option is implemented, though the rest of edisgo does
          not handle it yet.)
        * ('lv' to export LV grid level only. This option is not yet
           implemented)
    timesteps : :pandas:`pandas.DatetimeIndex<datetimeindex>` or \
        :pandas:`pandas.Timestamp<timestamp>`
        Timesteps specifies which time steps to export to pypsa representation
        and use in power flow analysis.

    Returns
    -------
        :pypsa:`pypsa.Network<network>`
            The `PyPSA network
            <https://www.pypsa.org/doc/components.html#network>`_ container.

    """

    # check if timesteps is array-like, otherwise convert to list (necessary
    # to obtain a dataframe when using .loc in time series functions)
    if not hasattr(timesteps, "__len__"):
        timesteps = [timesteps]

    # get topology and time series data
    if mode is None:
        mv_components = mv_to_pypsa(network)
        lv_components = lv_to_pypsa(network)
        components = combine_mv_and_lv(mv_components, lv_components)

        if list(components['Load'].index.values):
            timeseries_load_p, timeseries_load_q = _pypsa_load_timeseries(
                network, mode=mode, timesteps=timesteps)

        if len(list(components['Generator'].index.values)) > 1:
            timeseries_gen_p, timeseries_gen_q = _pypsa_generator_timeseries(
                network, mode=mode, timesteps=timesteps)

        if list(components['Bus'].index.values):
            timeseries_bus_v_set = _pypsa_bus_timeseries(
                network, components['Bus'].index.tolist(), timesteps=timesteps)

        if len(list(components['StorageUnit'].index.values)) > 0:
            timeseries_storage_p, timeseries_storage_q = \
                _pypsa_storage_timeseries(
                    network, mode=mode, timesteps=timesteps)

    elif mode is 'mv':
        # the pypsa export works but NotImplementedError is raised since the
        # rest of edisgo (handling of results from pfa, grid expansion, etc.)
        # does not yet work
        raise NotImplementedError
        mv_components = mv_to_pypsa(network)
        components = add_aggregated_lv_components(network, mv_components)

        if list(components['Load'].index.values):
            timeseries_load_p, timeseries_load_q = _pypsa_load_timeseries(
                network, mode=mode, timesteps=timesteps)

        if len(list(components['Generator'].index.values)) > 1:
            timeseries_gen_p, timeseries_gen_q = _pypsa_generator_timeseries(
                network, mode=mode, timesteps=timesteps)

        if list(components['Bus'].index.values):
            timeseries_bus_v_set = _pypsa_bus_timeseries(
                network, components['Bus'].index.tolist(), timesteps=timesteps)

        if len(list(components['StorageUnit'].index.values)) > 0:
            timeseries_storage_p, timeseries_storage_q = \
                _pypsa_storage_timeseries(
                    network, mode=mode, timesteps=timesteps)

    elif mode is 'lv':
        raise NotImplementedError
        #lv_to_pypsa(network)
    else:
        raise ValueError("Provide proper mode or leave it empty to export "
                         "entire grid topology.")

    # check topology
    _check_topology(components)

    # create power flow problem
    pypsa_network = PyPSANetwork()
    pypsa_network.edisgo_mode = mode
    pypsa_network.set_snapshots(timesteps)

    # import grid topology to PyPSA network
    # buses are created first to avoid warnings
    pypsa_network.import_components_from_dataframe(components['Bus'], 'Bus')

    for k, comps in components.items():
        if k is not 'Bus' and not comps.empty:
            pypsa_network.import_components_from_dataframe(comps, k)

    # import time series to PyPSA network
    if len(list(components['Generator'].index.values)) > 1:
        import_series_from_dataframe(pypsa_network, timeseries_gen_p,
                                     'Generator', 'p_set')
        import_series_from_dataframe(pypsa_network, timeseries_gen_q,
                                     'Generator', 'q_set')

    if list(components['Load'].index.values):
        import_series_from_dataframe(pypsa_network, timeseries_load_p,
                                     'Load', 'p_set')
        import_series_from_dataframe(pypsa_network, timeseries_load_q,
                                     'Load', 'q_set')

    if list(components['Bus'].index.values):
        import_series_from_dataframe(pypsa_network, timeseries_bus_v_set,
                                     'Bus', 'v_mag_pu_set')

    if len(list(components['StorageUnit'].index.values)) > 0:
        import_series_from_dataframe(pypsa_network, timeseries_storage_p,
                                     'StorageUnit', 'p_set')
        import_series_from_dataframe(pypsa_network, timeseries_storage_q,
                                     'StorageUnit', 'q_set')

    _check_integrity_of_pypsa(pypsa_network)

    return pypsa_network