def add_package_to_project(project, req):
    if '@' in req:
        name, version = req.split('@', 1)
        version_hint = version
    else:
        name = req
        version = None
        version_hint = 'latest release'

    cfg = project.open_config()
    info = _get_package_version_from_project(cfg, name)
    if info is not None:
        raise RuntimeError('The package was already added to the project.')

    for choice in name, 'lektor-' + name:
        rv = requests.get('https://pypi.python.org/pypi/%s/json' % choice)
        if rv.status_code != 200:
            continue

        data = rv.json()
        canonical_name = data['info']['name']
        if version is None:
            version = data['info']['version']
        version_info = data['releases'].get(version)
        if version_info is None:
            raise RuntimeError('Latest requested version (%s) could not '
                               'be found' % version_hint)

        cfg['packages.%s' % canonical_name] = version
        cfg.save()
        return {
            'name': canonical_name,
            'version': version
        }

    raise RuntimeError('The package could not be found on PyPI')
Given a pacakge requirement this returns the information about this
dataset/ETHPy150Open lektor/lektor/lektor/packages.py/add_package_to_project