A python-made framework which is like Spring in Java.
Project description
pythonic-spring
用python实现spring特性, 已集成fastapi, 可以像springboot那样统一管理类的生成和调用, 相比较原先python通过在类声明外面整实例的情况, 防止了写代码时循环调用的风险, 也可以为java中比较常见的多态和继承在python中的实战化做基底
当前最新版本 0.0.1.3:
两个装饰器:
- Service: 装饰class, 根据spring.json自动生成bean, 并通过BeanFactory注册
- Autowired: 装饰__init__方法, 根据bean_modules和bean_ids自动注入注册的bean到类中
SpringApplication:构建即使用, 支持输入通配扫描代码并延迟import, 提供了bean_id和type两种找bean的方式
spring.json:扫描并反序列, 供BeanFactory读取
使用方法
安装pip包
pip install pythonic-spring
创建实例
from pythonicspring import SpringApplication
app = SpringApplication()
声明需要bean化的类, 使用类装饰器:Service
声明类内需要引用的bean, 在__init__方法上使用装饰器:Autowired
from pythonicspring import Service
from pythonicspring import Autowired
@Service
class ClassA:
class_b: ClassB = None
class_c: ClassC = None
@Autowired(bean_modules={"class_b": ClassB}, bean_ids={"class_c": "ClassCCC"})
def __init__(self):
pass
def foo(self):
result = class_b.spam()
pass
一个例子:
test/testApp.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for pythonic_spring-0.0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ff443f3ddbe7a2fa791d3ebaf8bc3e88cbc9ae930a8d0809294e8671cca137b |
|
MD5 | 4f9972ba199be003262dc267c6370fd1 |
|
BLAKE2b-256 | c76053073c91a3ae16aa053a910b2e953bb7ed0bd88bc5095dfc42724cdaa914 |