Socket
Book a DemoInstallSign in
Socket

pytidy

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pytidy

Dependency Injection library based on type hints

0.4.0
pipPyPI
Maintainers
1

Build Status Coverage Status

Pytidy

A type hint based dependency injection library for python language (+3.6). While there are already several DI libraries for python, this library is inspired by Java Spring and aims to provide similar interface and functionality to Java Spring.

Supports Python 3.7 and 3.8.

Usage

Super simple. Attach @component decorator to any classes which need to be injected in somewhere constructor, and attach @autowired decorator to constructors which need dependency injection.

from pytidy.decorators import component, autowired


@component
class Hello:
    def say(self):
        print("Hello")


class Injected:
    @autowired
    def __init__(self, instance: Hello):
        self.instance = instance

    def say_proxy(self):
        self.instance.say()


a = Injected()
a.say_proxy()

Also supports dataclass of Python3.7+.

from dataclasses import dataclass
from pytidy.decorators import component, autowired_cls


@component
class Hello:
    def say(self):
        print("Hello")


@autowired_cls
@dataclass
class Injected:
    instance: Hello

    def say_proxy(self):
        self.instance.say()


a = Injected()
a.say_proxy()

License

MIT

FAQs

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.