pythonic-spring
用 Python 实现 Spring 特性,已集成 FastAPI,像 SpringBoot 一样统一管理类的生成和调用。
版本 0.0.2.0
特性
- @Service — 装饰 class,自动生成 bean 并注册到容器
- @Autowired — 装饰
__init__,自动注入依赖(支持类型注解自动推断、显式 bean_id / bean_modules) - @PostConstruct / @PreDestroy — Bean 生命周期回调
- BeanScope — SINGLETON(默认)/ PROTOTYPE 作用域
- 循环依赖解析 — 通过 BeanProxy 占位符机制自动处理
- 配置加载 — spring.json 支持多环境 profile、
${}占位符 - SpringApplication — 继承 FastAPI,支持通配扫描,按 bean_id / type 查找
安装
pip install pythonic-spring
快速开始
from pythonicspring import SpringApplication, Service, Autowired
app = SpringApplication()
# 声明 bean
@Service
class UserService:
def greet(self):
return "Hello, Spring!"
# 自动注入
@Service
class UserController:
user_svc: UserService = None
@Autowired
def __init__(self):
pass
def handle(self):
return self.user_svc.greet()
循环依赖
from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from somewhere import ClassB
@Service
class ClassA:
class_b: ClassB = None
@Autowired
def __init__(self):
pass
spring.json 配置
{
"config_type": "bean",
"detail": {
"id": "myBean",
"class_name": "mypackage.MyClass",
"properties": [
{"name": "host", "value": "${DB_HOST:localhost}"},
{"name": "port", "value": 5432}
]
}
}
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pythonic_spring-0.0.2.0.tar.gz
(15.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pythonic_spring-0.0.2.0.tar.gz.
File metadata
- Download URL: pythonic_spring-0.0.2.0.tar.gz
- Upload date:
- Size: 15.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7c706839733b38fac566bcfc55e211a43b92c5691d9a3d41769debf9a5fd0303
|
|
| MD5 |
b81180a2fdee58abaac7dc26e8700a56
|
|
| BLAKE2b-256 |
5a64cb6b616bbda4a1e8b959c8d87cc72394dc18ad7f8913c661c918f6f443ee
|
File details
Details for the file pythonic_spring-0.0.2.0-py3-none-any.whl.
File metadata
- Download URL: pythonic_spring-0.0.2.0-py3-none-any.whl
- Upload date:
- Size: 16.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c6811bcb26010efdeaf5223ccd900c294d9e5fb74988348c55a783412f8b9b9
|
|
| MD5 |
fd4b71f6bdc3493e316b00b257443a82
|
|
| BLAKE2b-256 |
a2e64e29c3c2f8fe4d573faf8437ff43b82ced32e288c038ed5fb1d086405333
|