{ "info": { "author": "Raimi bin Karim", "author_email": "raimi.bkarim@gmail.com", "bugtrack_url": null, "classifiers": [ "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6" ], "description": "\n# p2j - Python to Jupyter Notebook [![PyPI version](https://badge.fury.io/py/p2j.svg)](https://badge.fury.io/py/p2j)\n\nConvert your Python source code to Jupyter notebook with zero intervention.\n\nSee an example of a [Python source code](p2j/examples/example2.py) and its [Jupyter notebook](p2j/examples/example2.ipynb) after converting.\n\nThe purpose of this package is to be able to run a code on Jupyter notebook without having to copy each paragraph of the code into every cell. It's also useful if we want to run our code in Google Colab. This parser isn't perfect, but you would be satisfactorily pleased with what you get.\n\nContents of this README:\n\n- [Installing](##Installation)\n- [Running](##Running)\n- [Tests](##Tests)\n- [Requirements](##Requirements)\n- [Code format](##Code-Format)\n- [How it works](##How-it-works)\n- [Feedback and pull requests](##Feedback-and-pull-requests)\n\n## Installation\n\n```bash\npip install p2j\n```\n\n## Running\n\n```bash\np2j train.py\n```\n\nand you will get a `train.ipynb` Jupyter notebook.\n\nTo run examples from this repository, first clone this repo\n\n```bash\ngit clone https://github.com/raibosome/python2jupyter.git\n```\n\nand after you `cd` into the project, run\n\n```bash\np2j examples/example.py\n```\n\nThe `p2j/examples/example.py` is a Keras tutorial on building an autoencoder for the MNIST dataset, found [here](https://github.com/keras-team/keras/blob/master/examples/mnist_denoising_autoencoder.py).\n\n#### Command line usage\n\nTo see the command line usage, run `p2j -h` and you will get something like this:\n\n```txt\np2j [-h] [-t target_filename] [-o] source_filename\n\nrequired arguments:\n source_filename Python script to parse\n\noptional arguments:\n -h, --help Show this help message and exit\n -t, --target_filename Target filename of Jupyter notebook\n If not specified, it will use the filename of\n the Python script and append .ipynb\n -o, --overwrite Flag whether to overwrite existing target file.\n Defaults to false\n```\n\n## Requirements\n\n- Python 3.6\n\nNo third party libraries are used.\n\n## Tests\n\nTested on macOS 10.14.3 with Python 3.6.\n\n## Code format\n\nThere is no specific format that you should follow, but generally the parser assumes a format where your code is paragraphed. Check out some examples of well-documented code (and from which you can test!):\n\n- [PyTorch Tutorials](https://pytorch.org/tutorials/beginner/pytorch_with_examples.html)\n- [Keras Examples](https://github.com/keras-team/keras/tree/master/examples)\n- [Scikit Learn Example](https://scikit-learn.org/stable/auto_examples/classification/plot_digits_classification.html#sphx-glr-auto-examples-classification-plot-digits-classification-py)\n\n## How it works\n\nJupyter notebooks are just JSON files, like below. A Python script is read line by line and a dictionary of key-value pairs are generated along the way, using a set of rules. Finally, this dictionary is dumped as a JSON file whose file extension is `.ipynb`.\n\n```json\n{\n \"cells\": [\n {\n \"cell_type\": \"markdown\",\n \"execution_count\": null,\n \"metadata\": {},\n \"outputs\": [],\n \"source\": [\n \"# Import standard functions\"\n ]\n },\n {\n \"cell_type\": \"code\",\n \"metadata\": {},\n \"source\": [\n \"import os\"\n ]\n },\n ],\n \"metadata\": {},\n \"nbformat\": 4,\n \"nbformat_minor\": 2\n}\n```\n\nThere are 4 basic rules (and exceptions) that I follow to parse the Python script.\n\n### 1. Code or comment\n\nFirstly, any line that starts with a `#` is marked as a comment. So this will be a **markdown cell** in the Jupyter notebook. Everything else that does not start with this character is considered code, so this goes to the **code cell**. There are of course exceptions.\n\nThis is a comment\n\n```python\n# Train for 4 epochs\n```\n\nand this is code\n\n```python\nmodel.train(4)\n```\n\n### 2. Blocks of code and comment\n\nSecondly, code or comment can occur in blocks. A block of comment is several *consecutive* lines of comments that start with `#`. Similarly, several *consecutive* lines of codes that do not start with `#` will be considered as 'a block of code'. This rule is important because we want to ensure that a block of code or comment stays in one cell.\n\nThis is a block of comment\n\n```python\n# Load the model and\n# train for 4 epochs and\n# lastly we save the model\n```\n\nand this is a block of code\n\n```python\nmodel.load()\nmodel.train(4)\nmodel.save()\n```\n\n### 3. Paragraph\n\nThirdly, I assume that everyone writes his/her script in paragraphs, where each paragraph represents an idea. In a paragraph, there can be code or comments or both.\n\nThe following are 5 examples of paragraphs.\n\n```python\n# Evaluate the model\nmodel.evaluate()\n\n# Run the model for a while.\n# Then we hide the model.\nrun()\nhide()\n\nprint(type(data))\n\n# This is considered as a paragraph too\n# It has 2 lines of comments\n\n# The data that we are interested in is made of 8x8 images of digits.\n# Let's have a look at the first 4 images, which is of course\n# stored in the `images` attribute of the dataset. \nimages = list(zip(mnist.images))\n```\n\n### 4. Indentation\n\nAny line of code or comment that is indented by a multiple of 4 spaces is considered code, and will stay in the same code cell as the previous non-empty line. This ensures that function and class definitions, loops and multi-line code stay in one cell.\n\n### 5. Exceptions\n\nNow we handle the exceptions to the above-mentioned rules.\n\n- Docstrings are considered as **markdown cells**, only if they are not indented.\n\n- Lines that begin with `#pylint` or `# pylint` are Pylint directives and are kept as **code cells**.\n\n- Shebang is considered as a **code cell**, eg. `#!/usr/bin/env python3`.\n\n- Encodings like `# -*- coding: utf-8 -*-` are also considered as **code cells**.\n\n## Feedback and pull requests\n\nIf you do like this, star me maybe? Pull requests are very much encouraged! Slide into my DM with suggestions too!\n\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/raibosome/python2jupyter", "keywords": "convert python jupyter notebook script", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "p2j", "package_url": "https://pypi.org/project/p2j/", "platform": "", "project_url": "https://pypi.org/project/p2j/", "project_urls": { "Homepage": "https://github.com/raibosome/python2jupyter" }, "release_url": "https://pypi.org/project/p2j/1.2.1/", "requires_dist": null, "requires_python": ">=3.6.0", "summary": "p2j: Convert Python scripts to Jupyter notebook with minimal intervention", "version": "1.2.1" }, "last_serial": 4910100, "releases": { "1.1.0": [ { "comment_text": "", "digests": { "md5": "ce71b87d0bd5d52a48972734b2ae6669", "sha256": "dbc5c324a853a5dd712de4611a691b982e08fcf6c59f75ae821e44054232b47d" }, "downloads": -1, "filename": "p2j-1.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "ce71b87d0bd5d52a48972734b2ae6669", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6.0", "size": 14783, "upload_time": "2019-03-06T14:31:23", "url": "https://files.pythonhosted.org/packages/24/6b/cf9588967fe03f1537dd0b8448b1217f801fa60de56f1d7be3207af38fe8/p2j-1.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "01fdc40b44fa2e7f219c9e2dd3dd7cc7", "sha256": "28b77ea3f1bf960ed006d6a5cb90644848bff3852a1f59b1190ed587686285ed" }, "downloads": -1, "filename": "p2j-1.1.0.tar.gz", "has_sig": false, "md5_digest": "01fdc40b44fa2e7f219c9e2dd3dd7cc7", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 10393, "upload_time": "2019-03-06T14:31:25", "url": "https://files.pythonhosted.org/packages/74/4d/84591a9585d508df6f8321f1660136f9499e0ccfd09aba25a37c77d9bc8f/p2j-1.1.0.tar.gz" } ], "1.2.0": [ { "comment_text": "", "digests": { "md5": "96526d8b0868965cf2558724f22cb58b", "sha256": "a40cd920b3535d861d7a97ede79c6973da346ba898dd98a7ac8d6992c3cea21e" }, "downloads": -1, "filename": "p2j-1.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "96526d8b0868965cf2558724f22cb58b", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.5.0", "size": 16048, "upload_time": "2019-03-07T12:17:11", "url": "https://files.pythonhosted.org/packages/4a/74/31639083925c4205bd5cbe3426919cb94ad3bdae44a8005b746e238a7a4e/p2j-1.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "1e87abc3abac10417526c324006486bb", "sha256": "8c28bbfc7a542b65a714e6cc9fdb0fc8e65f0a2ab6d5d6fde8b9f7f88e044d57" }, "downloads": -1, "filename": "p2j-1.2.0.tar.gz", "has_sig": false, "md5_digest": "1e87abc3abac10417526c324006486bb", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.5.0", "size": 11895, "upload_time": "2019-03-07T12:17:13", "url": "https://files.pythonhosted.org/packages/e5/74/cb8bdb357e643b819bd6002e15b44c0b994202b224628bdbe1ad48c86616/p2j-1.2.0.tar.gz" } ], "1.2.1": [ { "comment_text": "", "digests": { "md5": "067b72ec69e4b7e476869c2adca96c97", "sha256": "019c6185f12c3cc9323435c5158731c7b3e19f21f3bc795ed094e3ea41dc175f" }, "downloads": -1, "filename": "p2j-1.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "067b72ec69e4b7e476869c2adca96c97", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6.0", "size": 16048, "upload_time": "2019-03-07T12:51:56", "url": "https://files.pythonhosted.org/packages/ed/d8/f0091e1eb1cab09e5619e988ce232c9cd2c8d253508c327efdae3f2a17b8/p2j-1.2.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c9c5e7a51473c365fa08ac0ca923efed", "sha256": "10305291a3d271d8ba5a00c74ca12a4bb89736334bef97fba1866f91fabfb7d3" }, "downloads": -1, "filename": "p2j-1.2.1.tar.gz", "has_sig": false, "md5_digest": "c9c5e7a51473c365fa08ac0ca923efed", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 11820, "upload_time": "2019-03-07T12:51:58", "url": "https://files.pythonhosted.org/packages/61/81/702aa3df4c08452d90cb6dbedcad63f8a6944755b4765367afddddcee669/p2j-1.2.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "067b72ec69e4b7e476869c2adca96c97", "sha256": "019c6185f12c3cc9323435c5158731c7b3e19f21f3bc795ed094e3ea41dc175f" }, "downloads": -1, "filename": "p2j-1.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "067b72ec69e4b7e476869c2adca96c97", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6.0", "size": 16048, "upload_time": "2019-03-07T12:51:56", "url": "https://files.pythonhosted.org/packages/ed/d8/f0091e1eb1cab09e5619e988ce232c9cd2c8d253508c327efdae3f2a17b8/p2j-1.2.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "c9c5e7a51473c365fa08ac0ca923efed", "sha256": "10305291a3d271d8ba5a00c74ca12a4bb89736334bef97fba1866f91fabfb7d3" }, "downloads": -1, "filename": "p2j-1.2.1.tar.gz", "has_sig": false, "md5_digest": "c9c5e7a51473c365fa08ac0ca923efed", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6.0", "size": 11820, "upload_time": "2019-03-07T12:51:58", "url": "https://files.pythonhosted.org/packages/61/81/702aa3df4c08452d90cb6dbedcad63f8a6944755b4765367afddddcee669/p2j-1.2.1.tar.gz" } ] }