Schema Class/ Object

Accern Python Library allows user to filter and select Accern data in 3 different ways: REST API, streaming and historical data request. schema object is used in these three methods to convey user’s idea of how to slice data.

Schema class here will provide some help functions and validate functions to help user build a right one.

Get Fields

Get available fields in the data.

from accern import Schema
print Schema.get_fields()

Get field options

For field type and available options.

Schema.get_options('event_group')

Build your schema

schema = {
    'select': [
        {
            'field': 'entity_ticker',
            'alias': 'ticker'
        }
    ],
    'filters': {
        'entity_sentiment': [
            [70, 100],
            [-100, -70]
        ]
    }
}

Validate schema

After drafting a schema, validate it along with the method you want to use.

Schema.validate_schema(method='api', schema=schema)

Select and add alias

To select only a few fields or rename the fields, pass the alias of the fields you want to schema.

schema = {
    'select': [
        {
            'field': 'entity_ticker',
            'alias': 'ticker'
        }
    ]
}

response = Client.request(schema)

The alias for the selected fields is optional and you can select multiple fields.

schema = {
    'select': [
        {
            'field': 'entity_ticker',
            'alias': 'ticker'
        }, {
            'field': 'harvested_at'
        }
    ]
}

response = Client.request(schema)

If you want to filter the data, here is a list of available fields to filter by:

Parameter Description
entity_competitors A list of ticker symbols of entity’s competitors.
entity_country The parent country of the entity.
entity_industry The industry in which the entity is listed.
entity_region The region where the entity is traded.
entity_sector The sector that the entity belongs to.
entity_ticker The traded ticker symbols of the extracted entity.
entity_type The type of entity, such as public equity, commodity, cryptocurrency, etc.
event Financial events extracted from the stories.
event_group The broader financial events category.
from The eariliest timestamp allowed in the returned data.
last_id The last id before the return data.
story_type Where the stories are published and their mode of access.
story_group_exposure The level of exposure for stories within a story group.

For the full list and available values, you can use the helper function menthioned above.

Pass the filters to schema. The value can be a single value or an array of values.

schema = {
    'filters': {
        'entity_industry': ['Apparel', 'Food Chains'],
        'event': 'Accident'
    }
}

response = Client.request(schema)

A list of filter examples is available at Cookbook