Decorator driven declarative framework to assist in creating large applications and manage beans
Fxquants core for python is a declarative based IOC framework for helping to build large applications in python.
Due to the way in which Python loads packages IOC frameworks are not as popular as for example in java. For example you could just use a flat file and declare instances inside of it them import it as required.
However there is still great value in employing the design patterns many developers are familiar with, and (IMHO) more useful is the declarative configuration-less nature that is used in modern versions of spring-boot allowing a developer to include at the point of code the intended purpose for a class. Defining these categories with the code allows a developer to focus on the problem domain, and less about how any given framework injects such dependencies.
The fxq series of python libraries look to take some of the best features of the Sping IOC framework and Spring boot annotations and port them as Decorators on top of a managed IOC container.
Create a class i.e. ComponentExample and decorate it with @Component, this will trigger an instance of this component to be registered with the IOC container and it can be pulled out with the decorator method Autowired (python doesnt currently support decorator syntax on fields so simply call the method itself, specifying either the bean name, or expected type)
import logging format = "[%(asctime)s] [%(levelname)s] [%(name)s] - %(message)s" logging.basicConfig(format=format, level=logging.DEBUG) from fxq.core.beans.factory.annotation import Autowired from fxq.core.stereotype import Component @Component class ComponentExample: def __init__(self): self.id = "1" def __repr__(self): return "ComponentExample instance %s - ID:%s" % (hash(self), self.id) if __name__ == '__main__': component_example = Autowired(type=ComponentExample) same_component = Autowired(name="component_example") same_component_again = Autowired(name="component_example", type=ComponentExample) logging.info(component_example) logging.info(same_component) logging.info(same_component_again)
[2019-05-19 19:17:07,789] [INFO] [BeanFactory] - Bean Factory Initialized [2019-05-19 19:17:07,789] [INFO] [ApplicationContext] - Application Context Initialized [2019-05-19 19:17:07,791] [DEBUG] [BeanFactory] - Registering Bean for type ComponentExample with name component_example [2019-05-19 19:17:07,791] [DEBUG] [BeanFactory] - Matched component_example to be of class type ComponentExample [2019-05-19 19:17:07,792] [DEBUG] [BeanFactory] - Found instance of type ComponentExample for requested bean component_example [2019-05-19 19:17:07,792] [DEBUG] [BeanFactory] - Validated Bean component_example to be of type ComponentExample [2019-05-19 19:17:07,792] [INFO] [root] - ComponentExample instance -9223372036577000402 - ID:1 [2019-05-19 19:17:07,792] [INFO] [root] - ComponentExample instance -9223372036577000402 - ID:1 [2019-05-19 19:17:07,792] [INFO] [root] - ComponentExample instance -9223372036577000402 - ID:1
Simply install the python module using
pip install fxq-core
Contributions are most welcome to the project, please raise issues first and contribute in response to the issue with a pull request.
- Jonathan Turnock - Initial work - fxquants - profile
This project is licensed under the MIT License - see the LICENSE.md file for details
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size & hash SHA256 hash help||File type||Python version||Upload date|
|fxq_core-1.0.3-py3-none-any.whl (7.7 kB) Copy SHA256 hash SHA256||Wheel||py3|
|fxq-core-1.0.3.tar.gz (4.8 kB) Copy SHA256 hash SHA256||Source||None|