File tree Expand file tree Collapse file tree 2 files changed +33
-6
lines changed
Expand file tree Collapse file tree 2 files changed +33
-6
lines changed Original file line number Diff line number Diff line change 11# Fast Registry
2+ [ ![ ] ( https://img.shields.io/pypi/v/fast-registry.svg )] ( https://pypi.python.org/pypi/fast-registry/ )
3+ [ ![ ] ( https://github.com/danialkeimasi/fast-registry/workflows/tests/badge.svg )] ( https://github.com/danialkeimasi/fast-registry/actions )
4+ [ ![ ] ( https://img.shields.io/github/license/danialkeimasi/fast-registry.svg )] ( https://github.com/danialkeimasi/fast-registry/blob/master/LICENSE )
5+
26A generic class that can be used to register classes or functions, with type hints support.
7+ # Installation
8+
9+ ``` bash
10+ pip install fast-registry
11+ ```
12+
13+ # Register Classes
14+ You can enforce types on your concrete classes, and also use type hints on your text editors:
315
4- # Example
516``` py
617from fast_registry import FastRegistry
718
@@ -11,7 +22,7 @@ class Animal:
1122 raise NotImplementedError
1223
1324
14- # create a registry that requires registered items to implement the Animal interface.
25+ # create a registry that requires registered items to implement the Animal interface:
1526animal_registry = FastRegistry(Animal)
1627
1728@animal_registry (" dog" )
@@ -31,9 +42,25 @@ class Dog:
3142' woof'
3243```
3344
45+ # Register Functions
3446
35- # Installation
47+ You can also use this tool to register functions:
48+ ``` py
49+ from fast_registry import FastRegistry
3650
37- ``` bash
38- pip install fast-registry
51+
52+ registry = FastRegistry()
53+
54+
55+ @registry (" foo" )
56+ def foo ():
57+ return " bar"
58+ ```
59+
60+ ``` sh
61+ >>> registry[" foo" ]
62+ < function foo at 0x7f803c989fc0>
63+
64+ >>> registry["foo"] ()
65+ ' bar'
3966```
Original file line number Diff line number Diff line change 11[tool .poetry ]
22name = " fast-registry"
3- version = " 0.1.3 "
3+ version = " 0.1.5 "
44description = " A generic class that can be used to register classes or functions."
55authors = [" Danial Keimasi <danialkeimasi@gmail.com>" ]
66license = " MIT"
You can’t perform that action at this time.
0 commit comments