{"id":25543474,"url":"https://github.com/josephp27/zeno","last_synced_at":"2025-04-11T17:50:22.015Z","repository":{"id":39922491,"uuid":"303534610","full_name":"josephp27/Zeno","owner":"josephp27","description":"An Object Config Mapper (OCM) for Python","archived":false,"fork":false,"pushed_at":"2022-10-07T08:04:08.000Z","size":152,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-02-18T23:34:47.651Z","etag":null,"topics":["config-mapper","configuration","dictionaries","ini","map-zeno","ocm","orm","parser","settings","settings-management","types","yaml","yml","zeno"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/josephp27.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-12T23:14:10.000Z","updated_at":"2022-07-07T04:10:13.000Z","dependencies_parsed_at":"2022-09-18T20:21:44.602Z","dependency_job_id":null,"html_url":"https://github.com/josephp27/Zeno","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josephp27%2FZeno","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josephp27%2FZeno/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josephp27%2FZeno/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/josephp27%2FZeno/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/josephp27","download_url":"https://codeload.github.com/josephp27/Zeno/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239793071,"owners_count":19697893,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["config-mapper","configuration","dictionaries","ini","map-zeno","ocm","orm","parser","settings","settings-management","types","yaml","yml","zeno"],"created_at":"2025-02-20T07:19:33.781Z","updated_at":"2025-02-20T07:19:34.846Z","avatar_url":"https://github.com/josephp27.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Zeno | An Object Config Mapper (OCM) \n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://app.travis-ci.com/github/josephp27/Zeno\"\u003e\u003cimg src=\"https://app.travis-ci.com/josephp27/Zeno.svg?branch=main\" alt=\"Build\" height=\"18\"\u003e\u003c/a\u003e\n\u003ca href=\"https://badge.fury.io/py/ZenoMapper\"\u003e\u003cimg src=\"https://badge.fury.io/py/ZenoMapper.svg\" alt=\"PyPI version\" height=\"18\"\u003e\u003c/a\u003e\n\u003ca href=\"https://pepy.tech/project/zenomapper\"\u003e\u003cimg src=\"https://pepy.tech/badge/zenomapper\" alt=\"Downloads\" height=\"18\"\u003e\u003c/a\u003e\n\u003cimg src=\"https://img.shields.io/badge/License-Apache%202.0-blue.svg\" alt=\"License\" height=\"18\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## I heard you like ORMs, so I got you an OCM.\n\nThe idea for this comes from ORMs like SqlAlchemy and how Spring Boot uses `@ConfigurationProperties`\n\n| Library Version| Python     |\n| :------------- | :----------: |\n| 1.x.x | 2.7, 3.5+   |\n| 0.x (Beta) | 2.7, 3.5+   |\n\nZeno maps your configs to objects for you.\n```yaml\nSpring:\n  Data:\n    MongoDb:\n      database: TESTDB\n      encryption: true\n      encryptionKey: \"FakePassWord!\"\n      password: \"!54353Ffesf34\"\n      replicaSet: FAKE-DB-531\n    second: 1\n    myList:\n      - first\n      - second\n      - third\n\nMyServer:\n  host: my.server.com\n  port: 8080\n```\nLooks like\n```python\nclass Spring(Configuration): #Inheriting from Configuration lets the parser know which class to modify\n    \"\"\"\n    loads in from data.yml. accessing nested sections can be done via nested classes\n    \"\"\"\n\n    class Data:\n        class MongoDb:\n            database = String()\n            encryption = Boolean()  # conversion automatically happens when specifying the type\n            encryptionKey = String()\n            password = String()\n            replicaSet = String()\n\n        second = Integer()\n        myList = List()\n```\nAnd can now be accessed like:\n```python\nspring = Spring()\nspring.Data.myList  # ['first', 'second', 'third']\nspring.Data.MongoDb.encryption is True  # True\n```\n## Autocompletion\nClasses give you autocompletion in your favorite IDE for all your config files\n```python\nclass MyServer(Configuration):\n    host = String()\n    port = Integer()\n```\n\n![Autocomplete](examples/autocomplete-ide.png)\n## Don't Like Classes?\nClasses are a powerful way for autocompletion, type hints and auto conversion to those types. However, if it isn't for you, calling Zeno directly can be done. The parameter to the constructor is the path within the dictionary. If no parameter is set, it will map the whole dictionary. More examples can be found [here](https://github.com/josephp27/Zeno/blob/231bb39d884cc8f30a742c68da7c6b1121128214/examples/impl.py#L61)\n```python\nfrom ZenoMapper.zeno import Zeno\n\nzeno = Zeno('Spring.Data.MongoDb')\nzeno.database  # TESTDB\n```\n## Install\n```bash\npip install ZenoMapper\n```\n\n## Import\n```python\nfrom ZenoMapper.Configuration import ConfigParser, Configuration\nfrom ZenoMapper.Types import String, Boolean, Integer, List\n```\n### Using \\_\\_section\\_\\_ to map super nested dictionaries/ignore nesting classes\n```python\nclass MyConfig(Configuration):\n    __section__ = 'Spring.Data.Mongodb'\n    \n    database = String()\n    encryption = Boolean()\n    encryptionKey = String()\n    password = String()\n    replicaSet = String()\n```\n## Using your custom configs with Zeno\nUsing your own configs is easy with Zeno, simply inherit from ConfigParser and instantiate the `get_config()` function. Load in your file and Zeno will do the rest.\n```python\nclass MyConfig(ConfigParser):\n    \"\"\"\n    loading your own config is done via subclassing the ConfigParser class and implementing the\n    get_config function.\n    \n    each time an object is instantiated, this is called, so cache the results to increase performance with the @lru_cache decorator\n    \"\"\"\n\n    @staticmethod\n    @lru_cache(maxsize=None)  # @cache if you're on python3.9 or later\n    def get_config():\n        with open(\"data.yml\", 'r') as stream:\n            return yaml.safe_load(stream)\n```            \n## Types\nZeno currently has 4 types, where auto conversion will happen based on the specified type. It also brings a little static typing to Python. The plan is to add more, but currently Zeno supports: `Integer`, `String`, `Boolean`, `List`. Supported types can be found [here](https://github.com/josephp27/Zeno/blob/main/ZenoMapper/Types.py)\n\nIf you have another type you'd like but it isn't supported, etc. `None` can be used to tell Zeno to not handle conversion\n\n### Custom Types\nUsers can specify their own types by inheriting from ConfigTypes\n```python\nclass AppConf(ConfigTypes):\n    \"\"\"\n    AppConf class to be used with Configuration class\n    \"\"\"\n\n    def __init__(self, name, to_type):\n        self.name = name\n        self.convert_to_type = to_type\n\n    def convert(self, obj):\n        \"\"\"Method called to convert obj to its specified convert type\n        NOTE: if the environment is production, it will first get it from appconf\n              and override the one in the config file\n\n        Required Args:\n            obj (obj) - The object to be converted\n\n        returned:\n            obj - The object as the specified type\n        \"\"\"\n        if os.environ.get('ENVIRONMENT') == 'production':\n            # we are in production and using appconf to get our values\n            obj = parse_appconf()[self.name]\n\n        # now convert it to the specified to_type\n        return self.convert_to_type().convert(obj)\n```\nand then can be called like the other types\n```python\nclass Database(Configuration):\n    \"\"\"section for database\"\"\"\n    __project__ = 'my_project'\n\n    dbname = String()\n    # you can even send in another type to do a later conversion within your new type\n    host = AppConf('host', String)\n    port = AppConf('port', Integer)\n```\n## Choosing what to map\nZeno is powerful. Only specify what you'd like to map and Zeno ignores the rest\n```python\nclass Spring(Configuration):\n    class Data:\n        class MongoDb:\n            database = String()\n```\n\n## Hold up, that's nice but I still like using dictionary methods\nWell then person reading this, Zeno is for you. All Classes are dictionary class hybrids, so you can access them like plain old dictionaries when necessary.\n```python\nspring.Data.myList # ['first', 'second', 'third']\nspring['Data']['myList'] # ['first', 'second', 'third']\nspring['Data'].myList # ['first', 'second', 'third']\nspring.Data['myList'] # ['first', 'second', 'third']\nspring # {'Data': {'MongoDb': {'database': 'TESTDB', 'encryption': True, 'encryptionKey': 'FakePassWord!', 'password': '!54353Ffesf34', 'replicaSet': 'FAKE-DB-531'}, 'second': 1, 'myList': ['first', 'second', 'third']}}\n```\n\n## Don't Break Python Naming Conventions!\nClasses can fuzzy match while not breaking Python's class naming conventions\n```yaml\nlower:\n  case_section: true\n```\n```python\nclass Lower(Configuration):\n    CaseSection = Boolean()\n```\n\n## Supports\n- Any parser \n  - YAML\n  - INI\n  - etc, as long as it parses into a dictionary\n- Automatic type conversion\n- Custom conversion classes\n- All Python 3 versions and 2.7\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosephp27%2Fzeno","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjosephp27%2Fzeno","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjosephp27%2Fzeno/lists"}