https://github.com/samuelmarks/py-typed-settings
Generate typed settings.py from settings.yaml in Python 2, 3
https://github.com/samuelmarks/py-typed-settings
Last synced: 2 months ago
JSON representation
Generate typed settings.py from settings.yaml in Python 2, 3
- Host: GitHub
- URL: https://github.com/samuelmarks/py-typed-settings
- Owner: SamuelMarks
- License: apache-2.0
- Created: 2022-09-13T21:16:25.000Z (almost 4 years ago)
- Default Branch: master
- Last Pushed: 2022-09-21T02:40:08.000Z (almost 4 years ago)
- Last Synced: 2025-03-23T01:28:03.672Z (over 1 year ago)
- Language: Python
- Size: 48.8 KB
- Stars: 0
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE
Awesome Lists containing this project
README
py_typed_settings
=================

[](https://opensource.org/licenses/Apache-2.0)
Generate typed settings.py from settings.yaml in Python 2, 3.
Useful for fully type-safe settings, with code-completion. E.g., `import settings; print(settings.AWS.bucket.value)`
## Command-line usage
```shell
$ python -m py_typed_settings --help
usage: py_typed_settings [-h] [--version] -i INPUT_YAML -o OUTPUT_PY
[-n NAMESPACE]
Generate typed settings.py from settings.yaml in Python 2, 3
options:
-h, --help show this help message and exit
--version show program's version number and exit
-i INPUT_YAML, --input-yaml INPUT_YAML
settings.yaml (input) filepath
-o OUTPUT_PY, --output-py OUTPUT_PY
settings.py (output) filepath
-n NAMESPACE, --namespace NAMESPACE
Environment variable to change `tier`
```
### Example
```shell
python -m py_typed_settings -i py_typed_settings/_data/settings.yaml -o py_typed_settings/settings_gen.py
```
## Example YAML input
```yaml
constants:
- name: cors_origin
dev:
origins:
- 'http://localhost:8080'
- '*'
remote-dev:
origins:
- 'https://api-dev.example.com'
prod:
origins:
- 'https://api.example.com'
providers:
- provider: aws
dev:
bucket:
value: bucket-dev
remote-dev:
bucket:
value: bucket-dev
prod:
bucket:
value: bucket-prod
```
## Example output (Python 2.7)
```python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# GENERATED! Do not manually edit. Modify 'settings.yaml' instead (then run `./settings_schema_gen.py`)
# (different tiers can be targeted with this script by setting the `TIER` env var; defaults to 'dev')
from typing import List, Tuple, Union
#############
# Providers #
#############
class AWS(object):
class bucket(object):
value = 'bucket-dev' # type: str
#############
# Constants #
#############
class CORS_ORIGIN(object):
origins = 'http://localhost:8080', '*' # type: Tuple[str]
__all__ = ['AWS', 'CORS_ORIGIN'] # type: List[str]
```
## Example output (Python 3)
```python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# GENERATED! Do not manually edit. Modify 'settings.yaml' instead (then run `./settings_schema_gen.py`)
# (different tiers can be targeted with this script by setting the `TIER` env var; defaults to 'dev')
from typing import List, Tuple, Union
#############
# Providers #
#############
class AWS(object):
class bucket(object):
value: str = 'bucket-dev'
#############
# Constants #
#############
class CORS_ORIGIN(object):
origins: Tuple[str] = ('http://localhost:8080', '*')
__all__: List[str] = ['AWS', 'CORS_ORIGIN']
```
## Developer
### Install dependencies
python -m pip install -r requirements.txt
### Install package
python -m pip install .
## End user
python -m pip install https://api.github.com/repos/SamuelMarks/py-typed-settings/zipball#egg=py_typed_settings
---
## License
Licensed under either of
- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or )
- MIT license ([LICENSE-MIT](LICENSE-MIT) or )
at your option.
### Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.