Open up a Python shell with Warehouse preconfigured in it.

def shell(config, type_):
    """
    Open up a Python shell with Warehouse preconfigured in it.
    """

    # Imported here because we don't want to trigger an import from anything
    # but warehouse.cli at the module scope.
    from warehouse.db import Session

    if type_ is None:
        type_ = autodetect()

    runner = {"bpython": bpython, "ipython": ipython, "plain": plain}[type_]

    session = Session(bind=config.registry["sqlalchemy.engine"])

    try:
        runner(config=config, db=session)
    except ImportError:
        raise click.ClickException(
            "The {!r} shell is not available.".format(type_)
        ) from None