import decimal


def pi_using_decimal_lib(precision):
    """Get value of pi via BBP formula to specified precision using decimal library.
    See: https://en.wikipedia.org/wiki/Bailey%E2%80%93Borwein%E2%80%93Plouffe_formula

    :param precision: Precision to retrieve.
    :return: Pi value with specified precision.
    """
    # Set precision for decimal library.
    decimal.getcontext().prec = precision
    value = 0
    for k in range(precision):
        value += decimal.Decimal(1) / decimal.Decimal(16) ** k * (
            decimal.Decimal(4) / (decimal.Decimal(8) * k + decimal.Decimal(1)) -
            decimal.Decimal(2) / (decimal.Decimal(8) * k + decimal.Decimal(4)) -
            decimal.Decimal(1) / (decimal.Decimal(8) * k + decimal.Decimal(5)) -
            decimal.Decimal(1) / (decimal.Decimal(8) * k + decimal.Decimal(6))
        )
    return value