ResourceCollection

class xbrl_filings_api.ResourceCollection

Bases: object

Collection of subresources of a FilingSet object.

The subresources are all other APIResource subclasses except Filing objects.

This object may be iterated over, it defines len() as well as operator in. It may not, however, be accessed with an indexer (e.g. object[index]) or reversed.

This collection is a view to the non-Filing resources of the parent FilingSet, backreferenced in attribute filingset.

Entity and ValidationMessage objects, as subclasses of APIResource, have a custom __hash__() method and their hash is based on a tuple of strings 'APIResource', class attribute TYPE, and object api_id. This means that equality checks (==) and related methods are based on this tuple. For example, when the actual entity object is not available, a fast way to check if an entity with api_id '123' is included in the filing set fs is:

('APIResource', Entity.TYPE, '123') in fs.entities

Methods

get_pandas_data([attr_names, ...])

Get resources as data for pandas.DataFrame constructor.

__hash__()

Return hash(self).

__repr__()

Return repr with item_class and len(self).

__str__()

Return str(self).

Attributes

columns

List of available columns for resources of this type.

exist

True if any resources of this type exist.

filingset

Reference to the parent FilingSet object.

item_class

Type object of the items within.

filingset: FilingSet

Reference to the parent FilingSet object.

item_class: type[APIResource]

Type object of the items within.

property columns: list[str]

List of available columns for resources of this type.

property exist: bool

True if any resources of this type exist.

This property is faster than len(obj) != 0.

get_pandas_data(attr_names=None, *, strip_timezone=True, date_as_datetime=True, include_urls=False)

Get resources as data for pandas.DataFrame constructor.

For example, a new dataframe can be instantiated for entities as follows:

import pandas as pd
df = pd.DataFrame(data=filingset.entities.get_pandas_data())

If parameter attr_names is not given, most data attributes will be extracted.

Parameters:
  • attr_names (iterable of str, optional) – Valid attribute names of resource object.

  • strip_timezone (bool, default True) – Strip timezone information (always UTC) from datetime values.

  • date_as_datetime (bool, default True) – Convert date values to naive datetime to be converted to pandas.datetime64 by pandas.

  • include_urls (bool, default False) – When parameter attr_names is not given, include attributes ending _url.

Returns:

data – Column names are the same as the attributes for resource of this type.

Return type:

dict of {str: list of DataAttributeType}

See also

FilingSet.get_pandas_data

For Filing resources.

__contains__(elem)

Return True if ResourceCollection contains elem.

Parameters:

elem (Any)

Return type:

bool

__iter__()

Iterate ResourceCollection.

Return type:

Iterator[APIResource]

__len__()

Return length of ResourceCollection.

Return type:

int

__repr__()

Return repr with item_class and len(self).

Return type:

str