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.0

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.0
File Size Uploaded
scrapy_ingest-1.1.0.tar.gz 28.4 kB Details

Built distribution (wheel)

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

Total release size: 64.0 kB

Release files / scrapy_ingest-1.1.0.tar.gz

Download URL scrapy_ingest-1.1.0.tar.gz
Size 28.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b6bdf4c0b1fc255f41366c9facc29e9aa58a7a7248dae6769eb5a8c987c663b9
BLAKE2b-256 checksum
How to use checksums
f792ab90d0d0e2a465ddc1395c7ac9cb02d66f243d5ecfa12a22bfa907050eb2
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.0-py3-none-any.whl

Download URL scrapy_ingest-1.1.0-py3-none-any.whl
Size 35.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
addf5e040e79981222b2067e3ab11dcc06ae7af1f6114670aee255fac00f702b
BLAKE2b-256 checksum
How to use checksums
cee3c70807c52605f634a926883effb7744f91dc1b281844d5b9ddb59e6b6af2
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

1.1.1

2 release files

This release

1.1.0 This release

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