Skip to main content

Scrapy Ingest

A Scrapy addon that saves items, requests, logs, and stats to PostgreSQL — 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,
}

# Pick ONE of the two database config styles:
DB_URL = "postgresql://user:password@localhost:5432/database"
# Or use discrete fields (avoids URL encoding):
# DB_TYPE = "postgres"
# DB_HOST = "localhost"
# DB_PORT = 5432
# 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.

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) — used when building a URL from DB_HOST / 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
  • 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 (spider-YYYYMMDDHHMMSS-xxxxxxxx)

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.0.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.0.0
File Size Uploaded
scrapy_ingest-1.0.0.tar.gz 25.0 kB Details

Built distribution (wheel)

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

Total release size: 56.5 kB

Release files / scrapy_ingest-1.0.0.tar.gz

Download URL scrapy_ingest-1.0.0.tar.gz
Size 25.0 kB
Tags Source
SHA-256 checksum
How to use checksums
dcdc4a4d3ef3346ff8a996a37a75b98e24dd8c13797ed59000fcf8daa607cdda
BLAKE2b-256 checksum
How to use checksums
696ec97ccd44a3fc5d4d32093156e25a87016f723c18079defa6aad4774edaa2
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.0.0-py3-none-any.whl

Download URL scrapy_ingest-1.0.0-py3-none-any.whl
Size 31.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
62f087a4a4cd68cb7451447c95de8204fe1e6fe1e9145df4413a084e14206ca2
BLAKE2b-256 checksum
How to use checksums
7572e8d7822da71a7a531af34e83cc733885652a09ef1fa6e20cb743ac60d06f
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

1.1.0

2 release files

This release

1.0.0 This release

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