Skip to content

Commit

Permalink
docs(examples): started on providing more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
robinvandernoord committed Jun 14, 2023
1 parent 6ba4bf2 commit ca84ecb
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 9 deletions.
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ pip install configuraptor
Configuraptor can be used to load your config files into structured Python classes.

```toml
# example_from_docs.toml
# examples/example_from_readme.toml
[config]
name = "Hello World!"

Expand All @@ -56,10 +56,12 @@ string = "42"
```

Could be loaded into Python classes using the following code:

```python
# example_from_docs.py
# examples/example_from_readme.py
from configuraptor import load_into, TypedConfig


######################
# with basic classes #
######################
Expand All @@ -76,7 +78,7 @@ class Config:


if __name__ == '__main__':
my_config = load_into(Config, "example_from_docs.toml") # or .json, .yaml
my_config = load_into(Config, "example_from_readme.toml") # or .json, .yaml

print(my_config.name)
# Hello World!
Expand All @@ -100,15 +102,15 @@ class OtherConfig(TypedConfig):


if __name__ == '__main__':
my_config = OtherConfig.load("example_from_docs.toml") # or .json, .yaml
my_config = OtherConfig.load("example_from_readme.toml") # or .json, .yaml

print(my_config.name)
# Hello World!
print(my_config.reference.numbers)
# [41, 43]
```

More examples will be available soon.
More examples can be round in [examples](https://github.com/trialandsuccess/configuraptor/blob/master/examples).

## License

Expand Down
2 changes: 1 addition & 1 deletion examples/dataclass.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from dataclasses import dataclass

from typedconfig import load_into
from configuraptor import load_into


@dataclass
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class Config:


if __name__ == '__main__':
my_config = load_into(Config, "example_from_docs.json")
my_config = load_into(Config, "example_from_readme.json")

print(my_config.name)
# Hello World!
Expand All @@ -40,7 +40,7 @@ class OtherConfig(TypedConfig):


if __name__ == '__main__':
my_config = OtherConfig.load("example_from_docs.json")
my_config = OtherConfig.load("example_from_readme.json")

print(my_config.name)
# Hello World!
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion examples/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Example with basic classes
"""

from typedconfig import load_into
from configuraptor import load_into


class AbsHasName:
Expand Down
13 changes: 13 additions & 0 deletions examples/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Examples

## Basic

## Dataclasses

## Inheriting from TypedConfig

## Classes with `init`

## Existing Instances

## Singletons

0 comments on commit ca84ecb

Please sign in to comment.