Skip to main content

Scrapy Ingest

A Scrapy addon that saves items, requests, logs, and stats to PostgreSQL or MySQL — with parent_url tracking, failed-request errors, and full job log capture (including print()).

Install

pip install scrapy-ingest

Minimal setup (settings.py)

Only the item pipeline is required — requests, logs, stats, parent_url, and error logging are enabled automatically:

ITEM_PIPELINES = {
    "scrapy_ingest.pipelines.DbInsertPipeline": 300,
}

# PostgreSQL
DB_URL = "postgresql://user:password@localhost:5432/database"
# MySQL
# DB_URL = "mysql://user:password@localhost:3306/database"
# Or discrete fields (avoids URL encoding):
# DB_TYPE = "postgres"   # or "mysql"
# DB_HOST = "localhost"
# DB_PORT = 5432         # MySQL: 3306
# DB_USER = "user"
# DB_PASSWORD = "password"
# DB_NAME = "database"

# Optional
CREATE_TABLES = True     # auto-create tables on first run (default True)
JOB_ID = 1               # or omit; a unique id is generated per crawl
INGEST_BATCH_SIZE = 50   # flush when this many rows are buffered

Run your spider:

scrapy crawl your_spider

Log level follows Scrapy LOG_LEVEL.

What is stored

Table Contents
jobs One row per crawl: id, unique job_id string, spider, status, start/finish, counts, items/min, stats
job_items JSON items (crawled_at added). job_id = jobs.id (CASCADE)
job_requests url, parent_url, parent_id, status, response_time, error, success. job_id = jobs.id (CASCADE)
job_logs time, logger, level, message, exception. job_id = jobs.id (CASCADE)

Request parent_url is the page that scheduled the request (e.g. sitemap → product). Start URLs are null.

Data flushes on batch size, every 10s, and on engine/process stop.

When the spider closes, a crawl summary is printed (job, database, tables, items, requests, logs, errors, elapsed time) even if LOG_LEVEL is ERROR. Set INGEST_SHOW_SUMMARY = False to hide it.

Troubleshooting

  • Password has special characters like @ or $?
    • In a URL, encode them: @ -> %40, $ -> %24.
    • Example: postgresql://user:PAK%40swat1%24@localhost:5432/db
    • Or use the discrete fields (no encoding needed).
  • Yield items from callbacks (not only return inside a generator).

Useful settings (optional)

  • DB_TYPE (default: postgres) — postgres / postgresql or mysql / mariadb when building a URL from DB_* fields
  • INGEST_BATCH_SIZE (default: 50) — flush when this many items+requests+logs are buffered
  • INGEST_FLUSH_INTERVAL (default: 10) — periodic flush in seconds
  • INGEST_SHOW_SUMMARY (default: True) — print crawl summary tables when the spider closes
  • CREATE_TABLES (default: True) — create tables on startup
  • ITEMS_TABLE, REQUESTS_TABLE, LOGS_TABLE, JOBS_TABLE — override table names
  • TIMEZONE (default: Asia/Karachi) — timezone for created_at
  • JOB_ID — omit to auto-generate a unique id (Rs_Spider-178826754-a1b2c3)

Standalone components

If you only want part of the collection:

# Items only
ITEM_PIPELINES = {"scrapy_ingest.pipelines.ItemsPipeline": 300}

# Requests only (parent_url + errors)
ITEM_PIPELINES = {"scrapy_ingest.pipelines.RequestsPipeline": 300}

# Logs only
EXTENSIONS = {"scrapy_ingest.extensions.LoggingExtension": 500}

License

MIT License. See LICENSE.

Metadata

Release files for scrapy-ingest 1.1.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 scrapy-ingest 1.1.1
File Size Uploaded
scrapy_ingest-1.1.1.tar.gz 28.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for scrapy-ingest 1.1.1
File Interpreter ABI Platform
scrapy_ingest-1.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 64.4 kB

Release files / scrapy_ingest-1.1.1.tar.gz

Download URL scrapy_ingest-1.1.1.tar.gz
Size 28.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b1d0cb581fb7da10cff68f389a96c04c1027ce504595a691cc7b2fca8c930ccd
BLAKE2b-256 checksum
How to use checksums
cedd29092eda82d273527c6d358183cb99a21bd3b55f9e62b3b00d7ca367b815
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release files / scrapy_ingest-1.1.1-py3-none-any.whl

Download URL scrapy_ingest-1.1.1-py3-none-any.whl
Size 35.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
101dd1e3fb7502b3498063ea970d8dae27456130eca11ef35641bf801cc97cab
BLAKE2b-256 checksum
How to use checksums
a534de4f8b65e7116afc1e52406bdd5b0073881f608388f6f695b5a3967285c4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.14.3

Release history Release notifications | RSS feed

1.8.0

2 release files

1.7.0

2 release files

1.6.0

2 release files

1.5.0

2 release files

1.4.0

2 release files

1.3.1

2 release files

1.3.0

2 release files

1.2.0

2 release files

This release

1.1.1 This release

2 release files

1.1.0

2 release files

1.0.0

2 release files

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