colab2pdf


Namecolab2pdf JSON
Version 1.0.0a14 PyPI version JSON
download
home_page
SummaryConvert Your Colab Notebook to a PDF. One-Minute Install. Zero Configuration.
upload_time2023-11-05 15:12:32
maintainer
docs_urlNone
author
requires_python>=3.7
license
keywords ai artificial-intelligence colab colab-notebook colab-notebooks data-science deep-learning google google-colab google-colaboratory jupyter-notebook jupyter-notebooks machine-learning ml pdf python python3 pytorch tensorflow torch
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <img src="https://drengskapur.com/colab2pdf.png" />

## Directions: Copy→Paste→Run [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1zqrIYC0iQ_CZkRqGXgZggrwjtt_4BmpL?usp=sharing)

```python
# Colab2PDF v1.0.0 by Drengskapur (github.com/drengskapur/colab2pdf) (License: GPL-3.0-or-later)
# @title {display-mode:"form"}
# @markdown ⬇️ Download PDF
def colab2pdf():
    ENABLE=True # @param {type:"boolean"}
    if ENABLE:
        import os, datetime, json, pathlib, urllib, requests, werkzeug, nbformat, google, yaml, warnings
        NAME = pathlib.Path(werkzeug.utils.secure_filename(urllib.parse.unquote(requests.get(f"http://{os.environ['COLAB_JUPYTER_IP']}:{os.environ['KMP_TARGET_PORT']}/api/sessions").json()[0]["name"])))
        TEMP = pathlib.Path("/content/pdfs") / f"{datetime.datetime.now().strftime('%Y%m%d_%H%M%S')}_{NAME.stem}"; TEMP.mkdir(parents=True, exist_ok=True)
        NB = [cell for cell in nbformat.reads(json.dumps(google.colab._message.blocking_request("get_ipynb", timeout_sec=30)["ipynb"]), as_version=4).cells if "--Colab2PDF" not in cell.source]
        warnings.filterwarnings('ignore', category=nbformat.validator.MissingIDFieldWarning)
        with (TEMP / f"{NAME.stem}.ipynb").open("w") as nb_copy: nbformat.write(nbformat.v4.new_notebook(cells=NB or [nbformat.v4.new_code_cell("#")]), nb_copy)
        if not pathlib.Path("/usr/local/bin/quarto").exists():
            !wget -q "https://quarto.org/download/latest/quarto-linux-amd64.deb" -P {TEMP} && dpkg -i {TEMP}/quarto-linux-amd64.deb > /dev/null && quarto install tinytex --update-path --quiet
        with (TEMP / "config.yml").open("w") as file: yaml.dump({'include-in-header': [{"text": r"\usepackage{fvextra}\DefineVerbatimEnvironment{Highlighting}{Verbatim}{breaksymbolleft={},showspaces=false,showtabs=false,breaklines,breakanywhere,commandchars=\\\{\}}"}],'include-before-body': [{"text": r"\DefineVerbatimEnvironment{verbatim}{Verbatim}{breaksymbolleft={},showspaces=false,showtabs=false,breaklines}"}]}, file)
        !quarto render {TEMP}/{NAME.stem}.ipynb --metadata-file={TEMP}/config.yml --to pdf -M latex-auto-install -M margin-top=1in -M margin-bottom=1in -M margin-left=1in -M margin-right=1in --quiet
        google.colab.files.download(str(TEMP / f"{NAME.stem}.pdf"))
colab2pdf()
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "colab2pdf",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "ai,artificial-intelligence,colab,colab-notebook,colab-notebooks,data-science,deep-learning,google,google-colab,google-colaboratory,jupyter-notebook,jupyter-notebooks,machine-learning,ml,pdf,python,python3,pytorch,tensorflow,torch",
    "author": "",
    "author_email": "Drengskapur <service@drengskapur.com>",
    "download_url": "https://files.pythonhosted.org/packages/a7/0c/856eaef3ce240cddfc0825b4cc61441d65bea5e68fff15ff0e906be7d6f0/colab2pdf-1.0.0a14.tar.gz",
    "platform": null,
    "description": "<img src=\"https://drengskapur.com/colab2pdf.png\" />\n\n## Directions: Copy\u2192Paste\u2192Run [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/drive/1zqrIYC0iQ_CZkRqGXgZggrwjtt_4BmpL?usp=sharing)\n\n```python\n# Colab2PDF v1.0.0 by Drengskapur (github.com/drengskapur/colab2pdf) (License: GPL-3.0-or-later)\n# @title {display-mode:\"form\"}\n# @markdown \u2b07\ufe0f Download PDF\ndef colab2pdf():\n    ENABLE=True # @param {type:\"boolean\"}\n    if ENABLE:\n        import os, datetime, json, pathlib, urllib, requests, werkzeug, nbformat, google, yaml, warnings\n        NAME = pathlib.Path(werkzeug.utils.secure_filename(urllib.parse.unquote(requests.get(f\"http://{os.environ['COLAB_JUPYTER_IP']}:{os.environ['KMP_TARGET_PORT']}/api/sessions\").json()[0][\"name\"])))\n        TEMP = pathlib.Path(\"/content/pdfs\") / f\"{datetime.datetime.now().strftime('%Y%m%d_%H%M%S')}_{NAME.stem}\"; TEMP.mkdir(parents=True, exist_ok=True)\n        NB = [cell for cell in nbformat.reads(json.dumps(google.colab._message.blocking_request(\"get_ipynb\", timeout_sec=30)[\"ipynb\"]), as_version=4).cells if \"--Colab2PDF\" not in cell.source]\n        warnings.filterwarnings('ignore', category=nbformat.validator.MissingIDFieldWarning)\n        with (TEMP / f\"{NAME.stem}.ipynb\").open(\"w\") as nb_copy: nbformat.write(nbformat.v4.new_notebook(cells=NB or [nbformat.v4.new_code_cell(\"#\")]), nb_copy)\n        if not pathlib.Path(\"/usr/local/bin/quarto\").exists():\n            !wget -q \"https://quarto.org/download/latest/quarto-linux-amd64.deb\" -P {TEMP} && dpkg -i {TEMP}/quarto-linux-amd64.deb > /dev/null && quarto install tinytex --update-path --quiet\n        with (TEMP / \"config.yml\").open(\"w\") as file: yaml.dump({'include-in-header': [{\"text\": r\"\\usepackage{fvextra}\\DefineVerbatimEnvironment{Highlighting}{Verbatim}{breaksymbolleft={},showspaces=false,showtabs=false,breaklines,breakanywhere,commandchars=\\\\\\{\\}}\"}],'include-before-body': [{\"text\": r\"\\DefineVerbatimEnvironment{verbatim}{Verbatim}{breaksymbolleft={},showspaces=false,showtabs=false,breaklines}\"}]}, file)\n        !quarto render {TEMP}/{NAME.stem}.ipynb --metadata-file={TEMP}/config.yml --to pdf -M latex-auto-install -M margin-top=1in -M margin-bottom=1in -M margin-left=1in -M margin-right=1in --quiet\n        google.colab.files.download(str(TEMP / f\"{NAME.stem}.pdf\"))\ncolab2pdf()\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Convert Your Colab Notebook to a PDF. One-Minute Install. Zero Configuration.",
    "version": "1.0.0a14",
    "project_urls": {
        "Documentation": "https://github.com/drengskapur/colab2pdf#readme",
        "Issues": "https://github.com/drengskapur/colab2pdf/issues",
        "Source": "https://github.com/drengskapur/colab2pdf"
    },
    "split_keywords": [
        "ai",
        "artificial-intelligence",
        "colab",
        "colab-notebook",
        "colab-notebooks",
        "data-science",
        "deep-learning",
        "google",
        "google-colab",
        "google-colaboratory",
        "jupyter-notebook",
        "jupyter-notebooks",
        "machine-learning",
        "ml",
        "pdf",
        "python",
        "python3",
        "pytorch",
        "tensorflow",
        "torch"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f60db17c3569b1f8d525b1141e7cf80f37852d0b711c9868fce60abf38589b48",
                "md5": "c4d7e8a8797ab46346770db4bab718f4",
                "sha256": "2386cb8eb2bb1ad835a7b483416b04b0f90a394c4ed59c80e56e0474180d9698"
            },
            "downloads": -1,
            "filename": "colab2pdf-1.0.0a14-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "c4d7e8a8797ab46346770db4bab718f4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 16795,
            "upload_time": "2023-11-05T15:12:30",
            "upload_time_iso_8601": "2023-11-05T15:12:30.565964Z",
            "url": "https://files.pythonhosted.org/packages/f6/0d/b17c3569b1f8d525b1141e7cf80f37852d0b711c9868fce60abf38589b48/colab2pdf-1.0.0a14-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a70c856eaef3ce240cddfc0825b4cc61441d65bea5e68fff15ff0e906be7d6f0",
                "md5": "69bade30976733af425abfab4c608bb4",
                "sha256": "95e63e09de95e5ff18313d007f6078a6445648baaad64927e4539cf8acee3ca0"
            },
            "downloads": -1,
            "filename": "colab2pdf-1.0.0a14.tar.gz",
            "has_sig": false,
            "md5_digest": "69bade30976733af425abfab4c608bb4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 79367,
            "upload_time": "2023-11-05T15:12:32",
            "upload_time_iso_8601": "2023-11-05T15:12:32.510385Z",
            "url": "https://files.pythonhosted.org/packages/a7/0c/856eaef3ce240cddfc0825b4cc61441d65bea5e68fff15ff0e906be7d6f0/colab2pdf-1.0.0a14.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-05 15:12:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "drengskapur",
    "github_project": "colab2pdf#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "colab2pdf"
}
        
Elapsed time: 0.30612s