import typing
import re


def get_package_namespace(package: str, namespaces: typing.Dict[typing.Union[str, None], str]) -> typing.Tuple[str, str]:
    """ Get the prefix and URI for the namespace of an SBML package

    Args:
        package (:obj:`str`): SBML package id (e.g., ``fbc``, ``qual``)
        namespaces (:obj:`dict`): dictionary that maps namespace prefixes to URIs

    Returns:
        :obj:`tuple`:

            * :obj:`str`: prefix
            * :obj:`str`: URI
    """
    sbml_fbc_prefixes = set()
    sbml_fbc_uris = set()
    for prefix, uri in namespaces.items():
        if uri and re.match(r'^http://www.sbml.org/sbml/level\d+/version\d+/{}/version\d+$'.format(package), uri):
            sbml_fbc_prefixes.add(prefix)
            sbml_fbc_uris.add(uri)
    if len(sbml_fbc_uris) != 1:
        raise ValueError('Namespaces must include 1 SBML {} namespace.'.format(package))
    return list(sbml_fbc_prefixes)[0], list(sbml_fbc_uris)[0]