5. Config¶
The EasyData config allows you to customize the behaviour of all EasyData components, including the parsers, processors and models themselves.
The infrastructure of the config provides a global namespace of key-value mappings that the code can use to pull configuration values from. The config attributes can be populated through different mechanisms, which are described below.
For a list of available built-in config variables see: Built-in config reference.
5.1. Populating config¶
The Config can be populated using different mechanisms, each of which having a different precedence. Here is a list of them in decreasing order of precedence:
Config per model (highest precedence)
Project config module
Default global settings (least precedence)
These mechanisms are described in more detail below.
Note
All custom config variables must start with ED_
, otherwise they wont be
recognized by the config loader.
5.1.1. Config per model¶
Models can define it’s own config attributes that will take precedence and override the project or global one. They can do so by defining the config key and value through a class attribute:
class ProductItemModel(ItemModel):
ED_LANGUAGE = 'fr'
ED_DATETIME_FORMAT = ''%d.%m.%Y %H:%M:%S'
...
5.1.2. Project config module¶
Global config can be overridden by creating your own config module. Then you need to
tell path to your config module by using an environment variable, ED_CONFIG_PATH
.
The value of ED_CONFIG_PATH
should be in Python path syntax, e.g. myproject.config
.
Note that the config module should be on the Python
import search path.
Note
The design decision that all config variables start with ED_
is due to possibility
to use config or settings module from a different framework, e.g. scrapy
and to prevent any name conflicts.
5.1.3. Default global config¶
The global defaults are located in the easydata.config.default
module and
documented in the Built-in config reference section.
5.2. Rationale for config names¶
Config names are usually prefixed with the component that they configure. For
example, proper config names for a date time parsers would be ED_URL_DOMAIN
,
ED_URL_PROTOCOL
, etc.
5.3. Accessing config¶
Via easydata.utils.config
:
from easydata.utils import config
>>> config.get('ED_LANGUAGE')
'en'
Examples above will return default config values or if they are overwritten or newly added via Project config module
Or via config
property in a parser
, model
or processor
components.
Through the config
property in a component, we will get any config value that was defined or
overwritten in a model
.
5.4. Built-in config reference¶
Here’s a list of all available EasyData
config names, along with their default values
and the scope where they apply.
The scope, where available, shows where the config is being used and if it’s tied to any particular component. In that case the module of that component will be shown, typically a parser or a processor. It also means that the component must be used in order for the config to have any effect.
5.4.1. Default config variables:¶
ED_LANGUAGE¶
Default: 'en'
ED_DATETIME_FORMAT¶
Default: '%m/%d/%Y %H:%M:%S'
ED_DATE_FORMAT¶
Default: '%m/%d/%Y'
ED_TIME_FORMAT¶
Default: '%H:%M:%S'
ED_DATETIME_FORMATS¶
Default: None
ED_DATETIME_LANGUAGE¶
Default: None
ED_DATETIME_LOCALES¶
Default: None
ED_DATETIME_REGION¶
Default: None
ED_URL_DOMAIN¶
Default: None
ED_URL_PROTOCOL¶
Default: 'https'
ED_PRICE_DECIMALS¶
Default: 2
ED_ITEM_DISCOUNT_ITEM_PRICE_KEY¶
Default: 'price'
ED_ITEM_DISCOUNT_ITEM_SALE_PRICE_KEY¶
Default: 'sale_price'
ED_ITEM_DISCOUNT_ITEM_DISCOUNT_KEY¶
Default: 'discount'
ED_ITEM_DISCOUNT_DECIMALS¶
Default: 2
ED_ITEM_DISCOUNT_NO_DECIMALS¶
Default: False
ED_ITEM_DISCOUNT_REMOVE_ITEM_SALE_PRICE_KEY¶
Default: False
ED_DATA_VARIANTS_NAME¶
Default: variants
ED_DATA_VARIANTS_KEY_NAME¶
Default: variants_key
ED_DATA_VARIANT_NAME¶
Default: variant