Skip to main content

Scrachy

Scrachy was primarily developed to provide a flexible cache storage backend for Scrapy that stores its data in a relational database using SQLAlchemy. However, it now has several other additional features including middleware for using Selenium to download requests. It also comes with a downloader middleware that will optionally ignore requests that are already in the cache.

Install

You can install the latest version from git:

>pip install git+https://bitbucket.org/reidswanson/scrachy.git

or from PyPI:

>pip install scrachy

NOTE : libnss3 must be installed for chromedriver to work. For example: sudo apt install libnss3

NOTE: At least on Ubuntu, you must install chromium-chromedriver. The version downloaded by the webdriver manager fails with an error about the user data directory.

Documentation

A brief guide to minimally using the cache storage engine and the Selenium backend are given below. For other configuration options and features please see the full documentation on Read the Docs.

Storage Backend

To (minimally) use the storage backend you simply need to enable caching by adding the following to your settings.py file:

# Enable caching
HTTPCACHE_ENABLED = True

# Set the storage backend to the one provided by Scrachy.
HTTPCACHE_STORAGE = 'scrachy.middleware.httpcache.AlchemyCacheStorage'

# One of the supported SqlAlchemy dialects
SCRACHY_DB_DIALECT = '<database-dialect>'

# The name of the driver (that must be installed as an extra) and used.
SCRACHY_DB_DRIVER = '<database-driver>'

# Options for connecting to the database
SCRACHY_DB_HOST = '<database-hostname>'
SCRACHY_DB_PORT = '<database-port>'
SCRACHY_DB_SCHEMA = <database-schema>
SCRACHY_DB_DATABASE = '<database-name>'
SCRACHY_DB_USERNAME = '<username>'

# Note, do not store this value in the settings file. Use an environment
# variable or python-dotenv.
SCRACHY_DB_PASSWORD = '<password>'

# A dictionary of other connection arguments
SCRACHY_DB_CONNECT_ARGS = {}

# there may be a conflict with the compression middleware. If you encounter
# errors either disable it or move it after the caching middleware.
DOWNLOADER_MIDDLEWARES = {
   ...
   'scrapy.downloadermiddlewares.http.compression.HttpCompressionMiddleware': None,
}

Selenium

There are two Selenium middleware classes provided by Scrachy. To use them, first add one of them to the DOWNLOADER_MIDDLEWARES

DOWNLOADER_MIDDLEWARES = {
    ...
    'scrachy.middleware.selenium.SeleniumMiddleware': 800,  # or AsyncSeleniumMiddleware
    ...
}

Then in your spider parsing code use a SeleniumRequest instead of a scrapy.http.Request.

License

Scrachy is released using the GNU Lesser General Public License. See the LICENSE file for more details. Files that are adapted or use code from other sources are indicated either at the top of the file or at the location of the code snippet. Some of these files were adapted from code released under a 3-clause BSD license. Those files should indicate the original copyright in a comment at the top of the file. See the BSD_LICENSE file for details of this license.

Metadata

Release files for scrachy 0.21.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scrachy 0.21.1
File Size Uploaded Provenance Actions
scrachy-0.21.1.tar.gz 63.5 kB Without provenance Details for scrachy-0.21.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for scrachy 0.21.1
File Interpreter ABI Platform Actions
scrachy-0.21.1-py3-none-any.whl Python 3 none any Details for scrachy-0.21.1-py3-none-any.whl

Total release size: 136.8 kB

Release files / scrachy-0.21.1.tar.gz

Download URL scrachy-0.21.1.tar.gz
Size 63.5 kB
Tags Source
SHA-256 checksum
How to use checksums
b547b1efa9bd303fa2f39fedd386863bfb19ed9439f36336a7a014fb34c7d3fc
BLAKE2b-256 checksum
How to use checksums
9d1747265e33e6ec09b56429cef6968e5516a575284efeba09d4c3c2f3da64ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.26.0 CPython/3.13.7 Linux/6.17.5-arch1-1

Release files / scrachy-0.21.1-py3-none-any.whl

Download URL scrachy-0.21.1-py3-none-any.whl
Size 73.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4b87345c6f70444b1629ed7d97302faf220b1afc23b48f1187ed7ab8da344d1e
BLAKE2b-256 checksum
How to use checksums
f4ce6fc28fceeb9cb627690b5bdcc1ecb5b41113975f71fbe248752c6cb6ec6b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.26.0 CPython/3.13.7 Linux/6.17.5-arch1-1

Security for scrachy 0.21.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page