
Product
Introducing Socket MCP for Claude Desktop
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.
A Python library for implementing layered architecture with services and dependency injection.
LayeredPy is a Python library built to implement a clean, maintainable layered architecture. It offers support for service-oriented programming and includes built-in dependency injection (DI) to improve code modularity and testability.
layeredpy
tool.Install LayeredPy using pip
:
pip install layered-py
Here’s how you can use LayeredPy in your projects.
Create a service by subclassing the Service
class and use the @register
decorator to register it.
from layered_py.service import Service
from layered_py.decorators import register
@register(singleton=True)
class GreetingService(Service):
def say_hello(self):
print("Hello from LayeredPy!")
With the @inject
decorator, services can be directly injected as attributes of the class. You don’t need to pass them explicitly.
LayeredPy uses lazy loading with the load_all_modules
function to collect all classes with the register annotation. Using this function in a
central point in your software is mandatory so classes that use Inject function properly.
from layered_py.decorators import inject
from layered_py.bootstrap import load_all_modules
class MyApp:
@inject
def run(self, GreetingService):
GreetingService.say_hello() # Directly access the injected service
# Example usage
if __name__ == "__main__":
load_all_modules()
app = MyApp()
app.run()
Hello from LayeredPy!
You can use the built-in layeredpy
CLI tool to create new service boilerplates automatically.
The CLI tool of LayeredPy can create services, repositories, domains and presentation classes
layeredpy createService MyNewService
This command generates the following services/MyNewService.py
file:
from layered_py.service import Service
from layered_py.decorators import register
@register(singleton=True)
class MyNewService(Service):
def setup(self):
pass
def handle(self):
raise NotImplementedError
The same works with the commands: createDomain, createPresentation, and createRepository
layeredpy generate
LayeredPy is capable of creating complete sets of classes for example this command:
layeredpy generate User
will create: UserService, UserRepository, UserModel and UserRoutes with the register annotation so they are DI-ready.
To change the paths where the classes will be generated create a layeredpy_config.yml
in your project root
The .yml File should contain the following:
service_destination: "your_services"
domain_destination: "your_domains"
repository_destination: "your_repositories"
presentation_destination: "your_presentations"
This project is licensed under the MIT License.
For questions or support, feel free to open an issue on the GitHub Issues page. You can find more information on the project repository.
FAQs
A Python library for implementing layered architecture with services and dependency injection.
We found that layered-py demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Product
Add secure dependency scanning to Claude Desktop with Socket MCP, a one-click extension that keeps your coding conversations safe from malicious packages.
Product
Socket now supports Scala and Kotlin, bringing AI-powered threat detection to JVM projects with easy manifest generation and fast, accurate scans.
Application Security
/Security News
Socket CEO Feross Aboukhadijeh and a16z partner Joel de la Garza discuss vibe coding, AI-driven software development, and how the rise of LLMs, despite their risks, still points toward a more secure and innovative future.