Name | pythonic-spring JSON |
Version |
0.0.1.5
JSON |
| download |
home_page | None |
Summary | A python-made framework which is like Spring in Java. |
upload_time | 2024-08-16 09:19:33 |
maintainer | None |
docs_url | None |
author | Tianhao Zhang |
requires_python | >=3.7 |
license | MIT |
keywords |
spring
pythonic
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# 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
Raw data
{
"_id": null,
"home_page": null,
"name": "pythonic-spring",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": "spring pythonic",
"author": "Tianhao Zhang",
"author_email": "genji9071@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/60/a5/b46bb05d1fc6c9eed3dea76446352722ff1ffecd69070dcd6cae45edb600/pythonic-spring-0.0.1.5.tar.gz",
"platform": null,
"description": "# pythonic-spring\r\n\r\n\u7528python\u5b9e\u73b0spring\u7279\u6027, \u5df2\u96c6\u6210fastapi, \u53ef\u4ee5\u50cfspringboot\u90a3\u6837\u7edf\u4e00\u7ba1\u7406\u7c7b\u7684\u751f\u6210\u548c\u8c03\u7528, \u76f8\u6bd4\u8f83\u539f\u5148python\u901a\u8fc7\u5728\u7c7b\u58f0\u660e\u5916\u9762\u6574\u5b9e\u4f8b\u7684\u60c5\u51b5, \u9632\u6b62\u4e86\u5199\u4ee3\u7801\u65f6\u5faa\u73af\u8c03\u7528\u7684\u98ce\u9669, \u4e5f\u53ef\u4ee5\u4e3ajava\u4e2d\u6bd4\u8f83\u5e38\u89c1\u7684\u591a\u6001\u548c\u7ee7\u627f\u5728python\u4e2d\u7684\u5b9e\u6218\u5316\u505a\u57fa\u5e95\r\n\r\n## \u5f53\u524d\u6700\u65b0\u7248\u672c 0.0.1.3:\r\n\r\n\u4e24\u4e2a\u88c5\u9970\u5668:\r\n\r\n- Service: \u88c5\u9970class, \u6839\u636espring.json\u81ea\u52a8\u751f\u6210bean, \u5e76\u901a\u8fc7BeanFactory\u6ce8\u518c\r\n- Autowired: \u88c5\u9970__init__\u65b9\u6cd5, \u6839\u636ebean_modules\u548cbean_ids\u81ea\u52a8\u6ce8\u5165\u6ce8\u518c\u7684bean\u5230\u7c7b\u4e2d\r\n\r\nSpringApplication:\u6784\u5efa\u5373\u4f7f\u7528, \u652f\u6301\u8f93\u5165\u901a\u914d\u626b\u63cf\u4ee3\u7801\u5e76\u5ef6\u8fdfimport, \u63d0\u4f9b\u4e86bean_id\u548ctype\u4e24\u79cd\u627ebean\u7684\u65b9\u5f0f\r\n\r\nspring.json:\u626b\u63cf\u5e76\u53cd\u5e8f\u5217, \u4f9bBeanFactory\u8bfb\u53d6\r\n\r\n## \u4f7f\u7528\u65b9\u6cd5\r\n\r\n### \u5b89\u88c5pip\u5305 \r\n\r\n pip install pythonic-spring\r\n\r\n### \u521b\u5efa\u5b9e\u4f8b\r\n\r\n from pythonicspring import SpringApplication\r\n app = SpringApplication()\r\n\r\n### \u58f0\u660e\u9700\u8981bean\u5316\u7684\u7c7b, \u4f7f\u7528\u7c7b\u88c5\u9970\u5668:Service\r\n\r\n### \u58f0\u660e\u7c7b\u5185\u9700\u8981\u5f15\u7528\u7684bean, \u5728__init__\u65b9\u6cd5\u4e0a\u4f7f\u7528\u88c5\u9970\u5668:Autowired\r\n\r\n from pythonicspring import Service\r\n from pythonicspring import Autowired\r\n @Service\r\n class ClassA:\r\n \r\n class_b: ClassB = None\r\n class_c: ClassC = None\r\n \r\n @Autowired(bean_modules={\"class_b\": ClassB}, bean_ids={\"class_c\": \"ClassCCC\"})\r\n def __init__(self):\r\n pass\r\n \r\n def foo(self):\r\n result = class_b.spam()\r\n pass\r\n\r\n## \u4e00\u4e2a\u4f8b\u5b50:\r\n\r\ntest/testApp.py\r\n\r\n\r\n\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A python-made framework which is like Spring in Java.",
"version": "0.0.1.5",
"project_urls": {
"Source": "https://github.com/genji9071/pythonic-spring/",
"Tracker": "https://github.com/genji9071/pythonic-spring/issues"
},
"split_keywords": [
"spring",
"pythonic"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "24e7f8f025357eed0e71440ef7a4963a09504bbe827fea61d70a67c9ff30d4df",
"md5": "1cf7a8660dfa4669b292e0a6ac2100f6",
"sha256": "e1614d04903fc1ffd51a1efda521e86c41ae66c4efbf6b3de1b1eae54a989f62"
},
"downloads": -1,
"filename": "pythonic_spring-0.0.1.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "1cf7a8660dfa4669b292e0a6ac2100f6",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 12340,
"upload_time": "2024-08-16T09:19:32",
"upload_time_iso_8601": "2024-08-16T09:19:32.324076Z",
"url": "https://files.pythonhosted.org/packages/24/e7/f8f025357eed0e71440ef7a4963a09504bbe827fea61d70a67c9ff30d4df/pythonic_spring-0.0.1.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "60a5b46bb05d1fc6c9eed3dea76446352722ff1ffecd69070dcd6cae45edb600",
"md5": "13903d7fe6466defc07b8507e0bc6592",
"sha256": "abf426cec50d1c19c7bc85d836c075067711a3ce3aa6974b948f5083c8cfe772"
},
"downloads": -1,
"filename": "pythonic-spring-0.0.1.5.tar.gz",
"has_sig": false,
"md5_digest": "13903d7fe6466defc07b8507e0bc6592",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 8512,
"upload_time": "2024-08-16T09:19:33",
"upload_time_iso_8601": "2024-08-16T09:19:33.601852Z",
"url": "https://files.pythonhosted.org/packages/60/a5/b46bb05d1fc6c9eed3dea76446352722ff1ffecd69070dcd6cae45edb600/pythonic-spring-0.0.1.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-16 09:19:33",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "genji9071",
"github_project": "pythonic-spring",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "pythonic-spring"
}