{"id":16285583,"url":"https://github.com/tonyfast/importable","last_synced_at":"2025-04-09T03:21:40.473Z","repository":{"id":75804110,"uuid":"95625619","full_name":"tonyfast/importable","owner":"tonyfast","description":"Import Jupyter notebooks and other files into Python","archived":false,"fork":false,"pushed_at":"2017-11-05T04:08:07.000Z","size":83,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-14T21:47:15.536Z","etag":null,"topics":["import","jupyter-notebook","python"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","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/tonyfast.png","metadata":{"files":{"readme":"readme.ipynb","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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-28T03:38:13.000Z","updated_at":"2017-07-24T00:31:06.000Z","dependencies_parsed_at":"2023-05-12T17:15:41.471Z","dependency_job_id":null,"html_url":"https://github.com/tonyfast/importable","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/tonyfast%2Fimportable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonyfast%2Fimportable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonyfast%2Fimportable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tonyfast%2Fimportable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tonyfast","download_url":"https://codeload.github.com/tonyfast/importable/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247969234,"owners_count":21025937,"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","jupyter-notebook","python"],"created_at":"2024-10-10T19:25:17.870Z","updated_at":"2025-04-09T03:21:40.446Z","avatar_url":"https://github.com/tonyfast.png","language":"Jupyter Notebook","readme":"{\n \"cells\": [\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"# importable \\n\",\n    \"\\n\",\n    \"`pip install git+`\u003ca href=\\\"https://github.com/tonyfast/importable\\\"\u003e\u003ccode\u003ehttps://github.com/tonyfast/importable\u003c/code\u003e\u003c/a\u003e\\n\",\n    \"\\n\",\n    \"\u003e __importable__ is an IPython magic that permits python imports from notebook sources. [See the source.](https://github.com/tonyfast/importable/blob/master/importable.ipynb)\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 2,\n   \"metadata\": {\n    \"collapsed\": true\n   },\n   \"outputs\": [],\n   \"source\": [\n    \"    %reload_ext importable \"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 3,\n   \"metadata\": {\n    \"scrolled\": false\n   },\n   \"outputs\": [\n    {\n     \"data\": {\n      \"text/plain\": [\n       \"(42, \u003cmodule 'readme' from './readme.ipynb'\u003e, './readme.ipynb')\"\n      ]\n     },\n     \"execution_count\": 3,\n     \"metadata\": {},\n     \"output_type\": \"execute_result\"\n    }\n   ],\n   \"source\": [\n    \"    foo = 42\\n\",\n    \"    import readme\\n\",\n    \"    readme.foo, readme.readme, readme.__file__\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"Once __importable__ is loaded any notebook can be used as source.  For example, [literacy](https://github.com/tonyfast/literacy) is a literate programming extension for the notebook [written with notebooks as source](https://github.com/tonyfast/literacy/blob/master/literacy/__init__.py#L1).\\n\",\n    \"\\n\",\n    \"__importable__ works in Python 2 and 3, reloading only works in python 3.\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"# Installation\\n\",\n    \"\\n\",\n    \"`pip install git+`\u003ca href=\\\"https://github.com/tonyfast/importable\\\"\u003e\u003ccode\u003ehttps://github.com/tonyfast/importable\u003c/code\u003e\u003c/a\u003e\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"## Advanced: Custom Finder\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 4,\n   \"metadata\": {\n    \"collapsed\": true\n   },\n   \"outputs\": [],\n   \"source\": [\n    \"    from importable import finder\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 5,\n   \"metadata\": {},\n   \"outputs\": [],\n   \"source\": [\n    \"    if __name__ == '__main__':\\n\",\n    \"        with open('test_file.json', 'w') as f: __import__('json').dump(['foo', 'bar'], f)\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 6,\n   \"metadata\": {\n    \"collapsed\": true\n   },\n   \"outputs\": [],\n   \"source\": [\n    \"    @finder('json')\\n\",\n    \"    def load_json(self, path):\\n\",\n    \"        \\\"\\\"\\\"Import files ending in json\\\"\\\"\\\"\\n\",\n    \"        return \\\"\\\"\\\"with open('{}') as f: data = __import__('json').load(f)\\n\",\n    \"        \\\"\\\"\\\".strip().format(self.path)\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 7,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"data\": {\n      \"text/plain\": [\n       \"['foo', 'bar']\"\n      ]\n     },\n     \"execution_count\": 7,\n     \"metadata\": {},\n     \"output_type\": \"execute_result\"\n    }\n   ],\n   \"source\": [\n    \"    import test_file\\n\",\n    \"    test_file.data\"\n   ]\n  },\n  {\n   \"cell_type\": \"code\",\n   \"execution_count\": 9,\n   \"metadata\": {},\n   \"outputs\": [\n    {\n     \"name\": \"stdout\",\n     \"output_type\": \"stream\",\n     \"text\": [\n      \"[NbConvertApp] Converting notebook readme.ipynb to markdown\\r\\n\",\n      \"[NbConvertApp] Writing 2212 bytes to readme.md\\r\\n\"\n     ]\n    }\n   ],\n   \"source\": [\n    \"    if True and __name__ == '__main__':        \\n\",\n    \"        !jupyter nbconvert --to markdown readme.ipynb\"\n   ]\n  },\n  {\n   \"cell_type\": \"markdown\",\n   \"metadata\": {},\n   \"source\": [\n    \"## References\\n\",\n    \"\\n\",\n    \"* http://brandonio21.com/2016/10/custom-fileextension-path-based-importers-in-python/\\n\",\n    \"* https://chaobin.github.io/2015/06/22/understand-import-system-of-python/\\n\",\n    \"* http://xion.org.pl/2012/05/06/hacking-python-imports/\\n\",\n    \"* https://android.googlesource.com/toolchain/benchmark/+/master/python/src/Demo/imputil/importers.py\\n\",\n    \"* https://docs.python.org/2.7/library/imputil.html\\n\",\n    \"* PEPs: [302](https://www.python.org/dev/peps/pep-0302/), [420](https://www.python.org/dev/peps/pep-0420/), [451](https://www.python.org/dev/peps/pep-0451/)\"\n   ]\n  }\n ],\n \"metadata\": {\n  \"kernelspec\": {\n   \"display_name\": \"Python 3\",\n   \"language\": \"python\",\n   \"name\": \"python3\"\n  },\n  \"language_info\": {\n   \"codemirror_mode\": {\n    \"name\": \"ipython\",\n    \"version\": 3\n   },\n   \"file_extension\": \".py\",\n   \"mimetype\": \"text/x-python\",\n   \"name\": \"python\",\n   \"nbconvert_exporter\": \"python\",\n   \"pygments_lexer\": \"ipython3\",\n   \"version\": \"3.5.3\"\n  }\n },\n \"nbformat\": 4,\n \"nbformat_minor\": 2\n}\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftonyfast%2Fimportable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftonyfast%2Fimportable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftonyfast%2Fimportable/lists"}