This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Reason given by maintainers: Not maintaned. Consider use https://pypi.org/project/pydantic-settings/
pysettings
Pysettings is a Python package to store your application settings. Compared to some settings managers, this package has been inspired by Django Rest Frameworks validators where you can validate the user input beforehand.
That simplifies your code because settings don't need to be validated in your application logic. Available features are:
- Store your application settings without using global objects.
- Extend your settings using a
BaseSettingsclass. The resulting class can be validated using asettings.is_valid()method. - Fields are represented with an
Optionfield that takesvalidatorsas parameter. It's possible to set adefaultvalue if the option is not set by users. - Out of the box validators:
not_null,is_https_url. - It's possible to add custom validators as functions.
Requirements
- Python 3.7+
Getting Started
pysettings is available on PyPI:
$ pip install pysettings-validator
Create your Settings
from pysettings.base import BaseSettings
from pysettings.options import Option
from pysettings.validators import is_https_url
# Class definition
class Settings(BaseSettings):
url = Option(validators=[is_https_url])
description = Option()
# Use settings in your application
settings = Settings()
settings.url = "https://example.com"
settings.description = "A shiny Website!"
settings.is_valid() # returns (True, [])
Settings API
settings instance doesn't allow to set attributes not defined as Option. If you
try to set a setting that is not defined, a OptionNotAvailable exception is raised:
class Settings(BaseSettings):
description = Option()
# Use settings in your application
settings = Settings()
settings.url = "https://example.com" # raise `OptionNotAvailable`
is_valid() exposes a raise_exception=True kwarg in case you prefer to not raise
exceptions in your code:
class Settings(BaseSettings):
url = Option(validators=[is_https_url])
# Use settings in your application
settings = Settings()
settings.url = "http://example.com"
settings.is_valid() # raise ConfigNotValid exception
settings.is_valid(raise_exception=False) # return (False, [{'url': [{'is_https_url': 'The schema must be HTTPS'}]}])
Create a Custom Validator
# app/validators.py
from pysettings.exceptions import ValidationError
def is_a_boolean(value):
if isinstance(value, bool):
return True
else:
raise ValidationError("The value must a Boolean")
# app/settings.py
from .validators import is_a_boolean
class Settings(BaseSettings):
dry_run = Option(validators=[is_a_boolean])
description = Option()
# app/main.py
settings = Settings()
settings.dry_run = "Yes"
settings.description = "Dry run mode!"
settings.is_valid() # raises ConfigNotValid exception
Test your Settings (pytest)
If you need to change some of your settings during tests, you can use the following snippet to restore the previous settings after each test:
# tests/conftest.py
from app.config import settings as app_settings # Import your global settings
from pysettings.test import SettingsWrapper # Import settings wrapper
@pytest.fixture(scope="function")
def settings():
wrapper = SettingsWrapper(app_settings)
# (Optional) Include test overrides
wrapper.DATABASE_URL = "sqlite://"
yield wrapper
# Restore original settings
wrapper.finalize()
# tests/test_settings.py
def test_settings(settings):
# Change settings for this test only
settings.BATCH_SIZE = 100
# ... Test your code ...
Development
We accept external contributions even though the project is mostly designed for personal needs. If you think some parts can be exposed with a more generic interface, feel free to open a GitHub issue and to discuss your suggestion.
Coding Guidelines
We use flake8 as a style guide enforcement. That said, we also use black to
reformat our code, keeping a well defined style even for quotes, multi-lines blocks and other.
Before submitting your code, be sure to launch black to reformat your PR.
Testing
tox is used to execute the following test matrix:
lint: launchesflake8andblack --checkto be sure the code honors our style guidelinepy{3.7,3.8,3.9,3.10,3.11}: launchespy.testto execute tests with different Python versions.
To launch the full test matrix, just:
$ tox
Metadata
Release files for pysettings-validator 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pysettings-validator-0.4.0.tar.gz | 11.9 kB | Without provenance | Details for pysettings-validator-0.4.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pysettings_validator-0.4.0-py3-none-any.whl | Python 3 | none | any | Details for pysettings_validator-0.4.0-py3-none-any.whl |
Total release size: 20.8 kB
Release files / pysettings-validator-0.4.0.tar.gz
| Download URL | pysettings-validator-0.4.0.tar.gz |
|---|---|
| Size | 11.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
00602a25c36fe5be2dd30f96ee7ac7f9a4d09453aca2e2ae9d1f292d51427938
|
|
BLAKE2b-256 checksum How to use checksums |
63a7b21a910c15e9c0296d01283d5520d1f544519a83ce1e2e345126a57e5639
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Release files / pysettings_validator-0.4.0-py3-none-any.whl
| Download URL | pysettings_validator-0.4.0-py3-none-any.whl |
|---|---|
| Size | 8.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1b20dd0f1e306f3215332450dd454d0fd4bf9e0878ddd71e0240766cc4d90bff
|
|
BLAKE2b-256 checksum How to use checksums |
6c16c81af0c8c8000ab687cda5c90ea324a155bfd54822625e75d4a583d3b717
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.3
|
Security for pysettings-validator 0.4.0
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.