This release is a pre-release and may not be stable for production use.
Figa
Figa can read from multiple config sources including several file formats, environment variables, and even the Internet, allowing you to configure your project however you want.
Figa supports many sources, including:
Environment variables
Dict objects
JSON (.json)
HOCON (.hocon, .conf)
INI, CFG (.ini, .cfg)
YAML (.yaml, .yml)
TOML (.toml)
.properties (.properties)
Internet resources
$ pip install figa
Usage
import figa
@figa.config
class MyConfig:
development = "~/config.yml" # use YAML file for config when developing
production = "env", "cfg_" # use environment variables with cfg_ prefix in production
config = MyConfig("development")
>>> config.key == config["key"] # config can be accessed using dots or indexing
True
Environment Detection
You can implement your own function that detects where to pull config values from.
@figa.config
class Config:
development = "~/config.yml" # use YAML file for config when developing
production = "env", "cfg_" # use environment variables with cfg_ prefix in production
def get_env(self):
if "ON_HEROKU" in figa.env: # figa.env is shortcut for os.environ
return "production"
else:
return "development"
>>> config = Config() # if no environment is passed, get_env() will be called.
File Types
By default, the config file type will be guessed from the file extension. This can also be set explicitly:
@figa.config
class MyConfig:
example = "ini", "./config.conf"
# .conf would be detected as HOCON, but we set to INI
Default Values
Default values can be set that will be included on every environment.
@figa.config
class MyConfig:
default = {"name": "My App"}
dev = {"host": "localhost"}
prod = {"host": "myapp.com"}
>>> dev_cfg = MyConfig("dev")
>>> prod_cfg = MyConfig("prod")
>>> dev_cfg.name == prod_cfg.name # "name" config item is included in both
True
Required Values and Type Checking
In your Config class you can set required values and types that will be checked when the config is loaded. This helps ensure that your code doesn’t run with missing information.
@figa.config
class Config:
# two required config values: `string` & `sub.number`
__required__ = {
"string": str,
"sub": {
"number": int
}
}
If any values are missing, an error will be raised:
@figa.config
class Config:
# two required config values: `string` & `sub.number`
__required__ = {
"string": str,
"sub": {
"number": int
}
}
missing_vals = { # this config is missing sub.number
"string": "hello, world",
"sub": {}
}
>>> cfg = Config("missing_vals")
ValueError: Missing required item 'sub.number'
Figa will automatically convert strings and numbers for you where possible.
@figa.config
class Config:
__required__ = {
"stringval": str,
"numberval": int
}
values = {
"stringval": 100,
"numberval": "42"
}
>>> cfg = Config("values")
>>> cfg.stringval
'100'
>>> cfg.numberval
42
This project is published under the MIT License. See LICENSE.md.
Metadata
Release files for figa 0.1a5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| figa-0.1a5.tar.gz | 8.9 kB | Without provenance | Details for figa-0.1a5.tar.gz |
Release files / figa-0.1a5.tar.gz
| Download URL | figa-0.1a5.tar.gz |
|---|---|
| Size | 8.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
56c51b49e40522b0f452c7d0e3b771bee1391a81159cd5399420ec5309989d2d
|
|
BLAKE2b-256 checksum How to use checksums |
742b90b7fa95900fb89f16b3f952e1c9e2a9281b6a83e9e0c0659fea83f04b6d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.4.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.8.3
|
Security for figa 0.1a5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.