Skip to content

Commit

Permalink
Rename to konfetti
Browse files Browse the repository at this point in the history
  • Loading branch information
Stranger6667 committed Jun 30, 2019
1 parent 2b1a1f1 commit 99b783f
Show file tree
Hide file tree
Showing 41 changed files with 173 additions and 176 deletions.
10 changes: 5 additions & 5 deletions .coafile
@@ -1,5 +1,5 @@
[all]
files = src/kwonfig/**.py, test/**.py, *.(yml|yaml), *.md, *requirements.txt, .coafile
files = src/konfetti/**.py, test/**.py, *.(yml|yaml), *.md, *requirements.txt, .coafile

indent_size = 4
use_spaces = yes
Expand All @@ -15,14 +15,14 @@ bears = LineCountBear

[all.python]
language = python
files = src/kwonfig/**.py, test/**.py
files = src/konfetti/**.py, test/**.py

[all.python.keywords]
language = python
files = src/kwonfig/**.py
files = src/konfetti/**.py
bears = KeywordBear
keywords =
from kwonfig,
from konfetti,
FIXME,
pdb.set_trace(),
sys.path.insert,
Expand All @@ -44,7 +44,7 @@ preferred_quotation = "
[all.python.imports]
bears = PyImportSortBear
force_single_line_imports = no
known_first_party_imports = kwonfig, test
known_first_party_imports = konfetti, test
isort_multi_line_output = 3
include_trailing_comma_in_import = yes
default_import_section = THIRDPARTY
Expand Down
6 changes: 3 additions & 3 deletions .coveragerc
@@ -1,12 +1,12 @@
[run]
branch = True
parallel = True
source = kwonfig
source = konfetti

[paths]
source =
src/kwonfig
.tox/*/lib/python*/site-packages/kwonfig
src/konfetti
.tox/*/lib/python*/site-packages/konfetti

[report]
show_missing = True
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -33,4 +33,4 @@ before_cache:
- rm -rf $HOME/.cache/pip/log

after_success:
- codecov
- codecov
6 changes: 3 additions & 3 deletions Makefile
Expand Up @@ -12,7 +12,7 @@ test:
pytest test -v

docker-test:
docker-compose -f docker-compose-tests.yml run kwonfig
docker-compose -f docker-compose-tests.yml run konfetti

tox-test:
tox -p all
Expand All @@ -21,10 +21,10 @@ pylint:
tox -e pylint

black:
black -l 120 src/kwonfig docs test setup.py
black -l 120 src/konfetti docs test setup.py

mypy:
mypy --config-file ./mypy.ini -p kwonfig
mypy --config-file ./mypy.ini src/konfetti

install:
ARCHFLAGS="-arch x86_64" pip install -r ./requirements.txt
Expand Down
96 changes: 48 additions & 48 deletions README.md
@@ -1,16 +1,16 @@
# kwonfig
# konfetti

![codecov](https://codecov.io/gh/kiwicom/kwonfig/branch/master/graph/badge.svg)
![Build](https://img.shields.io/travis/kiwicom/kwonfig.svg)
![Version](https://img.shields.io/pypi/v/kwonfig.svg)
![Python versions](https://img.shields.io/pypi/pyversions/kwonfig.svg)
![License](https://img.shields.io/pypi/l/kwonfig.svg)
![codecov](https://codecov.io/gh/kiwicom/konfetti/branch/master/graph/badge.svg)
![Build](https://img.shields.io/travis/kiwicom/konfetti.svg)
![Version](https://img.shields.io/pypi/v/konfetti.svg)
![Python versions](https://img.shields.io/pypi/pyversions/konfetti.svg)
![License](https://img.shields.io/pypi/l/konfetti.svg)

## Description

NOTE: The documentation is in progress

`kwonfig` provides a framework-independent way for configuration of applications or libraries written in Python.
`konfetti` provides a framework-independent way for configuration of applications or libraries written in Python.

Key features:

Expand All @@ -30,7 +30,7 @@ The interface design and features are heavily inspired by `Django` & `decouple`.

## Quickstart

To use `kwonfig` you need to define:
To use `konfetti` you need to define:

- configuration variables in a module or a class;
- an access point;
Expand All @@ -39,7 +39,7 @@ To use `kwonfig` you need to define:

```python
# app_name/settings/production.py
from kwonfig import env, vault
from konfetti import env, vault

VAULT_ADDR = env("VAULT_ADDR")
VAULT_TOKEN = env("VAULT_TOKEN")
Expand All @@ -54,14 +54,14 @@ DATABASE_URI = vault("path/to/db")

```python
# app_name/settings/__init__.py
from kwonfig import KWonfig, VaultBackend
from konfetti import Konfig, VaultBackend

config = KWonfig(vault_backend=VaultBackend("/secret/team"))
config = Konfig(vault_backend=VaultBackend("/secret/team"))
```

`kwonfig` relies on `KWONFIG` environment variable to discover your settings module, in the case above:
`konfetti` relies on `KONFETTI_SETTINGS` environment variable to discover your settings module, in the case above:

`export KWONFIG=app_name.settings.production`
`export KONFETTI_SETTINGS=app_name.settings.production`

### Usage

Expand All @@ -79,10 +79,10 @@ def something():

**Table of contents**:

- [Lazy evaluation](https://github.com/kiwicom/kwonfig#lazy-evaluation)
- [Environment](https://github.com/kiwicom/kwonfig#environment)
- [Vault](https://github.com/kiwicom/kwonfig#vault)
- [Testing](https://github.com/kiwicom/kwonfig#testing)
- [Lazy evaluation](https://github.com/kiwicom/konfetti#lazy-evaluation)
- [Environment](https://github.com/kiwicom/konfetti#environment)
- [Vault](https://github.com/kiwicom/konfetti#vault)
- [Testing](https://github.com/kiwicom/konfetti#testing)

### Lazy evaluation

Expand All @@ -100,7 +100,7 @@ It could be done either with direct accessing needed variables or with `config.r
### Environment

```python
from kwonfig import env
from konfetti import env

VARIABLE = env("VARIABLE_NAME", default="foo")
```
Expand All @@ -109,7 +109,7 @@ Since environment variables are strings, there is a `cast` option to convert
given variable from a string to the desired type:

```python
from kwonfig import env
from konfetti import env

VARIABLE = env("VARIABLE_NAME", default=42, cast=int)
```
Expand All @@ -119,7 +119,7 @@ If there is a need to use the environment variable immediately, it could be
evaluated via `str` call (other ways could be added on demand):

```python
from kwonfig import env, vault
from konfetti import env, vault

DATABASE_ROLE = env("DATABASE_ROLE", default="booking")

Expand All @@ -138,9 +138,9 @@ both the environment variable and the `.env` record exists, `False` by default.

```python
# app_name/settings/__init__.py
from kwonfig import KWonfig
from konfetti import Konfig

config = KWonfig(dotenv="path/to/.env", dotenv_override=False)
config = Konfig(dotenv="path/to/.env", dotenv_override=False)
```

### Vault
Expand All @@ -151,15 +151,15 @@ To use Vault as a secrets storage you need to configure the access point:

```python
# app_name/settings/__init__.py
from kwonfig import KWonfig, VaultBackend
from konfetti import Konfig, VaultBackend

config = KWonfig(vault_backend=VaultBackend("your/prefix"))
config = Konfig(vault_backend=VaultBackend("your/prefix"))
```

There are two Vault backends available:

- `kwonfig.VaultBackend`
- `kwonfig.AsyncVaultBackend`
- `konfetti.VaultBackend`
- `konfetti.AsyncVaultBackend`

The main difference is that the latter requires using `await` to access
the secret value (the call will be handled asynchronously under the hood), otherwise the interfaces and capabilities are the same.
Expand All @@ -173,7 +173,7 @@ Every Vault secret needs a `path` to be used as a lookup (leading and trailing s

```python
# app_name/settings/production.py
from kwonfig import vault
from konfetti import vault

WHOLE_SECRET = vault("path/to")
```
Expand All @@ -190,7 +190,7 @@ You can specify a specific key to be returned for a config option with `[]` synt

```python
# app_name/settings/production.py
from kwonfig import vault
from konfetti import vault

KEY = vault("path/to")["key"]
```
Expand All @@ -205,7 +205,7 @@ Using square brackets will not trigger evaluation - you could specify as many le

```python
# app_name/settings/production.py
from kwonfig import vault
from konfetti import vault

DEEP = vault("path/to")["deeply"]["nested"]["key"]
```
Expand All @@ -215,7 +215,7 @@ Casting could be specified as well:
```python
# app_name/settings/production.py
from decimal import Decimal
from kwonfig import vault
from konfetti import vault

DECIMAL = vault("path/to", cast=Decimal)["fee_amount"] # stored as string
```
Expand All @@ -226,7 +226,7 @@ DECIMAL = vault("path/to", cast=Decimal)["fee_amount"] # stored as string
Decimal("0.15")
```

Sometimes you need to access to some secrets dynamically. `KWonfig` provides a way to do it:
Sometimes you need to access to some secrets dynamically. `Konfig` provides a way to do it:

```python
>>> from app_name.settings import config
Expand All @@ -240,7 +240,7 @@ It is possible to get a file-like interface for vault secret.

```python
# app_name/settings/production.py
from kwonfig import vault_file
from konfetti import vault_file

KEY = vault_file("path/to/file")["key"]
```
Expand Down Expand Up @@ -285,7 +285,7 @@ Example:

```python
# app_name/settings/production.py
from kwonfig import vault
from konfetti import vault

KEY = vault("path/to")["key"]
```
Expand Down Expand Up @@ -322,42 +322,42 @@ If you don't need this behavior, it could be turned off with `try_env_first=Fals

```python
# app_name/settings/__init__.py
from kwonfig import KWonfig, VaultBackend
from konfetti import Konfig, VaultBackend

config = KWonfig(vault_backend=VaultBackend("your/prefix", try_env_first=False))
config = Konfig(vault_backend=VaultBackend("your/prefix", try_env_first=False))
```

##### Disabling access to secrets

If you want to forbid any access to Vault (e.g. in your tests) you can set `KWONFIG_DISABLE_SECRETS` environment
If you want to forbid any access to Vault (e.g. in your tests) you can set `KONFETTI_DISABLE_SECRETS` environment
variable with `1` / `on` / `true` / `yes`.

```python
>>> import os
>>> from app_name.settings import config
>>> os.environ["KWONFIG_DISABLE_SECRETS"] = "1"
>>> os.environ["KONFETTI_DISABLE_SECRETS"] = "1"
>>> config.get_secret("path/to")["key"]
...
RuntimeError: Access to secrets is disabled. Unset KWONFIG_DISABLE_SECRETS variable to enable it.
RuntimeError: Access to secrets is disabled. Unset KONFETTI_DISABLE_SECRETS variable to enable it.
```

##### Caching

Vault values could be cached in memory:

```python
config = KWonfig(vault_backend=VaultBackend("your/prefix", cache_ttl=60))
config = Konfig(vault_backend=VaultBackend("your/prefix", cache_ttl=60))
```

By default, caching is disabled.

#### Lazy options

If there is a need to calculate config options dynamically (e.g., if it depends on values of other options) `kwonfig`
If there is a need to calculate config options dynamically (e.g., if it depends on values of other options) `konfetti`
provides `lazy`:

```python
from kwonfig import lazy
from konfetti import lazy

LAZY_LAMBDA = lazy(lambda config: config.KEY + "/" + config.SECRET + "/" + config.REQUIRED)

Expand All @@ -372,10 +372,10 @@ def lazy_property(config):
It is usually a good idea to use a slightly different configuration for tests (disabled tracing, sentry, etc.).

```
export KWONFIG=app_name.settings.tests
export KONFETTI_SETTINGS=app_name.settings.tests
```

It is very useful to override some config options in tests. `KWonfig.override` will override config options defined
It is very useful to override some config options in tests. `Konfig.override` will override config options defined
in the settings module. It works as a context manager or a decorator to provide explicit setup & clean up for overridden options.

```python
Expand Down Expand Up @@ -422,13 +422,13 @@ def test_not_affected():

NOTE. `setup_class/setUp` and `teardown_class/tearDown` methods will work with `override`.

`kwonfig` includes a pytest integration that gives you a fixture, that allows you to override given config without
`konfetti` includes a pytest integration that gives you a fixture, that allows you to override given config without
using a context manager/decorator approach and automatically rollbacks changes made:

```python
import pytest
from app_name.settings import config
from kwonfig.pytest_plugin import make_fixture
from konfetti.pytest_plugin import make_fixture

# create a fixture. the default name is "settings",
# but could be specified via `name` option
Expand Down Expand Up @@ -472,13 +472,13 @@ NOTE. It is forbidden to create two fixtures from the same config instances.
The environment variable name could be customized via `config_variable_name` option:

```python
config = KWonfig(config_variable_name="APP_CONFIG")
config = Konfig(config_variable_name="APP_CONFIG")
```

Alternatively, it is possible to specify class-based settings:

```python
from kwonfig import env, vault
from konfetti import env, vault


class ProductionSettings:
Expand Down Expand Up @@ -602,7 +602,7 @@ $ make docker-test
or alternatively:

```bash
$ docker-compose -f docker-compose-tests.yml run kwonfig
$ docker-compose -f docker-compose-tests.yml run konfetti
```

## Contributing
Expand Down
2 changes: 1 addition & 1 deletion docker-compose-tests.yml
Expand Up @@ -2,7 +2,7 @@
version: "3.7"

services:
kwonfig:
konfetti:
image: kiwicom/tox
environment:
TEST_VAULT_ADDR: http://vault:8200
Expand Down
2 changes: 1 addition & 1 deletion docs/Makefile
Expand Up @@ -4,7 +4,7 @@
# You can set these variables from the command line.
SPHINXOPTS =
SPHINXBUILD = sphinx-build
SPHINXPROJ = kwonfig
SPHINXPROJ = konfetti
SOURCEDIR = .
BUILDDIR = _build

Expand Down

0 comments on commit 99b783f

Please sign in to comment.