Skip to content

Commit

Permalink
Merge pull request #10 from jordantshaw/rc-0.2.0
Browse files Browse the repository at this point in the history
RC-0.2.0
  • Loading branch information
jordantshaw committed Jul 19, 2023
2 parents 63c3a34 + 76c9cfa commit 3621621
Show file tree
Hide file tree
Showing 9 changed files with 310 additions and 148 deletions.
45 changes: 31 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ Support for Pydantic settings configuration file loading
## Installation
`pip install pydantic-config`

### Optional Dependencies

Pydantic-Config has the following optional dependencies:
- yaml - `pip install pydantic-config[yaml]`
- toml - `pip install pydantic-config[toml]`

You can install all the optional dependencies with `pip install pydantic-config[all]`

## Usage

```toml
Expand All @@ -13,17 +21,18 @@ description = "Test application description"
```

```python
from pydantic_config import SettingsModel
from pydantic_config import SettingsModel, SettingsConfig


class Settings(SettingsModel):
app_id: str = 1
app_name: str = None
description: str = None
log_level: str = 'INFO'

class Config:
config_file = 'config.toml'

model_config = SettingsConfig(
config_file='config.toml',
)


settings = Settings()
Expand Down Expand Up @@ -53,24 +62,31 @@ description = "Test application description"
```

```python
from pydantic_config import SettingsModel
from pydantic_config import SettingsModel, SettingsConfig


class Settings(SettingsModel):
app_id: str = 1
app_name: str = 'App Name'
description: str = None
log_level: str = 'INFO'

class Config:
config_file = ['config.toml', 'config.json'] # The config.json file will take priority over config.toml

model_config = SettingsConfig(
config_file=['config.toml', 'config.json'] # The config.json file will take priority over config.toml
)

settings = Settings()
print(settings)
# app_id='1' app_name='Python Application' description='Description from JSON file' log_level='WARNING'
```

## Supported file formats
Currently, the following file formats are supported:
- `.yaml` _Requires `pyyaml` package_
- `.toml` _Requires `toml` package_
- `.json`
- `.ini`


## Merging
If your configurations have existing `list` or `dict` variables the contents will be merged by default. To disable
Expand All @@ -91,15 +107,16 @@ item2 = "value2"
```

```python
from pydantic_config import SettingsModel
from pydantic_config import SettingsModel, SettingsConfig


class Settings(SettingsModel):
foo: dict = {}

class Config:
config_file = ['config.toml', 'config2.toml']
config_merge: bool = True

model_config = SettingsConfig(
config_file=['config.toml', 'config2.toml'],
config_merge= True,
)


settings = Settings()
Expand Down
2 changes: 1 addition & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ channels:
- defaults
dependencies:
- python=3.10
- pydantic<2.0.0, >=1.10.0
- pydantic-settings>=2.0.1
- toml=0.10.2
- python-dotenv=0.21.0
- pyyaml=6.0
35 changes: 26 additions & 9 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"
[project]
name = "pydantic-config"
description = "Support for Pydantic settings configuration file loading"
version = "0.1.2"
version = "0.2.0"
authors = [{name="Jordan Shaw"}]
readme = "README.md"
requires-python = ">=3.7"
Expand All @@ -19,24 +19,41 @@ classifiers = [
]

dependencies = [
'pydantic<2.0.0, >=1.10.0',
'pyyaml>=6.0',
'python-dotenv>=0.21.0',
'toml>=0.10.2'
'pydantic-settings>=2.0.2',

]

[project.optional-dependencies]
yaml = [
"pyyaml>=5.1"
]
toml = [
'toml>=0.10.0'
]
all = [
'pyyaml>=5.1',
'toml>=0.10.0'
]
dev = [
"pytest", 'twine', 'build'
'pytest',
'twine',
'build',
'pyyaml>=5.1',
'python-dotenv>=0.15.0',
'toml>=0.10.0'
]
test = [
"pytest"
'pytest',
'pyyaml==5.1',
'python-dotenv>=0.15.0',
'toml>=0.10.0'
]

[project.urls]
"Homepage" = "https://github.com/jordantshaw/pydantic-config"

[tool.pytest.ini_options]
addopts = [
"--import-mode=importlib",
pythonpath = [
"src"
]

2 changes: 1 addition & 1 deletion src/pydantic_config/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .main import SettingsModel
from .main import SettingsModel, SettingsConfig
Loading

0 comments on commit 3621621

Please sign in to comment.