{"id":16544797,"url":"https://github.com/synchronizing/aconf","last_synced_at":"2025-10-28T15:31:16.235Z","repository":{"id":57407981,"uuid":"308181780","full_name":"synchronizing/aconf","owner":"synchronizing","description":"🤖  Memory-based global configuration settings for Python projects. ","archived":false,"fork":false,"pushed_at":"2020-12-14T17:15:04.000Z","size":4,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-22T09:11:06.275Z","etag":null,"topics":["configuration","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/synchronizing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-10-29T01:11:42.000Z","updated_at":"2021-03-08T20:41:35.000Z","dependencies_parsed_at":"2022-09-26T17:10:50.391Z","dependency_job_id":null,"html_url":"https://github.com/synchronizing/aconf","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/synchronizing%2Faconf","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synchronizing%2Faconf/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synchronizing%2Faconf/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/synchronizing%2Faconf/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/synchronizing","download_url":"https://codeload.github.com/synchronizing/aconf/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219859266,"owners_count":16556036,"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":["configuration","python3"],"created_at":"2024-10-11T19:04:41.581Z","updated_at":"2025-10-28T15:31:15.916Z","avatar_url":"https://github.com/synchronizing.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🤖 Auto Config\n\nMemory-based global configuration for Python projects -- in 10 lines of code (including empty lines). Made with the intention of ridding the need to pass `Config` objects everywhere. Option to use [`namedtupled`](https://namedtupled.readthedocs.io/en/latest/) if wanted.\n\n## Installing\n\n```\npip install aconf\n```\n\n## Why?\n\nHonestly? Because why not. Was tired of having to pass `Config` objects left and right in small personal projects, so created this.\n\n## Using\n\nThis module comes with three main functions:\n\n* `make_config(**kwargs)`: Creates the configuration in memory.\n* `config()`: Loads configuration from memory as standard dictionary.\n* `conf()`: Loads configuration from memory as namedtuple object for cleaner access.\n\n```python\nfrom aconf import make_config, config, conf\n\n# Creates a global configuration that can be accessed by any other portion of the runtime.\nmake_config(database={\"user\": \"admin\", \"password\": \"db_password\", \"host\": \"localhost\", \"port\": \"3306\"}, method=\"GET\")\n\n# Accessing the global configuration as a dictionary.\nprint(config()['database']['user'])\n# \u003e\u003e\u003e admin\n\n# Accessing the global configuration as a namedtuple object.\nprint(conf().database.user)\n# \u003e\u003e\u003e admin\n```\n\nA single file example doesn't encapsulate the usefulness of this module. Instead, imagine the following project:\n\n```\n.\n├── project\n│   ├── __init__.py\n│   ├── config.py\n│   └── functionality.py\n└── main.py\n```\n\n### `config.py`\n\n```python\n\"\"\" 'Config' class to hold our desired configuration parameters. \n\nNote:\n    This is technically not needed. We do this so that the user knows what he/she should pass \n    as a config for the specific project. Note how we also take in a function object - this is\n    to demonstrate that one can have absolutely any type in the global config and is not subjected\n    to any limitations.\n\"\"\"\n\nfrom aconf import make_config\n\nclass Config:\n    def __init__(self, arg, func):\n        make_config(arg=arg, func=func)\n```\n\n### `functionality.py`\n\n```python\n\"\"\" Use of the global configuration through the `conf` function. \"\"\"\n\nfrom aconf import conf\n\nclass Example:\n    def __init__(self):\n        func = conf().func\n        arg = conf().arg\n\n        self.arg = func(arg)\n```\n\n### `main.py`\n\n```python\nfrom project.config import Config\nfrom project.functionality import Example\n\n# Random function to demonstrate we can pass _anything_ to 'make_config' inside 'Config'.\ndef uppercase(words):\n    return words.upper()\n\n# We create our custom configuration without saving it.\nConfig(arg=\"hello world\", func=uppercase)\n\n# We initialize our Example object without passing the 'Config' object to it.\nexample = Example()\nprint(example.arg) \n# \u003e\u003e\u003e \"HELLO WORLD\"\n```\n\n# Performance\n\nAbsolutely no idea. I wrote this for small projects that I don't intend on releasing and so I have not bothered to benchmark it. If anyone runs the number it would be lovely if you reported either as an Issue, or directly by shooting a pull request with this portion of the `README.md` updated. The project in essence does the following:\n\n* `make_config(**kwargs)`: Saves the `kwargs` dictionary and saves it to `globals()`.\n* `config()`: Loads the dictionary from `globals()`.\n* `conf()`: Loads the dictionary from `globals()` and transforms it into `namedtuple`.\n\nIt would be reasonable to assume `conf()` performance is slower than `config()`.\n\n# Project\n\nThis is the entirety of the project, which is inside `__init__.py`. Uses [`namedtuple`](https://docs.python.org/3/library/collections.html#collections.namedtuple):\n\n```python\nimport namedtupled\n\ndef make_config(**kwargs):\n    globals()[\"aconf\"] = kwargs\n\nconf = lambda: namedtupled.map(globals()[\"aconf\"])\nconfig = lambda: globals()[\"aconf\"]\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsynchronizing%2Faconf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsynchronizing%2Faconf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsynchronizing%2Faconf/lists"}