Package: pybok
PybokThe Python library to remove all the boilerplate from your code — inspired inhttps://projectlombok.org/🔥InstallationpipinstallpybokUsageThere are multiple useful decorators.ArgsConstructor@ArgsConstructorclassStudent:name:strage:intstudent=Student("John",21)print(student._name)# Johnprint(student._age)# 21Getter@Getter@ArgsConstructorclassStudent:name:strage:intstudent=Student("John",21)print(student.name)# Johnprint(student.age)# 21Setter@Setter@ArgsConstructorclassStudent:name:strage:intstudent=Student("John",21)student.name="Jane"student.age=19print(student._name("Jane"))# Janeprint(student._age_(19))# 19Data@DataclassPerson:name:strage:intp1=Person("John",21)print(p1)# 'Person(name=John,age=21)'print(p1.name)# Johnprint(p1.age)# 21print((hash(p1),hash((p1._name,p1._age)))# Truep1.name="Mike"p1.age=28print(p1._name)# Mikeprint(p1.get_age())# 28Builder@Builder@ArgsConstructorclassPerson:name:strage:intperson=Person.builder().name("John").age(23).build()print(person._name)# Johnprint(person._age# 23EqualsAndHashCode@EqualsAndHashCode@ArgsConstructorclassPerson:name:strage:intp1=Person("John",21)print(hash(p1)==hash((p1._name,p1._age)))# Truep2=Person("Jane",19)print(p1==p2)# Falseprint(p1==p1)# TrueToString@ToString@ArgsConstructorclassPerson:name:strage:intperson=Person("John",21)print(person)# Person(name=John,age=21)ToJSON@ToJSON@ArgsConstructorclassPerson:name:strage:intperson=Person("John",21)print(person.json())# {"name": "John", "age": 21} but prettySingleton@Singleton@ArgsConstructorclassPerson:name:strage:intjohn=Person("John",21)jane=Person("Jane",19)empty=Person()print(john==jane)# Trueprint(john==empty)# TrueUtilityClass@UtilityClassclassMyClass:defutility_method():# whatever you needMyClass()# raises exception (cannot instantiate)With@With@ArgsConstructorclassPerson:name:strage:intperson=Person("Jane",19)same=person.with_name("Jane")another=person.with_age(21)print(person==same)# Trueprint(person==another)# FalseCopy@ArgsConstructorclassEyes:color:str@Copy@ArgsConstructorclassPerson:name:strage:inteyes:Eyesperson=Person("Jane",19,Eyes("blue"))shallow_copy=person.copy()deep_copy=person.deepcopy()print(person._name==shallow_copy._name)# Trueprint(person._age==shallow_copy._age)# Trueprint(person._eyes==shallow_copy._eyes)# Trueprint(person._name==deep_copy._name)# Trueprint(person._age==deep_copy._age)# Trueprint(person._eyes==deep_copy._eyes)# FalseLog@Log@ArgsConstructorclassPerson:name:strage:intdefgreet(self):self.logger.info("{name}greets")@Log@ArgsConstructorclassCat:name:strage:intdefmeow(self):self.logger.warning(f"{name}"meows!)person=Person("Jane",19)person.greet()# 2005-03-23 23:47:11,663 - pybok_app - INFO - Jane greetscat=Cat("Tom",8)cat.meow()# 2005-03-23 23:47:11,663 - pybok_app - WARN - Tom meowsprint(person.logger==cat.logger)# TrueConfigurationPropertiesReads any environment variable that you require. Supports default values as well.Also, you can make it a singleton to inject it wherever you want by using the@Singleton.os.environ[self.DAY]="1"os.environ[self.MONTH]="10"@Singleton@ConfigurationPropertiesclassMyProps:day:strmonth:stryear:str='1991'myprops=MyProps()print(myprops._day)# 1print(myprops._month)# 10print(myprops._year)# 1991my_other_props=MyProps()print(myprops==my_other_props)# TrueContributionPlease readCONTRIBUTION.md.Code of ConductPlease read theContributor Covenant Code of Conduct.LicenseThis project is licensed under theMIT License.