{ "info": { "author": "Scrapy developers", "author_email": "", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Environment :: Console", "Framework :: Django", "Framework :: Scrapy", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Topic :: Utilities" ], "description": "=================\nscrapy-djangoitem\n=================\n\n.. image:: https://img.shields.io/pypi/v/scrapy-djangoitem.svg\n :target: https://pypi.python.org/pypi/scrapy-djangoitem\n :alt: PyPI Version\n\n.. image:: https://img.shields.io/travis/scrapy-plugins/scrapy-djangoitem/master.svg\n :target: http://travis-ci.org/scrapy-plugins/scrapy-djangoitem\n :alt: Build Status\n\n.. image:: https://img.shields.io/github/license/scrapy-plugins/scrapy-djangoitem.svg\n :target: https://github.com/scrapy-plugins/scrapy-djangoitem/blob/master/LICENSE\n :alt: License\n\n\n``scrapy-djangoitem`` is an extension that allows you to define `Scrapy items\n`_ using existing `Django\nmodels `_.\n\nThis utility provides a new class, named ``DjangoItem``, that you can use as a\nregular Scrapy item and link it to a Django model with its ``django_model``\nattribute. Start using it right away by importing it from this package::\n\n from scrapy_djangoitem import DjangoItem\n\nInstallation\n============\n\nStarting with ``v1.1`` both ``Python 2.7`` and ``Python 3.4/3.5`` are\nsupported. For ``Python 3`` you need ``Scrapy v1.1`` or above.\n\nLatest tested Django version is ``Django 1.9``.\n\nInstall from ``PyPI`` using::\n\n pip install scrapy-djangoitem\n\n\nIntroduction\n============\n\n``DjangoItem`` is a class of item that gets its fields definition from a\nDjango model, you simply create a ``DjangoItem`` and specify what Django\nmodel it relates to.\n\nBesides of getting the model fields defined on your item, ``DjangoItem``\nprovides a method to create and populate a Django model instance with the item\ndata.\n\nUsage\n=====\n\n``DjangoItem`` works much like ModelForms in Django, you create a subclass\nand define its ``django_model`` attribute to be a valid Django model. With this\nyou will get an item with a field for each Django model field.\n\nIn addition, you can define fields that aren't present in the model and even\noverride fields that are present in the model defining them in the item.\n\nLet's see some examples:\n\nCreating a Django model for the examples::\n\n from django.db import models\n\n class Person(models.Model):\n name = models.CharField(max_length=255)\n age = models.IntegerField()\n\nDefining a basic ``DjangoItem``::\n\n from scrapy_djangoitem import DjangoItem\n\n class PersonItem(DjangoItem):\n django_model = Person\n\n``DjangoItem`` works just like Scrapy items::\n\n >>> p = PersonItem()\n >>> p['name'] = 'John'\n >>> p['age'] = '22'\n\nTo obtain the Django model from the item, we call the extra method\n``DjangoItem.save()`` of the ``DjangoItem``::\n\n >>> person = p.save()\n >>> person.name\n 'John'\n >>> person.age\n '22'\n >>> person.id\n 1\n\nThe model is already saved when we call ``DjangoItem.save()``, we\ncan prevent this by calling it with ``commit=False``. We can use\n``commit=False`` in ``DjangoItem.save()`` method to obtain an unsaved model::\n\n >>> person = p.save(commit=False)\n >>> person.name\n 'John'\n >>> person.age\n '22'\n >>> person.id\n None\n\nAs said before, we can add other fields to the item::\n\n import scrapy\n from scrapy_djangoitem import DjangoItem\n\n class PersonItem(DjangoItem):\n django_model = Person\n sex = scrapy.Field()\n\n::\n\n >>> p = PersonItem()\n >>> p['name'] = 'John'\n >>> p['age'] = '22'\n >>> p['sex'] = 'M'\n\nAnd we can override the fields of the model with your own::\n\n class PersonItem(DjangoItem):\n django_model = Person\n name = scrapy.Field(default='No Name')\n\nThis is useful to provide properties to the field, like a default or any other\nproperty that your project uses. Those additional fields won't be taken into\naccount when doing a ``DjangoItem.save()``.\n\nCaveats\n=======\n\n``DjangoItem`` is a rather convenient way to integrate Scrapy projects with Django\nmodels, but bear in mind that Django ORM **may not scale well** if you scrape a lot\nof items (ie. millions) with Scrapy. This is because a relational backend is\n**often not a good choice for a write intensive applications** (such as a web\ncrawler), specially if the database is highly normalized and with many indices.\n\nSetup\n=====\n\nTo use the Django models outside the Django application you need to set up the\n``DJANGO_SETTINGS_MODULE`` environment variable and --in most cases-- modify\nthe ``PYTHONPATH`` environment variable to be able to import the settings\nmodule.\n\nThere are many ways to do this depending on your use case and preferences.\nBelow is detailed one of the simplest ways to do it.\n\nSuppose your Django project is named ``mysite``, is located in the path\n``/home/projects/mysite`` and you have created an app ``myapp`` with the model\n``Person``. That means your directory structure is something like this::\n\n /home/projects/mysite\n \u251c\u2500\u2500 manage.py\n \u251c\u2500\u2500 myapp\n \u2502\u00a0\u00a0 \u251c\u2500\u2500 __init__.py\n \u2502\u00a0\u00a0 \u251c\u2500\u2500 models.py\n \u2502\u00a0\u00a0 \u251c\u2500\u2500 tests.py\n \u2502\u00a0\u00a0 \u2514\u2500\u2500 views.py\n \u2514\u2500\u2500 mysite\n \u251c\u2500\u2500 __init__.py\n \u251c\u2500\u2500 settings.py\n \u251c\u2500\u2500 urls.py\n \u2514\u2500\u2500 wsgi.py\n\nThen you need to add ``/home/projects/mysite`` to the ``PYTHONPATH``\nenvironment variable and set up the environment variable\n``DJANGO_SETTINGS_MODULE`` to ``mysite.settings``. That can be done in your\nScrapy's settings file by adding the lines below::\n\n import sys\n sys.path.append('/home/projects/mysite')\n\n import os\n os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings'\n\nNotice that we modify the ``sys.path`` variable instead the ``PYTHONPATH``\nenvironment variable as we are already within the python runtime. If everything\nis right, you should be able to start the ``scrapy shell`` command and import\nthe model ``Person`` (i.e. ``from myapp.models import Person``).\n\nStarting with ``Django 1.8`` you also have to explicitly set up ``Django`` if using\nit outside a ``manage.py`` context\n(see `Django Docs `_)::\n\n import django\n django.setup()\n\n\nDevelopment\n===========\n\nTest suite from the ``tests`` directory can be run using ``tox`` by running::\n\n tox\n\n...using the configuration in ``tox.ini``. The ``Python`` interpreters\nused have to be installed locally on the system.\n\n\nChangelog\n=========\n\nv1.1.1 (2016-05-04)\n-------------------\n\n* Distribute as universal wheel\n* Fix README's markup\n\nv1.1 (2016-05-04)\n-----------------\n\n* ``Python 3.4/3.5`` support\n* Making tests work with ``Django 1.9`` again\n\nv1.0 (2015-04-29)\n-----------------\n\n* Initial version", "description_content_type": null, "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/scrapy-plugins/scrapy-djangoitem", "keywords": "", "license": "BSD", "maintainer": "", "maintainer_email": "", "name": "scrapy-djangoitem", "package_url": "https://pypi.org/project/scrapy-djangoitem/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/scrapy-djangoitem/", "project_urls": { "Homepage": "https://github.com/scrapy-plugins/scrapy-djangoitem" }, "release_url": "https://pypi.org/project/scrapy-djangoitem/1.1.1/", "requires_dist": [ "six" ], "requires_python": "", "summary": "Scrapy extension to write scraped items using Django models", "version": "1.1.1" }, "last_serial": 2099239, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "c80f7a6f12536bce4e33214063f51a93", "sha256": "bbea8a5a78060f825dc289341448591cf5906173897f28bc8071ac8830cee8ef" }, "downloads": -1, "filename": "scrapy-djangoitem-0.1.0.tar.gz", "has_sig": false, "md5_digest": "c80f7a6f12536bce4e33214063f51a93", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4538, "upload_time": "2015-04-20T19:10:37", "url": "https://files.pythonhosted.org/packages/ec/2f/554dd63ffa2d7bb5086c853b2f0d685e010af47a304841c62fd20918ffa3/scrapy-djangoitem-0.1.0.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "67d153c38d8a0888ed54ccf6b62dd796", "sha256": "0694b7248a6b899129e445b91ba3ed207c554c1443bf70bf57bce33b47143662" }, "downloads": -1, "filename": "scrapy_djangoitem-1.0.0-py2-none-any.whl", "has_sig": false, "md5_digest": "67d153c38d8a0888ed54ccf6b62dd796", "packagetype": "bdist_wheel", "python_version": "2.7", "requires_python": null, "size": 7323, "upload_time": "2015-04-27T18:43:31", "url": "https://files.pythonhosted.org/packages/e3/a1/619e9c5023cde8acddeb57781d87808146cae4679f5c8a5e4510d3f39fd1/scrapy_djangoitem-1.0.0-py2-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b79f9aada685e24bd38e2598dd152c5e", "sha256": "bac7c14fcf8ea2ab4c4f426380316ffb636a4c43fd1161044960091c6fe61f34" }, "downloads": -1, "filename": "scrapy-djangoitem-1.0.0.tar.gz", "has_sig": false, "md5_digest": "b79f9aada685e24bd38e2598dd152c5e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4518, "upload_time": "2015-04-27T18:43:28", "url": "https://files.pythonhosted.org/packages/9f/aa/71bc883e6378e3bf09b718a8567210a846d1291a0e4b96af2809acf74d38/scrapy-djangoitem-1.0.0.tar.gz" } ], "1.1.0": [ { "comment_text": "", "digests": { "md5": "de85ff73ed4abccf4b516f4cfc432e00", "sha256": "e17fb904f113ae3592d6c0f48d48dfba0c4cc2822454205eca7edab6d9815726" }, "downloads": -1, "filename": "scrapy_djangoitem-1.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "de85ff73ed4abccf4b516f4cfc432e00", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 8201, "upload_time": "2016-05-04T16:17:32", "url": "https://files.pythonhosted.org/packages/09/2a/d49c7fc3d61349f3f633bd28b5e8497f3b5abeceac4a7888ab79d158a26d/scrapy_djangoitem-1.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "033c61969b359ea5817690c291712d56", "sha256": "e6adf98a02eacf8b994f16c4c1f835bf7d326bbf8e3ecfa62de17b6416a7fa3e" }, "downloads": -1, "filename": "scrapy-djangoitem-1.1.0.tar.gz", "has_sig": false, "md5_digest": "033c61969b359ea5817690c291712d56", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5163, "upload_time": "2016-05-04T16:17:49", "url": "https://files.pythonhosted.org/packages/ad/ee/5cc82ba1be829b2a3a8ee38e14885d64c86a74ce55c2bc872c520a1239b0/scrapy-djangoitem-1.1.0.tar.gz" } ], "1.1.1": [ { "comment_text": "", "digests": { "md5": "85e5614159e8164e7fd434a8c95668ea", "sha256": "58da093778f2cd92734b5539adcb60d59854475050d7511c42173bd8c104acef" }, "downloads": -1, "filename": "scrapy_djangoitem-1.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "85e5614159e8164e7fd434a8c95668ea", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 8293, "upload_time": "2016-05-04T16:45:10", "url": "https://files.pythonhosted.org/packages/5c/ff/ca88e5fa4b5df11876d877c568de8f5e1a06587bcd23dab7d1847a9b1123/scrapy_djangoitem-1.1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fbd7c04100fd4e95d7ea43e99ab7ba40", "sha256": "2c633ae1559f6e3d43c9a5ebb19aa5a64152deef434aa3fa57168e6b002d9c50" }, "downloads": -1, "filename": "scrapy-djangoitem-1.1.1.tar.gz", "has_sig": false, "md5_digest": "fbd7c04100fd4e95d7ea43e99ab7ba40", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5223, "upload_time": "2016-05-04T16:45:19", "url": "https://files.pythonhosted.org/packages/50/10/7b8d1caf3c292069b1bc983c2c872597f429bac4673707d11ee76313515a/scrapy-djangoitem-1.1.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "85e5614159e8164e7fd434a8c95668ea", "sha256": "58da093778f2cd92734b5539adcb60d59854475050d7511c42173bd8c104acef" }, "downloads": -1, "filename": "scrapy_djangoitem-1.1.1-py2.py3-none-any.whl", "has_sig": false, "md5_digest": "85e5614159e8164e7fd434a8c95668ea", "packagetype": "bdist_wheel", "python_version": "py2.py3", "requires_python": null, "size": 8293, "upload_time": "2016-05-04T16:45:10", "url": "https://files.pythonhosted.org/packages/5c/ff/ca88e5fa4b5df11876d877c568de8f5e1a06587bcd23dab7d1847a9b1123/scrapy_djangoitem-1.1.1-py2.py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fbd7c04100fd4e95d7ea43e99ab7ba40", "sha256": "2c633ae1559f6e3d43c9a5ebb19aa5a64152deef434aa3fa57168e6b002d9c50" }, "downloads": -1, "filename": "scrapy-djangoitem-1.1.1.tar.gz", "has_sig": false, "md5_digest": "fbd7c04100fd4e95d7ea43e99ab7ba40", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 5223, "upload_time": "2016-05-04T16:45:19", "url": "https://files.pythonhosted.org/packages/50/10/7b8d1caf3c292069b1bc983c2c872597f429bac4673707d11ee76313515a/scrapy-djangoitem-1.1.1.tar.gz" } ] }