PyBean
1. What is this?
This is a Python module implementation of IOC container management.
You can read your XML files and dynamically manage your Python classes through the "Application Context" class. In order to help those familiar with Java Spring understand quickly, I plan to try to adapt to the rules in Spring as much as possible in the future.
2.How to use?
For Developers, ensure that Python is installed on your device and that the environment is ready.
Download in shell by pip:
pip install pyBean
or
pip3 install pyBean
File structure
project
+-- dao
| +-- __init__.py
| +-- person.py
|
+-- resource
| +-- applicationContext.xml
+-- main.py
Prepare the classes you want to inject
# person.py
class PersonDao:
def __init__(self, name):
self.name = name
self.home = ""
def greet(self):
sentence = f"Hey {self.name}!"
if self.home:
sentence += f" {self.home} is a good place!"
print(sentence)
Prepare the XML file, named applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans resource="https://pypi.org/project/pyBean/">
<bean id="me" class="dao.person.PersonDao">
<!--person name-->
<constructor-arg value="Lee"/>
<!--you can change it to your region here.-->
<property name="home" value="China"/>
</bean>
</beans>
In your python file:
# main.py
from PyBean.ioc import ApplicationContext, ApplicationMode
if __name__ == '__main__':
actx = ApplicationContext('resource/applicationContext.xml')
personGet = actx.getBean("me")
personGet.greet()
Run it.
python main.py
or
python3 main.py
Hey Lee! China is a good place!
You can turn on development mode to ensure that each getBean operation will re-read the latest content in the XML.
actx = ApplicationContext('resource/applicationContext.xml',
applicationMode=ApplicationMode.development)
or
actx.set__mode(ApplicationMode.development)
You can add a second type parameter to getBean to constrain the obtained object to belong to that type. Of course, make sure that the type name in your XML is an absolute class path.
from dao.person import PersonDao
personGet = actx.getBean("me", requiredType=PersonDao)
website: https://space.bilibili.com/178065252
pypi: https://pypi.org/project/pyBean/
repository: https://github.com/Liruochen1207/PyBean
Metadata
Release files for pyBean 0.0.26
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyBean-0.0.26.tar.gz | 8.6 kB | Without provenance | Details for pyBean-0.0.26.tar.gz |
Release files / pyBean-0.0.26.tar.gz
| Download URL | pyBean-0.0.26.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a050b1c18c211886a68572e132bd1774dcff8500e4a0c416fd5c6b5d15695905
|
|
BLAKE2b-256 checksum How to use checksums |
3e7967e2613f040384590a570cc29c7ce72ffba8ab3b0df4bea3dc0942073e3f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.2
|
Security for pyBean 0.0.26
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.