
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Figcan is a minimalistic configuration handling library for Python.
It is designed to help you manage runtime configuration coming from different sources, without making any assumptions about configuration file formats and locations, and while staying super simple to use for common use cases.
Figcan has no runtime dependencies other than Python versions 2.7 or 3.4 and up.
Figcan's design is based on a few basic assumptions:
With those in mind, here is what Figcan will do:
And here is what Figcan will not do for you in one line - but supports doing very easily with just a few lines of custom code you will need to write:
INI
, JSON
, YAML
etc.)argparse
,
optparse
, click
etc.)dict
interface provides (which, if you ask us, should be enough for everybody)We plan to provide some documentation and examples on how to get these done with Figcan.
It is recommended to add Figcan to your project using pip
:
pip install figcan
You should also be able to install directly from the source tree pulled from git:
`TBD`
Typically, Figcan is used by reading configuration from all sources at the
beginning of your program (e.g. in your main
), and making the configuration
object available to all other parts of the program as needed.
Here is a very basic (but not unrealistic) usage example:
import os
from figcan import Configuration
from my_project.config import default_config # A dictionary defining default configuration values
def main():
config = Configuration(default_config)
# Apply configuration overrides from environment variables
config.apply_flat(os.environ, prefix='MYPROJECT')
# Do something with the configuration:
db_engine = sqlalchemy.create_engine(config['db']['url'])
If your configuration is saved in a file format that can be parsed into a
Python dict
, you can easily get Figcan to work with it. For example:
import yaml
from figcan import Configuration
from my_project.config import default_config # A dictionary defining default configuration values
def main(config_file_path):
config = Configuration(default_config)
with open(config_file_path) as f:
config.apply(yaml.safe_load(f))
# Do something with the configuration:
db_engine = sqlalchemy.create_engine(config['db']['url'])
Note that Configuration.apply
will raise an exception if it encounters a
configuration key that is not present in your default_config
. This can be
changed like so:
config.apply(yaml.safe_load(f), raise_on_unknown_key=False)
If you want to allow merging new configuration keys into a configuration
section, you will need to define that section as Extensible
in the base
configuration:
from figcan import Configuration, Extensible
default_config = dict({ # Base configuration keys are known ahead and static
'bind_port': 5656,
'db': { # Database settings keys are known ahead and static
'hostname': 'db.local',
'username': 'foobar',
'password': 'blahblah'
} ,
'logging': Extensible({ # But logging settings are flexible, and new handlers / loggers can be defined
'handlers': {
'handler_1': '...'
}
})
})
config = Configuration(default_config)
# This will not raise an exception and 'handler_2' config will be available in `config`:
config.apply({"logging": {"handlers": {"handler_2": "... more config ..."}}})
There are many configuration handling libraries for Python. Some may be more suitable for you than Figcan (some we have tried before deciding to write Figcan):
the idea here is that the initial default_config
dict will also contain some
type annotations in some form. These will be used to coerce override values
(e.g. when coming as strings from environment variables) and to do some
validation when configuration is applied.
For example, a logging
section used for logging.config.dictConfig
typically
needs to have a flexible structure. However, making everything flexible can
lead to typos etc. not being detected.
Figcan was created by the Shoppimon team and is in use by Shoppimon in highly used, critical production code.
© 2018 Shoppimon LTD, all rights reserved
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
FAQs
Figcan - minimalistic configuration handling library for Python
We found that figcan demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.