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
File details
Details for the file pythonic-spring-0.0.1.5.tar.gz
.
File metadata
- Download URL: pythonic-spring-0.0.1.5.tar.gz
- Upload date:
- Size: 8.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | abf426cec50d1c19c7bc85d836c075067711a3ce3aa6974b948f5083c8cfe772 |
|
MD5 | 13903d7fe6466defc07b8507e0bc6592 |
|
BLAKE2b-256 | 60a5b46bb05d1fc6c9eed3dea76446352722ff1ffecd69070dcd6cae45edb600 |
File details
Details for the file pythonic_spring-0.0.1.5-py3-none-any.whl
.
File metadata
- Download URL: pythonic_spring-0.0.1.5-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.4
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e1614d04903fc1ffd51a1efda521e86c41ae66c4efbf6b3de1b1eae54a989f62 |
|
MD5 | 1cf7a8660dfa4669b292e0a6ac2100f6 |
|
BLAKE2b-256 | 24e7f8f025357eed0e71440ef7a4963a09504bbe827fea61d70a67c9ff30d4df |