Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7efaa2f
commit 3fc4e4e
Showing
3 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# output-json | ||
import os | ||
from typing import List | ||
|
||
from pydantic import BaseSettings, Field | ||
|
||
|
||
def parse_list(s: str) -> List[int]: | ||
return [int(x.strip()) for x in s.split(",")] | ||
|
||
|
||
class Settings(BaseSettings): | ||
numbers: List[int] = Field(env_parse=parse_list) | ||
|
||
|
||
os.environ["numbers"] = "1,2,3" | ||
print(Settings().dict()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# output-json | ||
import os | ||
from typing import List | ||
|
||
from pydantic import BaseSettings, Field, validator | ||
|
||
|
||
class Settings(BaseSettings): | ||
numbers: List[int] = Field(env_parse=str) | ||
|
||
@validator("numbers", pre=True) | ||
def validate_numbers(cls, s): | ||
return [int(x.strip()) for x in s.split(",")] | ||
|
||
|
||
os.environ["numbers"] = "1,2,3" | ||
print(Settings().dict()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters