We are incredibly excited to announce that Stormpath is joining forces with Okta. Please visit the Migration FAQs for a detailed look at what this means for Stormpath users.
We're available to answer all questions at [email protected].
Stormpath configuration loader.
Note
This library is responsible for loading Stormpath configuration. It is an internal module used by stormpath-sdk-python, stormpath-django, and stormpath-flask, and is not meant for general consumption.
To install this library, just run:
$ pip install stormpath-config
If this doesn't work, you might need to install pip
on your computer. See
the pip installation guide for more information.
First, you'll need to initialize a new ConfigLoader
object like so:
from stormpath_config.loader import ConfigLoader
config_loader = ConfigLoader(load_strategies, post_processing_strategies, validation_strategies)
All ConfigLoader
arguments are lists of strategies:
load_strategies
- List of strategies that load configuration data.post_processing_strategies
- List of strategies that will be performed after each load strategy.validation_strategies
- List of strategies that will be performed after load and post processing strategies are finished.
See strategies for a list of all supported strategies, and information about how to create your own.
Here's an example of how Stormpath configuration data can be loaded from environment variables:
from stormpath_config.strategies import LoadEnvConfigStrategy, LoadFileConfigStrategy
config_loader = ConfigLoader([
LoadEnvConfigStrategy(prefix='STORMPATH'),
LoadFileConfigStrategy('~/stormpath.yml'),
])
Now, once you have your new ConfigLoader
object, all you need to do is call
the load()
method to load all configuration data. You can do this like so:
config = config_loader.load()
print(config)
A strategy is simply a prototype that implements a method named process
that takes the parameter config
and returns processed config
. For
instance:
class MyConfigStrategy(object):
def process(self, config=None):
# Apply strategy to config and return resulting config.
config['someNewField'] = 'abc' # Append someNewField to our config
return config
Some default strategies for loading configuration data are already built in.
These are accessible through the stormpath_config.strategies
module.
Loads configuration from the system environment.
Loads client API key configuration from a .properties file.
Loads configuration from either a JSON or YAML file.
Extends configuration data with an existing object.
Loads an API key from configuration data.
Moves an API key from apiKey
to client.apiKey
.
Enriches the configuration with client configuration information resolved from the Stormpath API.
Enriches the configuration with integration config resolved at runtime.
Enriches the configuration with integration config resolved from the Stormpath API.
Validates the client configuration.
Dumps the config to the provided logger.
You can make your own contributions by forking this repository, making your
changes in a feature branch, and then issuing a pull request back to this
repository on the master
branch.
Here's how you might do this if you wanted to contribute something:
$ git clone https://github.com/stormpath/stormpath-python-config.git
$ cd stormpath-python-config
$ git checkout -b feature-something-something
$ # make changes
$ git commit -m "This was easy!"
$ git push origin feature-something-something
$ # submit a pull request
We regularly maintain this repository, and are quick to review pull requests and accept changes!
We <333 contributions!
Copyright ©2015 Stormpath, Inc. and contributors.