Compression Configuration
cshelve supports compression to reduce the size of stored data. This is particularly useful when working with large datasets or to reduce network time. The compression algorithm can be configured using the options provided in the configuration.
Example Configuration
Section titled “Example Configuration”[default]provider = in-memoryalgorithm = zlib
[compression]algorithm = zliblevel = 1
In this example, the algorithm
is set to zlib
, and the compression level is set to 1
.
Supported Algorithms
Section titled “Supported Algorithms”Supported compression algorithms include:
zlib
: Uses thezlib
library for compression.
Usage Example
Section titled “Usage Example”cshelve supports compression transparently; the compression settings don’t require changes to the application code:
import cshelve
with cshelve.open('config.ini') as db: db['data'] = 'This is some data that will be compressed.'
with cshelve.open('config.ini') as db: data = db['data']
Error Handling
Section titled “Error Handling”If the specified compression algorithm isn’t supported, cshelve raises an UnknownCompressionAlgorithmError
. Ensure the chosen algorithm is correctly specified in the configuration.