Skip to content

Commit

Permalink
Update README.md and bump version
Browse files Browse the repository at this point in the history
Remove expired domain from the examples

Fix precommit
  • Loading branch information
isik-kaplan committed Mar 16, 2023
1 parent 591d695 commit c3d3d7f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v3.2.0
rev: v4.4.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace

- repo: https://github.com/psf/black
rev: stable
rev: 23.1.0
hooks:
- id: black
args: [--line-length=120]

- repo: https://github.com/pycqa/isort
rev: 5.5.3
rev: 5.12.0
hooks:
- id: isort
args: [--profile=black, -m=3, -l=120]

- repo: https://github.com/hakancelik96/unimport
rev: stable
- repo: https://github.com/hakancelikdev/unimport
rev: 0.14.1
hooks:
- id: unimport
args: [--remove, --include-star-import]
41 changes: 21 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,39 @@ from iubeo import config
def list_from_string(val):
return val.split(',')

CONFIG = config({
'DATABASE': {
'USER': str,
'PASSWORD': str,
'HOST': str,
'PORT': str,
CONFIG = config(
{
'DATABASE': {
'USER': str,
'PASSWORD': str,
'HOST': str,
'PORT': str,
},
'ALLOWED_HOSTS': list_from_string,
},
'ALLOWED_HOSTS': list_from_string,
})
# prefix = '', # default
# sep = '__', # default
)
```

It creates the environment variable names for you, and reads them from the environment, casting it to the final nodes.

Now your can just chain the attributes, and if it is the last node on the above dictionary, you get the environment
variable casted to given callable.
with the above config, environment variables like

```.env
DATABASE__USER=isik-kaplan
DATABASE__PASSWORD=isik-kaplan-db-password
DATABASE__USER=example
DATABASE__PASSWORD=example-password
DATABASE__HOST=localhost
DATABASE__PORT=5432
ALLOWED_HOSTS=isik-kaplan.com,api.isik-kaplan.com,www.isik-kaplan.com
ALLOWED_HOSTS=example.com,api.example.com,www.example.com
```

are read from the environment, and are casted when you access the attribute.
are read from the environment.

```py
CONFIG.DATABASE.USER # "isik-kaplan"
CONFIG.DATABASE.PASSWORD # "isik-kaplan-db-password"
CONFIG.DATABASE.USER # "example-user"
CONFIG.DATABASE.PASSWORD # "example-password"
CONFIG.DATABASE.HOST # "localhost"
CONFIG.DATABASE.PORT # "5432"
CONFIG.ALLOWED_HOSTS # ["isik-kaplan.com", "api.isik-kaplan.com", "www.isik-kaplan.com"]
CONFIG.ALLOWED_HOSTS # ["example.com", "api.example.com", "www.example.com"]
```

You can also change the separator and add a prefix to manage your environment variables better
Expand All @@ -65,7 +66,7 @@ which would be read from
APP1-SECRETS-API_KEY=isik_kaplan_api_key
```

Iubeo also comes with couple of pre-configured functions to read common environment variable types:
Iubeo also comes with a couple of pre-configured functions to read common environment variable types:
```py
from iubeo import config, comma_separated_list, boolean

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "iubeo"
version = "0.2.0"
version = "0.2.1"
description = "Friendlier way to write your config."
authors = ["isik-kaplan <[email protected]>"]

Expand Down

0 comments on commit c3d3d7f

Please sign in to comment.