Skip to main content

A Python library for implementing layered architecture with services and dependency injection.

Project description

LayeredPy

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.


Features

  • Layered Architecture: Enables a structured and modular separation of concerns.
  • Dependency Injection: Dependencies get injected automatically, improving testability and reducing tight coupling.
  • Service Management: Defines base services with extensible behavior for your application logic.
  • CLI Tool: Generate service boilerplate with the service tool.

Installation

Install LayeredPy using pip:

pip install layered-py

Getting Started

Here’s how you can use LayeredPy in your projects.


1. Define and Register a Service

Create a service by subclassing the Service class and use the @register_service decorator to register it.

from service_layer.service import Service
from service_layer.decorators import register_service

@register_service("GreetingService")
class GreetingService(Service):
    def say_hello(self):
        print("Hello from LayeredPy!")

2. Inject the Service Where Needed

With the @inject decorator, services can be directly injected as attributes of the class. You don’t need to pass them explicitly.

from service_layer.decorators import inject

class MyApp:
    @inject("GreetingService")
    def run(self):
        self.GreetingService.say_hello()  # Directly access the injected service

# Example usage
if __name__ == "__main__":
    app = MyApp()
    app.run()

Output:

Hello from LayeredPy!


3. Generate Service Templates with the CLI

You can use the built-in service CLI tool to create new service boilerplates automatically.

Example Usage:

service create MyNewService

This command generates the following services/MyNewService.py file:

from service_layer.service import Service

class MyNewService(Service):
    def setup(self):
        pass

    def handle(self):
        raise NotImplementedError

License

This project is licensed under the MIT License.


Support

For questions or support, feel free to open an issue on the GitHub Issues page. You can find more information on the project repository.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

layered_py-1.0.1.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

layered_py-1.0.1-py3-none-any.whl (3.5 kB view details)

Uploaded Python 3

File details

Details for the file layered_py-1.0.1.tar.gz.

File metadata

  • Download URL: layered_py-1.0.1.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for layered_py-1.0.1.tar.gz
Algorithm Hash digest
SHA256 4fc7baa54b3680a5984a6d05634128c7901b0d2090185977ba7b020e467d4888
MD5 51e2623b4a3c1c55646e7ec73adc3438
BLAKE2b-256 31d6498ae516a6076d5d495ec1bcf34d22cc730a4aa96ae90311e9e615ecc943

See more details on using hashes here.

File details

Details for the file layered_py-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: layered_py-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.2

File hashes

Hashes for layered_py-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5148d9fd10daa316ffa90c3c2a2c4f5ef920ee9c12ec2ea017f82380cb31a101
MD5 0c23cea187bd71c564a9f9235cf97e0c
BLAKE2b-256 f395ac35745b35573aa9fcd8a25b4f7b74ef35f1c78aa3e5d844999229d6dea5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page