Skip to main content

CircleCI codecov

GarlicConfig

GarlicConfig is a framework that makes it easy to deal with configurations in an easy yet flexible way. The core of this package is written in C++ and this Python package wraps the native code to provide an easy access to the configuration and some extra feature on top of it. The native library allows for quick retrieval of the configurations which can be used on any platform, this wrapper, however allows for defining advanced validation and config retrieval logic. For example, you could define your own conventions for getting localized version of configs.

The whole thing starts by defining the structure of your configs using models.

You can define models by inheriting from ConfigModel:

from garlicconfig import models

class DatabaseConfig(models.ConfigModel):
    pass

By adding attributes (or properties), you can define what this model recognizes and what format should each one of these attributes have.

For properties, you can use ConfigField. There are a set of built-in fields:

  • StringField
  • IntegerField
  • ArrayField
  • ModelField
  • BooleanField

You can also make your own custom ConfigModel and/or ConfigField.

for example:

from garlicconfig import fields
from garlicconfig.exceptions import ValidationError

class EvenIntegerField(IntegerField):

    def validate(self, value):
        if value % 2 != 0:
            raise ValidationError('bad integer')
    
    def to_model_value(self, value):
        return int(value)
        
    def to_garlic_value(self, value):
        return str(value)

The field class above stores str in the python dictionary representation. However, for the materialized config model, int is used. It also invalidates unaccepted values by raising ValidationError, in this case odd values.

Note that to_model_value is responsible for converting a basic type to a more complicated python type, perhaps constructing a Python-defined class.

to_garlic_value does the exact opposite, it should convert the value to a basic value. Basic value is defined to be one of the following types:

  • str
  • int
  • float
  • dict
  • set & list

This is primarily used for ease of encoding/decoding. By default, both of these methods return the given value without making any changes and I'd recommend not creating very complicated objects since it'll limit the accessibility of them in different platforms should you need to support them.

Next, you can define your own config model and use the custom ConfigField we just created.

for example:

class SomeRandomConfig(ConfigModel):

	value = EvenIntegerField(nullable=False, default=2)

You can use py_value method on config models to get a python dictionary with basic value types in it. This is handy to cache it in memory, or to use it for serialization.

from_dict will create a new config model from a python dictionary.

Furthermore, you can use garlic_value to construct a GarlicValue from the current config model and use from_garlic to construct a model from a GarlicValue.

GarlicValue is a type that keeps configuration objects in the native code and loads them in Python lazily. This allows you to lower memory usage while speeding up all operations. It also comes with a set of handy methods:

resolve

Allows for requested a specific value by providing a dot separated path.

for example:

class ParentConfig(models.ConfigModel):
    
    random_config_field = models.ModelField(SomeRandomConfig)


foo = ParentConfig()
foo.random_config_field.value = 8
garlic_value = foo.garlic_value()
print(garlic_value.resolve('random_config_field.value'))

In the above code, if value to the given path exists, the python representation of the value gets returned. Otherwise, None gets returned. This is helpful because you can simply give the path to the final value and get the requested value. Since all of this is happening in the native code, it's significantly faster to use GarlicValue over python dictionary or regular models.

Your goal should be to validate models using ConfigModel and store/read configurations using GarlicValue.

clone

Copy operations, specially deep copies in Python are very expensive. You can, however, clone GarlicValue instances much faster by using the native clone which copies the object without the need to use deep copy yet accomplish the same result.

for example:

garlic_value_1 = foo.garlic_value()
garlic_value_2 = foo.clone()

Serialization

You can use the following code to encode/decode configs. The default encoder is Json. However, you can write your own encoder and support other formats as needed.

from garlicconfig import encoding

config = DatabaseConfig()
serialized_string = encoding.encode(config, pretty=True)

Merging layers

You merge two configuration layers in order to support inheritance. Something that will come very handy if you plan to use localization or multi-layered configurations.

Any GarlicValue instance will have a apply method that will basically applies a second GarlicValue on top of itself.

for example:

from garlicconfig import models
from garlicconfig import fields


class ExtraConfig(models.ConfigModel):

    has_id = fields.BooleanField(default=False)
    has_degree = fields.BooleanField(default=False)


class DumbConfig(models.ConfigModel):

    name = fields.StringField(nullable=False)
    numbers = fields.ArrayField(IntegerField())
    extra = models.ModelField(ExtraConfig)
    
    def validate(self):
        super(DumbConfig, self).validate()
        if not self.name and not self.numbers:
            raise garlicconfig.exceptions.ValidationError('invalid config for some reason!')


config_1 = DumbConfig.from_dict({
    'name': 'Peyman',
    'numbers': [1, 2, 3]
    'extra': {
        'has_id': True
    }
}).garlic_value()

config_2 = DumbConfig.from_dict({
    'name': 'Patrick',
    'numbers': [4, 5, 6]
    'extra': {
        'has_degree': True
    }
}).garlic_value()

config_1.apply(config_2)
config_1.resolve('numbers')  # returns [4, 5, 6]
config_1.resolve('name')  # returns 'Patrick'
config_1.resolve('extra.has_id')  # returns True (from config_1)
config_1.resolve('extra.has_degree')  # returns True (from config_2)

Metadata

Release files for garlicconfig 1.4.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for garlicconfig 1.4.1
File Actions
garlicconfig-1.4.1-cp312-cp312-musllinux_1_2_x86_64.whl CPython 3.12 CPython 3.12 Linux musl 1.2+ x86-64 Details for garlicconfig-1.4.1-cp312-cp312-musllinux_1_2_x86_64.whl
garlicconfig-1.4.1-cp312-cp312-musllinux_1_2_aarch64.whl CPython 3.12 CPython 3.12 Linux musl 1.2+ ARM64 Details for garlicconfig-1.4.1-cp312-cp312-musllinux_1_2_aarch64.whl
garlicconfig-1.4.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details for garlicconfig-1.4.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
garlicconfig-1.4.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl CPython 3.12 CPython 3.12 Linux glibc 2.24+ ARM64, Linux glibc 2.28+ ARM64 Details for garlicconfig-1.4.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
garlicconfig-1.4.1-cp311-cp311-musllinux_1_2_x86_64.whl CPython 3.11 CPython 3.11 Linux musl 1.2+ x86-64 Details for garlicconfig-1.4.1-cp311-cp311-musllinux_1_2_x86_64.whl
garlicconfig-1.4.1-cp311-cp311-musllinux_1_2_aarch64.whl CPython 3.11 CPython 3.11 Linux musl 1.2+ ARM64 Details for garlicconfig-1.4.1-cp311-cp311-musllinux_1_2_aarch64.whl
garlicconfig-1.4.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details for garlicconfig-1.4.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
garlicconfig-1.4.1-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl CPython 3.11 CPython 3.11 Linux glibc 2.24+ ARM64, Linux glibc 2.28+ ARM64 Details for garlicconfig-1.4.1-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
garlicconfig-1.4.1-cp310-cp310-musllinux_1_2_x86_64.whl CPython 3.10 CPython 3.10 Linux musl 1.2+ x86-64 Details for garlicconfig-1.4.1-cp310-cp310-musllinux_1_2_x86_64.whl
garlicconfig-1.4.1-cp310-cp310-musllinux_1_2_aarch64.whl CPython 3.10 CPython 3.10 Linux musl 1.2+ ARM64 Details for garlicconfig-1.4.1-cp310-cp310-musllinux_1_2_aarch64.whl
garlicconfig-1.4.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details for garlicconfig-1.4.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
garlicconfig-1.4.1-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl CPython 3.10 CPython 3.10 Linux glibc 2.24+ ARM64, Linux glibc 2.28+ ARM64 Details for garlicconfig-1.4.1-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
garlicconfig-1.4.1-cp39-cp39-musllinux_1_2_x86_64.whl CPython 3.9 CPython 3.9 Linux musl 1.2+ x86-64 Details for garlicconfig-1.4.1-cp39-cp39-musllinux_1_2_x86_64.whl
garlicconfig-1.4.1-cp39-cp39-musllinux_1_2_aarch64.whl CPython 3.9 CPython 3.9 Linux musl 1.2+ ARM64 Details for garlicconfig-1.4.1-cp39-cp39-musllinux_1_2_aarch64.whl
garlicconfig-1.4.1-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details for garlicconfig-1.4.1-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
garlicconfig-1.4.1-cp39-cp39-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl CPython 3.9 CPython 3.9 Linux glibc 2.28+ ARM64, Linux glibc 2.24+ ARM64 Details for garlicconfig-1.4.1-cp39-cp39-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Total release size: 33.2 MB

Release files / garlicconfig-1.4.1-cp312-cp312-musllinux_1_2_x86_64.whl

Download URL garlicconfig-1.4.1-cp312-cp312-musllinux_1_2_x86_64.whl
Size 2.6 MB
Tags CPython 3.12 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
8cf7e897ce79c822f59a45cb6b63297350e13b79bacb585a99d4a235c014491a
BLAKE2b-256 checksum
How to use checksums
d83d54f4021cfca085b822e60b507313076bc7f2249bc5c0e6a1defdd2e0e7b3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.11

Release files / garlicconfig-1.4.1-cp312-cp312-musllinux_1_2_aarch64.whl

Download URL garlicconfig-1.4.1-cp312-cp312-musllinux_1_2_aarch64.whl
Size 2.6 MB
Tags CPython 3.12 Linux musl 1.2+ ARM64
SHA-256 checksum
How to use checksums
10ca222061ff3df953a2d68a118b9af981a95e49d083cc8708746c7bec7cc0b4
BLAKE2b-256 checksum
How to use checksums
e71ff6aa51f2d6a11d28eac9074c61885efb283573a7ea2870ee02953234e477
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.11

Release files / garlicconfig-1.4.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL garlicconfig-1.4.1-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 1.6 MB
Tags CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
8ad21d7f519b8721fc2e1bbe386db292d5211046c8c6454ab564813fc49452c2
BLAKE2b-256 checksum
How to use checksums
74ccbd575349e6be8aa13b6ffd96aafe859d9a0cd9df0f383b066423e1aeff98
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.11

Release files / garlicconfig-1.4.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Download URL garlicconfig-1.4.1-cp312-cp312-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 1.6 MB
Tags CPython 3.12 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
b665b759b24512b563d91f806a5f663bc706a0922bb28d8307adbffbe3f56779
BLAKE2b-256 checksum
How to use checksums
c5dd589ca3ab16781345e157ff47017776d0bbcbc214116149a9a6f363ca79b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.11

Release files / garlicconfig-1.4.1-cp311-cp311-musllinux_1_2_x86_64.whl

Download URL garlicconfig-1.4.1-cp311-cp311-musllinux_1_2_x86_64.whl
Size 2.6 MB
Tags CPython 3.11 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
77d45e1b8f563c5fe144bf46d1f5cf3d46d08cd445d8b2ac510c6ba09d908ed0
BLAKE2b-256 checksum
How to use checksums
fc2522b546a37196315b7fca52cb8b38b0e137b1af25cd06dea410faf5082bb2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.11.13

Release files / garlicconfig-1.4.1-cp311-cp311-musllinux_1_2_aarch64.whl

Download URL garlicconfig-1.4.1-cp311-cp311-musllinux_1_2_aarch64.whl
Size 2.5 MB
Tags CPython 3.11 Linux musl 1.2+ ARM64
SHA-256 checksum
How to use checksums
f67e367155109bea225caa6fadba60bd2c2641c5ac243e093c4a292bd6368fae
BLAKE2b-256 checksum
How to use checksums
97e036593a0f0d79680eeff1f63dd22fb48ee508dc9062c5c4186786f7f5db35
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.11.13

Release files / garlicconfig-1.4.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL garlicconfig-1.4.1-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 1.6 MB
Tags CPython 3.11 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
65bb0e73591a29a69f749fc48134cb379bac272e002c3ac699fc2b98f9046ec0
BLAKE2b-256 checksum
How to use checksums
ff5a1343677b5388fe9d62ac943bcbb0c4c12c3828f508bcc189fcccb5889747
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.11.13

Release files / garlicconfig-1.4.1-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Download URL garlicconfig-1.4.1-cp311-cp311-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 1.6 MB
Tags CPython 3.11 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
485add563dd1a67eddfb9ed48ddf96424939837da2eb549be5385eac99d0dc7c
BLAKE2b-256 checksum
How to use checksums
0e2c385313ba219f5c5d9636a5476b75ad82362de70b4dc347ed42ccaed975d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.11.13

Release files / garlicconfig-1.4.1-cp310-cp310-musllinux_1_2_x86_64.whl

Download URL garlicconfig-1.4.1-cp310-cp310-musllinux_1_2_x86_64.whl
Size 2.6 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
85e899d7fcc3c270177c3f018d8efa30b5b879c0d0bde803c245a72eb9f26c14
BLAKE2b-256 checksum
How to use checksums
8b0ed2b09ae35ab8be0d4107ab56aa201d8ef823b9a3c7acafb319ce9321d90b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.10.18

Release files / garlicconfig-1.4.1-cp310-cp310-musllinux_1_2_aarch64.whl

Download URL garlicconfig-1.4.1-cp310-cp310-musllinux_1_2_aarch64.whl
Size 2.5 MB
Tags CPython 3.10 Linux musl 1.2+ ARM64
SHA-256 checksum
How to use checksums
41da8d620d7d692f25762f8f632a1848d1a971618a1a0fa25ff3d75272e4dc08
BLAKE2b-256 checksum
How to use checksums
af5bd947a8e445ce1fb458e3bd877105430b3bf673f81332747129bcfdf9e4ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.10.18

Release files / garlicconfig-1.4.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL garlicconfig-1.4.1-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 1.6 MB
Tags CPython 3.10 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
17e5a272ecf4d3929661c3218efb493b0c53ebb4ec24b31f3c985d2831076984
BLAKE2b-256 checksum
How to use checksums
c9bcedda91a4fb303d5e6f8982f35608112f6dd1477fb227390194ec4a3b690e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.10.18

Release files / garlicconfig-1.4.1-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Download URL garlicconfig-1.4.1-cp310-cp310-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 1.5 MB
Tags CPython 3.10 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
c17e191ca03d71269a22544b889a372517ba9bbef49b43242c754f16138096d4
BLAKE2b-256 checksum
How to use checksums
e30725bbe785d7d97339d1b87a04586a7a2d54f479e15a7c8f80c17d6698e0f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.10.18

Release files / garlicconfig-1.4.1-cp39-cp39-musllinux_1_2_x86_64.whl

Download URL garlicconfig-1.4.1-cp39-cp39-musllinux_1_2_x86_64.whl
Size 2.6 MB
Tags CPython 3.9 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
27089eafcbb06bdade4dee2061a471e3509f025d0a4e704903515312f6cdbbc3
BLAKE2b-256 checksum
How to use checksums
ada37a4d9dc7e348a924c07f2092692085da9718b3a8dd32a2216509529653eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / garlicconfig-1.4.1-cp39-cp39-musllinux_1_2_aarch64.whl

Download URL garlicconfig-1.4.1-cp39-cp39-musllinux_1_2_aarch64.whl
Size 2.5 MB
Tags CPython 3.9 Linux musl 1.2+ ARM64
SHA-256 checksum
How to use checksums
f6442dbef1f1991ed7046071db831c53fa1761cd5f8c822541053cdbb95d2f51
BLAKE2b-256 checksum
How to use checksums
d08752c1449e47d1cb29d6e21f39bd6ff1e1261f9e3600c95ad3db9e43af6803
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / garlicconfig-1.4.1-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL garlicconfig-1.4.1-cp39-cp39-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 1.6 MB
Tags CPython 3.9 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
fdec8b0c69e4733a56bc1cec02e473b605838e20ec8dbe56a751115e6635b194
BLAKE2b-256 checksum
How to use checksums
59e6b01ae7c3abf8c9abbb8f60a9f14ed35db267944f4c4ed8003341e17fcf4a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.9.23

Release files / garlicconfig-1.4.1-cp39-cp39-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl

Download URL garlicconfig-1.4.1-cp39-cp39-manylinux_2_24_aarch64.manylinux_2_28_aarch64.whl
Size 1.6 MB
Tags CPython 3.9 Linux glibc 2.24+ ARM64 Linux glibc 2.28+ ARM64
SHA-256 checksum
How to use checksums
0c80fd367eb9eff8c72c8ff700121e2b612ac879c1ae1e5d3ebec45c3d1cfd23
BLAKE2b-256 checksum
How to use checksums
4b3115e882b342d85d32caffebb24af3fd64063e8896c5c785a925f3bbfa1668
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.9.23

Security for garlicconfig 1.4.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page