{"id":19626107,"url":"https://github.com/deepsourcecorp/import-x","last_synced_at":"2025-04-28T05:33:10.724Z","repository":{"id":54128899,"uuid":"184094591","full_name":"DeepSourceCorp/import-x","owner":"DeepSourceCorp","description":"Import anything like it is a python module","archived":false,"fork":false,"pushed_at":"2021-11-08T08:00:01.000Z","size":11,"stargazers_count":39,"open_issues_count":0,"forks_count":6,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-10-11T14:46:11.681Z","etag":null,"topics":["import","import-hook","json","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DeepSourceCorp.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":"2019-04-29T15:15:29.000Z","updated_at":"2024-04-02T17:41:40.000Z","dependencies_parsed_at":"2022-08-13T07:10:11.912Z","dependency_job_id":null,"html_url":"https://github.com/DeepSourceCorp/import-x","commit_stats":null,"previous_names":["deepsourcelabs/import-x"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepSourceCorp%2Fimport-x","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepSourceCorp%2Fimport-x/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepSourceCorp%2Fimport-x/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DeepSourceCorp%2Fimport-x/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DeepSourceCorp","download_url":"https://codeload.github.com/DeepSourceCorp/import-x/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224098465,"owners_count":17255507,"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":["import","import-hook","json","python"],"created_at":"2024-11-11T11:44:59.053Z","updated_at":"2024-11-11T11:45:00.223Z","avatar_url":"https://github.com/DeepSourceCorp.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://deepsource.io/images/logo-wordmark-dark.svg\" /\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://deepsource.io/docs\"\u003eDocumentation\u003c/a\u003e |\n  \u003ca href=\"https://deepsource.io/signup\"\u003eGet Started\u003c/a\u003e |\n  \u003ca href=\"https://gitter.im/deepsourcelabs/lobby?utm_source=share-link\u0026utm_medium=link\u0026utm_campaign=share-link\"\u003eDeveloper Chat\u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  DeepSource helps you ship good quality code.\n\u003c/p\u003e\n\n\u003c/p\u003e\n\n---\n\n# import-x\n\nAn ext-tensible loader to import anything like it is a python module.\n\nSupports Python **3.6+**.\n\n## Installation\n\n```\npip install import-x\n```\n\n## Usage\n\nExample json file in your path ``foo.json``:\n\n```json\n    {\n        \"why\": \"not\",\n    }\n```\n\n```python\n   # Extend the ExtensionLoader and implement 'handle_module' method\n   # where you will get a module object and the path to that module.\n\n   \u003e\u003e\u003e from import_x import ExtensionLoader\n\n   \u003e\u003e\u003e class JsonLoader(ExtensionLoader):\n        extension = '.json'\n\n        auto_enable = False\n\n        @staticmethod\n        def handle_module(module, path):\n            \"\"\"\n            Load the json file and set as `data` attribute of the module.\n            \"\"\"\n            json_file = Path(path)\n            content = json_file.read_text()\n            try:\n                data = json.loads(content)\n            except (json.JSONDecodeError, ValueError):\n                data = {}\n            module.data = data\n\n    \u003e\u003e\u003e json_imports = JsonLoader()\n    \u003e\u003e\u003e with json_imports:\n            import foo\n    \u003e\u003e\u003e foo.data\n    \u003e\u003e\u003e {\"why\": \"not\"}\n```\n\nIf you want to enable imports automatically without the context_manager then just\ndo ``auto_enable = True`` in your loader.\n\nThis Example ``JsonLoader`` can be used directly by importing\n\n```python\n    from import_x.loaders.json_loader import JsonLoader\n```\n\nand you are ready to import all the json files.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepsourcecorp%2Fimport-x","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdeepsourcecorp%2Fimport-x","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdeepsourcecorp%2Fimport-x/lists"}