def shapely_records(filename, **kwargs):
    """
    Uses `pyshp <https://pypi.python.org/pypi/pyshp/>`_ to return
    shapes and records from shapefiles.

    @param      filename        filename
    @param      kwargs          addition parameter for the shapefile reader,
                                useful options car *encoding* and *encodingErrors*
    @return                     shapes, records, fields

    .. faqref::
        :title: Fields in shapefiles

        The following codes is usually used to retrieve
        shapefiles:

        ::

            rshp = shapefile.Reader(filename)
            shapes = rshp.shapes()
            records = rshp.records()

        *records* contains metadata about each shape.
        Fields and values are not stored in a dictionary.
        Here is a snippet of code to do so:

        ::

            {k[0]: v for k, v in zip(rshp.fields[1:], records[0])}

        Here is an example of the results:

        ::

            {'ORD_PRE_DI': 'SW',
            'ORD_STNAME': 'SW 149TH ST',
            'ORD_STREET': '149TH',
            'ORD_STRE_1': 'ST',
            'ORD_SUF_DI': b'  ',
            'R_ADRS_FRO': 976,
            ...

    """
    import shapefile
    rshp = shapefile.Reader(filename, **kwargs)
    shapes = rshp.shapes()
    records = rshp.records()
    try:
        rshp.shp.close()
    except IOError:
        pass
    try:
        rshp.shx.close()
    except IOError:
        pass
    try:
        rshp.dbf.close()
    except IOError:
        pass
    return shapes, records, rshp.fields
