[Core Package] A simple high-level framework for research
Project description
Cinnamon (Core Package)
Cinnamon is a simple framework for general-purpose configuration and code logic de-coupling. It was developed to offer two main functionalities:
De-coupling a code logic from its regulating parameters
Re-use of code logic without effort
Documentation
Check the online documentation of cinnamon-core for more information.
Check also the central cinnamon documentation to overview all cinnamon packages!
Background
Consider a code logic that has to load some data.
class DataLoader:
def load(...):
data = read_from_file(folder_name=self.folder_name)
return data
The data loader reads from a file located according to self.folder_name
's value.
If self.folder_name
has multiple values, we can use the same code logic to load data from different folders.
Hypothetically, we would define multiple data loaders:
data_loader_1 = DataLoader(folder_name='*folder_name1*')
data_loader_2 = DataLoader(folder_name='*folder_name2*')
...
Now, if the data loader code block is used in a project, we require some code modularity to avoid defining several versions of the same script. One common solution is to rely on configuration files (e.g., JSON file).
{
'data_loader' : {
'folder_name': '*folder_name1*'
}
}
The main script is modified to load our configuration file so that each code logic is properly initialized.
Cinnamon
Well, cinnamon keeps this <configuration, code logic> dichotomy where a configuration is written in plain Python code!
class DataLoaderConfig(Configuration):
@classmethod
def get_default(cls):
config = super().get_default()
config.add(name='folder_name',
type_hint=str,
is_required=True,
variants=['*folder_name1*', '*folder_name2*', ...],
description="Base folder name from which to look for data files.")
return config
Cinnamon allows high-level configuration definition (constraints, type-checking, description, variants, etc...)
To quickly load any instance of our data loader code logic, we
register the configuration via a registration key
key = RegistrationKey(name='data_loader', namespace='showcase')
Registry.add_configuration_variants_from_key(config_class=DataLoaderConfig,
key=key)
bind
the configuration to its code logic: DataLoaderConfig
--> DataLoader
Registry.bind(config_class=DataLoaderConfig,
component_class=DataLoader,
key=key)
build
the DataLoader
code logic with a specific configuration instance via the used registration key
variant_key = RegistrationKey(name='data_loader', tags={'folder_name=*folder_name1*'}, namespace='showcase')
data_loader = Registry.build_component(key=variant_key)
That's it! This is all of you need to use cinnamon.
Features
General-purpose
cinnamon
is meant to simplify your code organization for better re-use.
Simple
cinnamon
is a small library that acts as a high-level wrapper for your projects.
Modular
cinnamon
is shipped in several small packages to meet different requirements.
Community-based
the Component
and Configuration
you define can be imported from/exported to other users and project!
Flexible
cinnamon
imposes minimal APIs for a quick learning curve.
You are still free to code as you like!
Install
pip
pip install cinnamon-core
git
git clone https://github.com/federicoruggeri/cinnamon_core
Contribute
Want to contribute with new Component
and Configuration
?
Feel free to submit a merge request!
Cinnamon is meant to be a community project :)
Contact
Don't hesitate to contact:
- Federico Ruggeri @ federico.ruggeri6@unibo.it
for questions/doubts/issues!
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file cinnamon_core-0.2.2.tar.gz
.
File metadata
- Download URL: cinnamon_core-0.2.2.tar.gz
- Upload date:
- Size: 29.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 colorama/0.4.4 importlib-metadata/4.6.4 keyring/23.5.0 pkginfo/1.8.2 readme-renderer/34.0 requests-toolbelt/0.9.1 requests/2.25.1 rfc3986/1.5.0 tqdm/4.57.0 urllib3/1.26.5 CPython/3.10.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5a397018854fef144a8bf2f9cfbb5b9b08952031b3fad1a63345328e79e813f |
|
MD5 | 23bb081b94c30a729427867fd4080b15 |
|
BLAKE2b-256 | 7684f6c3bcc131b51033f78f77da8989b6a15e8d78f05bcb2a6a987908dbdfae |