{ "info": { "author": "Andrew Carter", "author_email": "andrew.carter@istresearch.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "Topic :: System", "Topic :: System :: Distributed Computing", "Topic :: Utilities" ], "description": "phantom-snap\n====\n\nRender HTML to an image using PhantomJS with this library designed to scale for high volume continuous operation.\n\nFeatures\n--------\n\n- Provides full timing control around the rendering process.\n- Maintains a live PhantomJS process (instead of a new one per request which many wrappers do, which is slow).\n- Render content from a URL, or provide the HTML content directly to the renderer\n\nRoadmap\n-------\n- Decorator to manage rendering under specified timezones\n- Decorator to manage rendering under specified proxies.\n\nExamples\n--------\n\nThe example assumes you have http://phantomjs.org/ installed.\n\n\nThis first example demonstrates rendering a URL and saving the resulting image to a file at /tmp/google-render.jpg.\n::\n\n from phantom_snap.settings import PHANTOMJS\n from phantom_snap.phantom import PhantomJSRenderer\n from phantom_snap.imagetools import save_image\n\n config = {\n 'executable': '/usr/local/bin/phantomjs',\n 'args': PHANTOMJS['args'] + ['--disk-cache=false', '--load-images=true'],\n 'env': {'TZ': 'America/Los_Angeles'}\n 'timeouts': {\n 'page_load': 3\n }\n }\n r = PhantomJSRenderer(config)\n\n url = 'http://www.google.com'\n\n try:\n page = r.render(url, img_format='JPEG')\n save_image('/tmp/google-render', page)\n finally:\n r.shutdown(15)\n\nA sample response from ``r.render(url)`` looks like this:\n\n::\n\n {\n \"status\": \"success\",\n \"format\": \"PNG\",\n \"url\": \"http://www.google.com\",\n \"paint_time\": 141,\n \"base64\": \"iVBORw0KGgo RK5CYII=\",\n \"error\": null,\n \"load_time\": 342\n }\n\nThis example shows how to provide HTML content directly to the rendering process, instead of requesting it.\n::\n\n from phantom_snap.settings import PHANTOMJS\n from phantom_snap.phantom import PhantomJSRenderer\n from phantom_snap.imagetools import save_image\n\n config = {\n 'executable': '/usr/local/bin/phantomjs',\n 'args': PHANTOMJS['args'] + ['--disk-cache=false', '--load-images=true']\n }\n r = PhantomJSRenderer(config)\n\n url = 'http://www.a-url.com'\n html = 'Boo ya!'\n\n try:\n page = r.render(url=url, html=html, img_format='PNG')\n save_image('/tmp/html-render', page)\n finally:\n r.shutdown(15)\n\nIf you would like to offload the running of phantomjs into `AWS Lambda `_, you can use the ``LambdaRenderer`` class in the following way:\n\n::\n\n from phantom_snap.lambda_renderer import LambdaRenderer\n from phantom_snap.imagetools import save_image\n\n config = {\n 'url': 'http://url-to-my-lambda-func',\n }\n\n r = LambdaRenderer(config)\n url = 'http://www.youtube.com'\n\n page = r.render(url, img_format='JPEG')\n save_image('/tmp/youtube-render', page)\n\n r.shutdown()\n\nTo learn more about offloading renders into AWS Lambda, please see the ``serverless`` folder.\n\n\nDecorators\n----------\n\n**Lifetime**\n\nIf you plan on running a ``PhantomJSRenderer`` instance for an extended period of time with high volume, it's recommended that you wrap the instance with a ``Lifetime`` decorator as shown below.\n\nThe ``Lifetime`` decorator will transparently shutdown the underlying PhantomJS process if the renderer is idle or after a maximum lifetime to release any accumulated resources. This is important if PhantomJS is configured to use a memory-based browser cache to prevent the cache from growing too large. After the ``Lifetime`` decorator shuts down the Renderer (due to idle time or maximum time) the next render request will automatically create a new PhantomJS process.\n\n::\n\n from phantom_snap.settings import PHANTOMJS\n from phantom_snap.phantom import PhantomJSRenderer\n from phantom_snap.decorators import Lifetime\n\n config = {\n 'executable': '/usr/local/bin/phantomjs',\n 'args': PHANTOMJS['args'] + ['--disk-cache=false', '--load-images=true'],\n 'env': {'TZ': 'America/Los_Angeles'},\n\n # Properties for the Lifetime decorator\n 'idle_shutdown_sec': 900, # 15 minutes, Shutdown PhantomJS if it's been idle this long\n 'max_lifetime_sec': 43200 # 12 hours, Restart PhantomJS every 12 hours\n }\n\n r = Lifetime(PhantomJSRenderer(config))\n\n try:\n urls = [] # Some endless source of URL targets\n\n for url in urls:\n page = r.render(url=url, img_format='JPEG')\n\n # Store the image somewhere\n\n finally:\n r.shutdown()\n\n\nYou can view the default configuration values in ``phantom_snap.settings.py``.", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/istresearch/phantom-snap", "keywords": "web,html,render,screenshot,phantomjs", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "phantom-snap", "package_url": "https://pypi.org/project/phantom-snap/", "platform": "", "project_url": "https://pypi.org/project/phantom-snap/", "project_urls": { "Homepage": "https://github.com/istresearch/phantom-snap" }, "release_url": "https://pypi.org/project/phantom-snap/0.0.18.1/", "requires_dist": null, "requires_python": "", "summary": "Render HTML to an image using PhantomJS with this library designed to scale for high volume continuous operation.", "version": "0.0.18.1" }, "last_serial": 4466935, "releases": { "0.0.18": [ { "comment_text": "", "digests": { "md5": "c5220c7f71d8781e0134aaae4e9adc02", "sha256": "b676e38033f27d741a7cfe138ccfefd14e05362d0200471fe173331aca01fe55" }, "downloads": -1, "filename": "phantom-snap-0.0.18.tar.gz", "has_sig": false, "md5_digest": "c5220c7f71d8781e0134aaae4e9adc02", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11528, "upload_time": "2018-10-30T14:27:34", "url": "https://files.pythonhosted.org/packages/df/25/9f7b72b3c91f23c8778930c46195293a58b91ed4ef95e7bad4364c8b5891/phantom-snap-0.0.18.tar.gz" } ], "0.0.18.1": [ { "comment_text": "", "digests": { "md5": "351b140cb521dcfba7ec60f46000f56c", "sha256": "502d7a3f5ba4d1a2141d193d0c9cb8af6c4d84f1ee50410ab00d53360ea5a0c2" }, "downloads": -1, "filename": "phantom-snap-0.0.18.1.tar.gz", "has_sig": false, "md5_digest": "351b140cb521dcfba7ec60f46000f56c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11548, "upload_time": "2018-11-08T20:19:50", "url": "https://files.pythonhosted.org/packages/0a/50/ddc9b4042ad71d3a03ca25e1be7aca4ecb5b9c3732000754c113dec6eaf9/phantom-snap-0.0.18.1.tar.gz" } ], "0.0.18.dev0": [ { "comment_text": "", "digests": { "md5": "13019737582b68d834bba009cbc33352", "sha256": "a8bd847023198cbdf1d6aa6525dd1bba8dd7c01d70b766f1e4716011e8fe1e56" }, "downloads": -1, "filename": "phantom-snap-0.0.18.dev0.tar.gz", "has_sig": false, "md5_digest": "13019737582b68d834bba009cbc33352", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9432, "upload_time": "2018-10-15T21:27:30", "url": "https://files.pythonhosted.org/packages/ff/2d/b4edeeee71faac1c5774a0b6982cfb37030a23527337f8bd3b024eed86ab/phantom-snap-0.0.18.dev0.tar.gz" } ], "0.0.18.dev4": [ { "comment_text": "", "digests": { "md5": "ad960021feed71e9d7934ae65aafbda1", "sha256": "04ada5c45ff3df846219f5bbb1606070f0e95b4e743b18657d603f441b2ce40c" }, "downloads": -1, "filename": "phantom-snap-0.0.18.dev4.tar.gz", "has_sig": false, "md5_digest": "ad960021feed71e9d7934ae65aafbda1", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11457, "upload_time": "2018-10-18T15:29:05", "url": "https://files.pythonhosted.org/packages/f8/92/bbf5edf531bec3ab987421e94359f0b2d5a3fb57e094e045818d1bf2b9c4/phantom-snap-0.0.18.dev4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "351b140cb521dcfba7ec60f46000f56c", "sha256": "502d7a3f5ba4d1a2141d193d0c9cb8af6c4d84f1ee50410ab00d53360ea5a0c2" }, "downloads": -1, "filename": "phantom-snap-0.0.18.1.tar.gz", "has_sig": false, "md5_digest": "351b140cb521dcfba7ec60f46000f56c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11548, "upload_time": "2018-11-08T20:19:50", "url": "https://files.pythonhosted.org/packages/0a/50/ddc9b4042ad71d3a03ca25e1be7aca4ecb5b9c3732000754c113dec6eaf9/phantom-snap-0.0.18.1.tar.gz" } ] }