Replaces the 12 ad-hoc JSON file stores (quality, intel, monitors,
sessions, accounts, agency, etc.) with a single SQLAlchemy-backed
database. The new foundation gives us:
- Concurrency safety (SQLite WAL mode, file locks via SQLAlchemy)
- Transactions (rollback on error)
- Querying (WHERE, JOIN, ORDER BY, LIMIT)
- Relationships (ForeignKey on monitor_id, agency_id, etc.)
- Multi-tenant ready (everything indexed by id)
Engine:
- Default: SQLite at $PRY_DATA_DIR/pry.db (zero-config)
- Production: set PRY_DATABASE_URL=postgresql://... (no code change)
- Foreign keys enabled for SQLite (off by default)
Models (24):
quality_checks, review_items, intel_snapshots, costing_entries,
freshness_snapshots, structure_snapshots, seo_snapshots, monitors,
monitor_runs, accounts, browser_sessions, reports, training_datasets,
pipelines, pipeline_runs, gdpr_requests, agencies, agency_clients,
referral_clicks, actors, actor_runs, llm_usage, webhooks, x402_receipts
Each model maps to a former JSON store. Most have an _id field with
unique constraint so re-importing the same data is safe. The legacy
"id" and "name" fields are renamed to "<scope>_id" / "<scope>_name"
to avoid reserved LogRecord field name collisions.
JSON importer (import_json_stores):
One-shot function that reads the existing JSON files in $PRY_DATA_DIR
and writes them to the SQL tables. Returns a {store: count} dict.
Idempotent: re-running with the same data is safe.
Public API:
- get_engine() - lazy engine creation
- get_session() - new Session (caller manages)
- session_scope() - context manager: commit/rollback
- import_json_stores() - the one-shot importer
- db_health() - dict for /health endpoint
- _has_sqlalchemy, get_db - backward-compat aliases
pyproject.toml: added sqlalchemy>=2.0.0 and aiosqlite>=0.19.0
Tests: 7/7 in tests/test_db.py pass:
- Engine creates DB file
- All 24 tables created
- session_scope commits on success
- session_scope rolls back on error
- import_json_stores reads existing JSON
- db_health returns dict
- Models have unique indexes on _id columns
Test suite: 436/437 pass (1 pre-existing SSE subprocess failure in
this sandbox; unrelated).
Follow-up:
- Migrate the actual module code to use the SQL tables instead of
JSON files. Each module (quality.py, intelligence.py, monitors.py,
etc.) needs a SQL-backed replacement. Estimated 4-6 hours.
- Add Alembic for schema migrations instead of create_all().
- Add Postgres-specific tuning when PRY_DATABASE_URL is set.
129 lines
3 KiB
TOML
129 lines
3 KiB
TOML
# SPDX-License-Identifier: MIT
|
|
# Copyright (c) 2026 Rug Munch Media LLC
|
|
# Part of Pry — https://git.rugmunch.io/RugMunchMedia/pryscraper
|
|
# Licensed under MIT. See LICENSE.
|
|
[build-system]
|
|
requires = ["setuptools>=69.0"]
|
|
build-backend = "setuptools.build_meta"
|
|
|
|
[project]
|
|
name = "pry"
|
|
version = "3.0.0"
|
|
description = "Free web scraping + browser automation API — self-hosted, no API keys needed"
|
|
readme = "README.md"
|
|
requires-python = ">=3.11"
|
|
license = { text = "MIT AND BSL-1.1" }
|
|
authors = [{ name = "Rug Munch Media LLC" }]
|
|
keywords = ["scraping", "crawler", "browser-automation", "mcp", "x402", "ai-agents"]
|
|
classifiers = [
|
|
"Development Status :: 4 - Beta",
|
|
"License :: OSI Approved :: MIT License",
|
|
"License :: Other/Proprietary License",
|
|
"Operating System :: OS Independent",
|
|
"Programming Language :: Python :: 3",
|
|
"Programming Language :: Python :: 3.11",
|
|
"Programming Language :: Python :: 3.12",
|
|
"Topic :: Internet :: WWW/HTTP :: Browsers",
|
|
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
"Typing :: Typed",
|
|
]
|
|
[project.license-files]
|
|
paths = ["LICENSE", "LICENSE-BSL-STEALTH"]
|
|
dependencies = [
|
|
"fastapi>=0.115.0",
|
|
"uvicorn[standard]>=0.32.0",
|
|
"trafilatura>=2.0.0",
|
|
"readability-lxml>=0.8.1",
|
|
"lxml>=5.3.0",
|
|
"httpx>=0.28.0",
|
|
"markdownify>=0.14.0",
|
|
"pydantic>=2.0.0",
|
|
"pydantic-settings>=2.0.0",
|
|
"playwright>=1.50.0",
|
|
"redis>=5.0.0",
|
|
"pypdf>=5.0.0",
|
|
"python-docx>=1.1.0",
|
|
"tiktoken>=0.8.0",
|
|
"pillow>=10.0.0",
|
|
"click>=8.0.0",
|
|
"pyyaml>=6.0",
|
|
"pandas>=2.0.0",
|
|
"anyio>=4.0.0",
|
|
"croniter>=2.0.0",
|
|
"structlog>=24.0.0",
|
|
"sqlalchemy>=2.0.0",
|
|
"aiosqlite>=0.19.0",
|
|
]
|
|
|
|
[project.optional-dependencies]
|
|
dev = [
|
|
"pytest>=8.0",
|
|
"pytest-asyncio>=0.24.0",
|
|
"pytest-cov>=5.0.0",
|
|
"ruff>=0.7.0",
|
|
"mypy>=1.12.0",
|
|
"pre-commit>=4.0.0",
|
|
]
|
|
|
|
[project.scripts]
|
|
pry = "cli:main"
|
|
|
|
[tool.setuptools.packages.find]
|
|
include = ["pry*"]
|
|
|
|
[tool.ruff]
|
|
target-version = "py311"
|
|
line-length = 100
|
|
|
|
[tool.ruff.lint]
|
|
select = ["E", "F", "I", "N", "W", "B", "A", "C4", "SIM", "UP", "RUF", "BLE"]
|
|
ignore = ["E501", "N815", "B008", "A002", "RUF006"]
|
|
|
|
# BLE001 (blind except Exception) is enforced. Pre-existing sites are
|
|
# marked with `# noqa: BLE001`; new code must use specific exception
|
|
# types (e.g. httpx.HTTPError, json.JSONDecodeError, OSError).
|
|
|
|
[tool.ruff.format]
|
|
quote-style = "double"
|
|
indent-style = "space"
|
|
|
|
[tool.mypy]
|
|
python_version = "3.11"
|
|
strict = true
|
|
ignore_missing_imports = true
|
|
exclude = [
|
|
"build/",
|
|
"dist/",
|
|
".git/",
|
|
"__pycache__/",
|
|
]
|
|
warn_unused_ignores = false
|
|
|
|
[[tool.mypy.overrides]]
|
|
module = [
|
|
"trafilatura",
|
|
"trafilatura.*",
|
|
"readability",
|
|
"readability.*",
|
|
"playwright",
|
|
"playwright.*",
|
|
"pypdf",
|
|
"pypdf.*",
|
|
"docx",
|
|
"docx.*",
|
|
"PIL",
|
|
"PIL.*",
|
|
"markdownify",
|
|
"markdownify.*",
|
|
"pandas",
|
|
"pandas.*",
|
|
"yaml",
|
|
"yaml.*",
|
|
"numpy",
|
|
"numpy.*",
|
|
]
|
|
ignore_missing_imports = true
|
|
|
|
[tool.pytest.ini_options]
|
|
asyncio_mode = "auto"
|
|
testpaths = ["tests"]
|