Skip to main content

pspring

This is a lightweight framework to enable python developers to quickly develop apps with annotations/decorators. Inspired by Spring Framework of Java, the framework provides the ability for IOC ( Inversion of control ) and Autowiring the beans.

The default environment variables can always be found defaultvars.py file

Below is the index the annotations/decorators supported by this module

  • @Bean(name="")

    This decorator will register the class or method ( which returns an instance of bean ) to the pspring application context. You can provide an optional name attribute to register the bean with a qualified name. Providing no name would register the bean for its type ( and its base classes )

  • @Autowired(name=beanname)

    This decorator is the heard of dependency injection and will autowire the arguments of a method ( especially used in __init__ constructor ). You can provide a list of name value pairs where, name is the argument name in the method definition for which a bean named beanname would be injected with that qualifier.

Configuration Framework

Configuring applications can get complicated with environment variables, default variables and various source of configurations ( like secrets, encrypted variables etc ).

pspring brings a configuration framework which can be used exhaustively for developing cloud applications. The idea in Configuration framework is to provide a standard interface for applications to fetch properties.

The two classes which forms the backbone of this framework are Configuration and ConfigurationProvider. During the application start up, the framework needs to be initialized with a list of ConfigurationProviders as shown below

from pspsring import Configuration, ConfigurationProvider

config = {
	"firstname" : "dave",
	"lastname" : "picaso"
}

# A simple dictionary based config provider
class DictionaryConfigurationProvider(ConfigurationProvider):
	def getProperty(propertyName):
		return config.get(propertyName)

Configuration.initialize([
	DictionaryConfigurationProvider()
])

config = Configuration.getConfig(__name__)

# will print 'dave'
print(config.getProperty("firstname"))

Within a module, the configuration provides a means for namespace to avoid property name conflicts.

Example:

from pspsring import Configuration
config = Configuration.getConfig(__name__)

print(config.getProperty("firstname"))

In the above code, we create a configiration accessor instance by passing in the module name ( name ). This will create a namespace under which the property lives. For Eg: if the file is saved under the package as com/example/application.py, the property name will be actually referenced as com.example.application.firstname.

when getProperty method is invoked

1) the property is looked up in environment variables
2) the property is searched in the given list of ConfigurationProviders during initialization
3) the property is searched in the defaults
4) Search the property one above the hierarchy in the namespace starting from step 1. ( Eg: com.example.firstname )

The above search sequence is pursued until the property is found. If the property is not found,then None is returned.

pspring along with pspring-aws provides a wealth of ConfigurationProviders ( SecretsMgrConfigProvider, DynamodbConfigProvider, RealTimeSecretsMgrConfigProvider etc...) that can be used with aws.

Usage

The context of pspring should be initialized before any dependency injection is expected. A sample of code is show below

import sys,os

from pspring import *

config = Configuration.getConfig(__name__)

@Bean(name="loggerBeanName")
class Logger():
  def __init__():
    pass

  def sayHi(self,name):
    print("Hi "+str(name));

class MyApp():
  @Autowired(mylogger="loggerBeanName")
  def __init__(self,mylogger:Logger):
    self.logger = mylogger

os.environ["name"] = "dave"

Configuration.initialize([])

ApplicationContext.initialize()


app = MyApp()

# prints "Hi dave"
app.logger.sayHi(config.getProperty("name"))

Metadata

Release files for pspring 0.0.39

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pspring 0.0.39
File Size Uploaded Provenance Actions
pspring-0.0.39.tar.gz 7.7 kB Without provenance Details for pspring-0.0.39.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pspring 0.0.39
File Interpreter ABI Platform Actions
pspring-0.0.39-py3-none-any.whl Python 3 none any Details for pspring-0.0.39-py3-none-any.whl

Total release size: 15.5 kB

Release files / pspring-0.0.39.tar.gz

Download URL pspring-0.0.39.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
1f4049c10410f7992fd44d9ce68e67116ac1638ffbd92e8b444098a46686c1cb
BLAKE2b-256 checksum
How to use checksums
ff9717ed7f27b971305852623c891fed144d9fe02b89e94c790d3a201a91b5e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Release files / pspring-0.0.39-py3-none-any.whl

Download URL pspring-0.0.39-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b4da6334582d6df27f63a5d06c4a47fa966c57a93644e27e0392b86d67b959e5
BLAKE2b-256 checksum
How to use checksums
d9b63dbb11f0eb932bea45430343f9163cc740e779c8c2feb513b827aecf9363
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.47.0 CPython/3.8.3

Security for pspring 0.0.39

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.

Release history Release notifications | RSS feed

This release

0.0.39 This release

2 release files No provenance

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