Created
April 17, 2023 03:44
-
-
Save la4gia/391970eabdd84fb345df819fad3e3dd9 to your computer and use it in GitHub Desktop.
Python Plugin Framework
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from plugin_ingestor import PluginIngestor | |
class FirstPlugin(PluginIngestor): | |
ATTRIBUTES = { | |
'name': 'John Doe', | |
'age': 22, | |
'languages': ['English', 'Japanese'], | |
'clients': {'joe': 'somebody'} | |
} | |
def run(self): | |
self.execute() | |
if __name__ == "__main__": | |
go = FirstPlugin() | |
go.run() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cerberus import Validator | |
import yaml | |
with open('plugin_schema.yml', 'r') as h: | |
schema = yaml.safe_load(h.read()) | |
class PluginIngestor: | |
ATTRIBUTES = {} | |
ATTRIBUTE_SCHEMA = schema | |
def __init__(self): | |
self._validate_schema() | |
def _validate_schema(self): | |
v = Validator(self.ATTRIBUTE_SCHEMA, require_all=True) | |
v.validate(self.ATTRIBUTES) | |
if v.errors: | |
exit(f"Attributes does not match schema. Fix: {v.errors}") | |
def execute(self): | |
print(f'Created character:', self.ATTRIBUTES) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: | |
type: string | |
age: | |
type: integer | |
languages: | |
type: [string, list] | |
clients: | |
type: dict |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment