Skip to main content

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)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pythonic_spring-0.0.2.0-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

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

Hashes for pythonic_spring-0.0.2.0.tar.gz
Algorithm Hash digest
SHA256 7c706839733b38fac566bcfc55e211a43b92c5691d9a3d41769debf9a5fd0303
MD5 b81180a2fdee58abaac7dc26e8700a56
BLAKE2b-256 5a64cb6b616bbda4a1e8b959c8d87cc72394dc18ad7f8913c661c918f6f443ee

See more details on using hashes here.

File details

Details for the file pythonic_spring-0.0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pythonic_spring-0.0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6c6811bcb26010efdeaf5223ccd900c294d9e5fb74988348c55a783412f8b9b9
MD5 fd4b71f6bdc3493e316b00b257443a82
BLAKE2b-256 a2e64e29c3c2f8fe4d573faf8437ff43b82ced32e288c038ed5fb1d086405333

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.0.2.0 This release

2 files

0.0.1.5

2 files

0.0.1.4

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page