Skip to content

Territories

rigour.territories

Political geography

This module provides a set of classes and functions to work with countries, territories and jurisdictions. It is based on the notion that a territory is any political entity that may be referred to by a code, such as a country, a territory or a jurisdiction. Jurisdictions are most countries, but also sub-national entities like states, especially if they have their own legal incorporation regime.

For all territories, mappings to Wikidata QIDs are provided, as well as a set of other codes that may be used to refer to the same territory. The module also provides a set of functions to retrieve territories by their codes or QIDs.

get_ftm_countries()

Get all the countries that were supported by the FtM country property type.

Returns:

Type Description
List[Territory]

A list of territories.

Source code in rigour/territories/__init__.py
def get_ftm_countries() -> List[Territory]:
    """Get all the countries that were supported by the FtM `country`
    property type.

    Returns:
        A list of territories.
    """
    territories: List[Territory] = []
    for territory in get_territories():
        if territory.is_ftm:
            territories.append(territory)
    return territories

get_territories() cached

Get all the territories in the index.

Returns:

Type Description
List[Territory]

A list of territories.

Source code in rigour/territories/__init__.py
@cache
def get_territories() -> List[Territory]:
    """Get all the territories in the index.

    Returns:
        A list of territories.
    """
    return sorted(set(_get_index().values()))

get_territory(code)

Get a territory object for the given code.

Parameters:

Name Type Description Default
code str

Country, territory or jurisdiction code.

required

Returns:

Type Description
Optional[Territory]

A territory object.

Source code in rigour/territories/__init__.py
def get_territory(code: str) -> Optional[Territory]:
    """Get a territory object for the given code.

    Args:
        code: Country, territory or jurisdiction code.

    Returns:
        A territory object.
    """
    index = _get_index()
    code = clean_code(code)
    return index.get(code)

get_territory_by_qid(qid) cached

Get a territory object for the given Wikidata QID.

Parameters:

Name Type Description Default
qid str

Wikidata QID.

required

Returns:

Type Description
Optional[Territory]

A territory object.

Source code in rigour/territories/__init__.py
@cache
def get_territory_by_qid(qid: str) -> Optional[Territory]:
    """Get a territory object for the given Wikidata QID.

    Args:
        qid: Wikidata QID.

    Returns:
        A territory object.
    """
    for territory in _get_index().values():
        if qid in territory.qids:
            return territory
    return None