config-types
Type aliases and validators for configuration settings.
This package provides aliases for types typically found in configuration files. When the pydantic versions are used, they come with validators that transform the strings to their intended type (and value).
When the standard types are used, they all resolve to string and it's your job to transform them in your application code.
The rest of this document assumes usage with pydantic or
more specifically with
pydantic-settings.
Quick start
Install with: pip install config-types[pydantic]
Create your application settings:
from pydantic_settings import BaseSettings
from config_types.pydantic import IsTrue, DottedPathAttribute
class Config(BaseSettings):
debug: IsTrue = False
cache_backend: DottedPathAttribute
settings = Config()
Populate your environment, for example using a .env file:
DEBUG=yes
CACHE_BACKEND=django_redis.cache.RedisCache
Now import your settings singleton where needed.
Reference
DottedPath
A reference to a python module that is imported and returned if found.
Example:
from config_types.pydantic import DottedPath
from pydantic_settings import BaseSettings
class AppConfig(BaseSettings):
logging_module: DottedPath
# In `.env`:
# LOGGING_MODULE=loguru
ModuleAttributeRef
A reference to a module attribute, typically a class name, singleton or callable. The module path is a DottedPath and the attribute to be imported is separated by a colon.
Example:
from config_types.pydantic import ModuleAttributeRef
from pydantic_settings import BaseSettings
class AppConfig(BaseSettings):
asgi_application: ModuleAttributeRef
# In `.env`:
# ASGI_APPLICATiON=app.main:application
DottedPathAttribute
The same as a ModuleAttributeRef, but done with all dots. The last part is the entity reference.
Example:
from config_types.pydantic import DottedPathAttribute
from pydantic_settings import BaseSettings
class AppConfig(BaseSettings):
CACHE_BACKEND: DottedPathAttribute
# In `.env`:
# CACHED_BACKEND=django_redis.cache.RedisCache
IsTrue
A switch that defaults to false. The following values are recognised as true (case-insensitive):
- "yes"
- "on"
- "1"
- "true"
Example:
from config_types.pydantic import IsTrue
from pydantic_settings import BaseSettings
class AppConfig(BaseSettings):
debug: IsTrue = False
# In your development `.env`:
# DEBUG=yes
IsFalse
A switch that defaults to true. The following values are recognised as false (case-insensitive):
- "no"
- "off"
- "0"
- "false"
Example:
from config_types.pydantic import IsFalse
from pydantic_settings import BaseSettings
class AppConfig(BaseSettings):
use_https: IsFalse = True
# In your development `.env`:
# USE_HTTPS=off
RelativeUrlRef
A relative URL reference, in the strict sense. While the URL specs may
classify a URL starting with '/' as relative, this does not. It is meant to
be used as the final part of a URL, where the first part is different for
each environment. The classic case, is an asset reference part of static
resources, which is then prepended with the STATIC_URL.
The validator does not strip a leading slash, but throws an error, to prevent users from providing references to the root of the server, which a typical application does not allow.
Example:
from config_types.pydantic import RelativeUrlRef
from pydantic_settings import BaseSettings
class AppConfig(BaseSettings):
favicon: RelativeUrlRef = 'favicons/16x16.ico'
# In `.env`:
# FAVICON=branding/logo-32.png
TODO
The following are planned:
- containers
- support for other packages that can support a similar interface, if any
Note: numbers aren't planned as pydantic-settings (and typing) have plenty support for it.
Metadata
Release files for config-types 0.2.2
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 |
|---|---|---|---|---|
| config_types-0.2.2.tar.gz | 4.5 kB | Without provenance | Details for config_types-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| config_types-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for config_types-0.2.2-py3-none-any.whl |
Total release size: 10.4 kB
Release files / config_types-0.2.2.tar.gz
| Download URL | config_types-0.2.2.tar.gz |
|---|---|
| Size | 4.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a21919053b17392c286d207e9c546cb100903cfe676b4e33543629c09073465e
|
|
BLAKE2b-256 checksum How to use checksums |
fbe37808a5ef79fe0f13f7b96bc65b932c164466da34b55d3f9f176cd92fcb46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.19
|
Release files / config_types-0.2.2-py3-none-any.whl
| Download URL | config_types-0.2.2-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f6539d5b8b37048b5224053db0995a7ae74c0c9deb3bdbe4e0a4ebce1b22c7be
|
|
BLAKE2b-256 checksum How to use checksums |
3a704aed3bb84ddfbb6ae0ba7b23cd6a46bfe2937c9683c7f7bd2473e2b6f8aa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.8.19
|
Security for config-types 0.2.2
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.