Metadata-Version: 2.4
Name: pythonic-spring
Version: 0.0.2.0
Summary: A python-made framework which is like Spring in Java, integrated with FastAPI.
Author: Tianhao Zhang
Author-email: genji9071@gmail.com
License: MIT
Project-URL: Source, https://github.com/genji9071/pythonic-spring/
Project-URL: Tracker, https://github.com/genji9071/pythonic-spring/issues
Keywords: spring pythonic fastapi ioc di
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.11
Requires-Python: >=3.7
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: fastapi~=0.108.0
Requires-Dist: setuptools~=65.5.1
Requires-Dist: pydantic~=2.5.3
Dynamic: author
Dynamic: author-email
Dynamic: classifier
Dynamic: description
Dynamic: description-content-type
Dynamic: keywords
Dynamic: license
Dynamic: license-file
Dynamic: project-url
Dynamic: requires-dist
Dynamic: requires-python
Dynamic: summary

# 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 查找

### 安装

```bash
pip install pythonic-spring
```

### 快速开始

```python
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()
```

### 循环依赖

```python
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 配置

```json
{
    "config_type": "bean",
    "detail": {
        "id": "myBean",
        "class_name": "mypackage.MyClass",
        "properties": [
            {"name": "host", "value": "${DB_HOST:localhost}"},
            {"name": "port", "value": 5432}
        ]
    }
}
```

### License

MIT
