Store parameters in easy to access files, and access backend data


This module is at the core of pywws. By default it stores data on disc, using a backend module which uses text files (see pywws.filedata) but other plugin backend modules can be used to use alternative means. These modules must adopt the same API (Class names and methods) as pywws.filedata so as to be transparent to the rest of pywws.

From a “user” point of view, the data is accessed as a cross between a list and a dictionary. Each data record is indexed by a datetime.datetime object (dictionary behaviour), but records are stored in order and can be accessed as slices (list behaviour).

For example, to access the hourly data for Christmas day 2009, one might do the following:

from datetime import datetime
datastore ='weather_data', False)
hourly = datastore.hourly_data
for data in hourly[datetime(2009, 12, 25):datetime(2009, 12, 26)]:
    print(data['idx'], data['temp_out'])

Some more examples of data access:

# get value nearest 9:30 on Christmas day 2008
data[data.nearest(datetime(2008, 12, 25, 9, 30))]
# get entire array, equivalent to data[:]
# get last 12 hours worth of data
data[datetime.utcnow() - timedelta(hours=12):]

Note that the datetime.datetime index is in UTC. You may need to apply an offset to convert to local time.

See pywws.filedata for more details on the underlying data store API.

Detailed API


pywws_context(data_dir[, live_logging])


ParamStore(root_dir, file_name)
PywwsContext(data_dir, live_logging)
class, file_name)[source]

Bases: object

get(section, option, default=None)[source]

Get a parameter value and return a string.

If default is specified and section or option are not defined in the file, they are created and set to default, which is then the return value.

get_datetime(section, option, default=None)[source]
set(section, option, value)[source]

Set option in section to string value.

unset(section, option)[source]

Remove option from section.

class, live_logging)[source]

Bases: object

flush()[source], live_logging=False)[source]

Comments or questions? Please subscribe to the pywws mailing list and let us know.