Skip to content

shimech/instance-builder

Repository files navigation

Instance-Builder - Instance builder library for Python inspired by Lombok

Python Versions PyPI version CI

Installation

pip install instance-builder

Usage

Builder

@builder("id", "name", "age", "email")
class User:
    def __init__(self, id: int, name: str, age: int, email: str) -> None:
        self.id = id
        self.name = name
        self.age = age
        self.email = email

user = User.Builder().id(0).name("Shuntaro Shimizu").age(99).email("[email protected]").build()

Getter

@getter
class User:
    __id: int = 0
    __name: str = "Shuntaro Shimizu"

user = User()
user.get_id()  # 0
user.get_name()  # "Shuntaro Shimizu"

Setter

@setter
class User:
    __id: int = 0
    __name: str = "Shuntaro Shimizu"

user = User()
user.set_id(1)  # user._User__id == 1
user.set_name("New Name")  # user._User__name == "New Name"

© Copyright 2021 to Shuntaro Shimizu, under the MIT license