Spring Python Core
raw JSON → 0.1.5 verified Sat May 09 auth: no python
A Python implementation of the Spring Framework Inversion of Control (IoC) container, providing dependency injection, bean management, and configuration support. Currently at version 0.1.5, released with a monthly cadence. Requires Python 3.11+.
pip install spring-py-core Common errors
error ImportError: cannot import name 'SpringApplication' from 'spring' ↓
cause Using wrong import path. The module uses underscores, not hyphens.
fix
Use 'from spring_py_core import SpringApplication' (underscores).
error AttributeError: module 'spring_py_core' has no attribute 'Component' ↓
cause Component is in the annotations submodule, not directly in spring_py_core.
fix
Use 'from spring_py_core.annotations import Component'.
error TypeError: SpringApplication.run() got an unexpected keyword argument 'class_' ↓
cause Incorrect signature used; run() expects a class reference, not a string.
fix
Use 'SpringApplication.run(App)' where App is a class, not a string.
Warnings
gotcha The package name on PyPI is 'spring-py-core' but the import module uses underscores: 'spring_py_core'. Common installation mistake leads to ImportError. ↓
fix Use 'import spring_py_core' (underscores) after pip installing 'spring-py-core' (hyphens).
gotcha Only Python 3.11+ is supported. Installing on older Python versions will fail. ↓
fix Ensure Python 3.11 or higher is used.
breaking In version 0.1.5, the 'SpringApplication.run()' method no longer accepts a class as a string; it must be a class reference. ↓
fix Pass the class object directly: SpringApplication.run(App)
deprecated The 'XmlBeanFactory' is deprecated in 0.1.5. Use 'AnnotationConfigApplicationContext' instead. ↓
fix Replace 'XmlBeanFactory' with 'AnnotationConfigApplicationContext' and use annotations for configuration.
Imports
- SpringApplication wrong
from spring import SpringApplicationcorrectfrom spring_py_core import SpringApplication - Component wrong
from spring_py_core import Componentcorrectfrom spring_py_core.annotations import Component - Autowired
from spring_py_core.annotations import Autowired
Quickstart
from spring_py_core import SpringApplication
from spring_py_core.annotations import Component, Autowired
@Component
class Greeter:
def greet(self):
return "Hello, Spring!"
@Component
class App:
@Autowired
def __init__(self, greeter: Greeter):
self.greeter = greeter
def run(self):
print(self.greeter.greet())
if __name__ == "__main__":
SpringApplication.run(App)