Skip to content
Exalt24Public

About

Django and Postgres pipeline for auto parts supplier feeds, with REST and Meilisearch search. Invented data.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Camlobe

CI

A terminal replay of the real command output: three sample suppliers ingested, one feed refused for a renamed column, 19,098 parts matched, a second pass that changes nothing

Replayed from the output of python manage.py run_demo --brief (captured text).

The word REFUSED and its reason are fixed text in that view for any failed file. Everything in it runs on generated sample data in a local database.

A Django and PostgreSQL pipeline that ingests auto parts catalogs from several suppliers' feeds and matches the same part across them without guessing.

It normalises part numbers first, and serves the result through REST and a Meilisearch index. The normaliser also exists as a Rust port that is checked against the Python on every code point (the port).

On 20,000 generated parts, 40,008 stored feed rows from three suppliers became 19,098 parts. 14,106 of them are listed by two or more suppliers. A second pass wrote nothing new. Five sources are skipped on a matching content hash, and the row level case is tested (run output). At 2,500 parts a test (tests/test_pipeline_truth.py) finds no part merged wrongly or split against the generator's own truth file.

What it is and why it exists

A parts distributor sends a catalog in whatever shape its export tool produces. The same part can arrive as MF-H4123A, h 4123 a or 0000451233. A column can be renamed in the middle of the month, and a file can come in two encodings. The pipeline has to keep what was received, turn it into one canonical catalog, and be safe to run again after a crash. This repository is that pipeline running on a data generator I wrote, since a supplier's own feed cannot be published.

Three sample suppliers, each with its own faults, feed one universe of parts:

Supplier Format Faults on purpose
redline CSV, windows-1252 lines pasted as UTF-8, undefined bytes, exact duplicate rows, blank part numbers, N/A costs
harbor XML brand missing on some items, zero padded numbers, a renumbered part that reuses another part's barcode
delta four CSV files with a BOM columns reordered, two columns renamed to a known alias, then one renamed to something unknown

What it does

flowchart LR
  F[Feed: file, SFTP, REST, SOAP, scraped site] --> I[ingest_feed]
  I -->|append only| R[(RawPart)]
  I --> X[(Rejected rows with a reason)]
  R --> N[normalize_parts]
  N --> M[match_parts]
  M --> P[(Part and PartSource)]
  M --> Q[(Review queue)]
  P --> S[Meilisearch index]
  P --> A[REST API]
Loading
Stage Command What is guaranteed
Ingest ingest_feed the raw row is stored as received and never changed (a trigger refuses row UPDATE and DELETE for ordinary roles); a second run over the same source changes nothing in the catalog (a repeated listing of one part adds one rejected row per run); a killed run resumes at its checkpoint; for a supplier flagged as sending its whole catalog, a part missing from a complete run is delisted (feeds)
Normalise normalize_parts one canonical number per row, with the rules that fired recorded (rules)
Match match_parts the same brand and number across suppliers is one part; a row with no brand or with a conflicting barcode goes to a review queue instead of being merged (rule)
Index rebuild_search_index, sync_search_index the rebuild resumes and swaps in at the end; the sync sends only parts that changed
Serve runserver search, part detail with sources and fitment, vehicle fitment, run status (API)
Background celery -A config worker, celery -A config beat a feed run is a Celery task on Redis: a worker that loses the Postgres lock steps aside, a dropped connection is retried with backoff and a bad file is not, and a run resumes at its checkpoint (background runs)
Orders edi_po, edi_parse an X12 850 built from a supplier's own part numbers, and readers for 855, 856 and 810 (EDI)

Feed adapters sit behind one interface: feeds. They are a local file, SFTP, paged REST with rate limit and retry, SOAP, and an HTTP scraper for a site with a login. The scraper was tested against a local fake site only: see Limits.

Measured

Windows 11 desktop, Docker Postgres 17 on localhost, one process. Counts and timings are from the saved runs below.

Run Raw rows Parts Listed by 2 or more suppliers Review queue Ingest per file Normalise Match
20,000 parts (output, same counts again after two fixes: output, and after the review fixes below: output) 40,008 19,098 14,106 500 1.1 to 2.0 s 3.3 s 11.0 s
100,000 parts (output) 199,886 95,345 70,468 2,518 5.2 to 11.4 s 20.0 s 65.7 s

python manage.py check_query_plans runs EXPLAIN ANALYZE on the queries the pipeline and API depend on. It fails when one stops using its index. At 20,000 parts the checked queries (eight in the captured demo, nine in the later runs) each took under 3 ms.

Public source crawler

crawl/ is a Scrapy project that reads public sources into Postgres, JSON lines and CSV. Its spiders are news_rss (RSS 2.0 and Atom with rel="next" paging), forum_threads, reviews (schema.org microdata) and reddit_listing (Reddit's official OAuth API, never its pages). Notes per spider and the rest are on the crawler page. apify_actor and firecrawl_scrape hand a page to Apify or Firecrawl.

An item pipeline cleans, tags, dedupes and stores. A mention is stored once whether it repeats in a run, returns on a later run, carries a tracking parameter or is the same text at another address. The crawler obeys robots.txt, waits 2 s with jitter plus AutoThrottle, retries a 429 or 5xx three times, holds for Retry-After and ends the run on a 403. python -m publicsources.healthcheck exits 1 and writes an ALERT line when a source parsed nothing, matched no known layout, was blocked or went stale. Cron and systemd files in crawl/deploy run it every six hours; tests check them and they were not installed here.

On the saved run against a local stand-in server three sources parsed 15 rows and stored 13, and a second pass stored 0 (output). cd crawl && python -m pytest runs 207 tests (output). python tests/mutation_controls.py breaks the crawler 36 ways and all 36 turn a test red (output). The feed, forum, review and Reddit spiders ran against stand-ins written from the real page shapes: no live site was read and Reddit was never called.

Two optional stages add to a new mention. CRAWL_VIDEO_META=1 reads a linked public video's title, channel, duration and captions with yt-dlp and downloads no media (notes). CRAWL_LLM=1 asks a model for a summary, tags and a sentiment as strict JSON, re-asking once (notes). Apify, Firecrawl, yt-dlp and Groq each ran for real once on free plans on 2026-12-01 (outputs are listed on the crawler page).

What was hard

  • A blank column nobody had read. Scrapy 2.20 no longer passes the spider to process_item, so the run_id of every stored row was empty. It showed in the CSV of the first real run, not in a test. It is now read from the crawler, and a test asserts that every row names its run (more).
  • A search setting that hid new parts. Turning typo tolerance off for part numbers only, per attribute, worked on the first build. It made every part number added afterwards unfindable on Meilisearch 1.12.8. The sync test test_a_part_added_after_the_build_is_found_by_its_number caught it. Typo tolerance is now off for the whole index. That also costs typo tolerance on description words.
  • Rows re read after a gap. A paged source whose page 2 fails keeps its checkpoint at the gap. The pages after it are read again on the next run. A row is unchanged only when it equals the newest stored version of its part (a key that exists proves nothing about that). The generated tests in tests/test_output_round_3.py pin it.
  • A mutation harness that edited nothing. Two guards that span several lines in files with CRLF line endings were never edited. Their mutants were reported as survivors that were not real. The harness now matches on LF text. It refuses to report a mutation that changed nothing.
  • A search that missed a quarter of the numbers a supplier prints. A reviewer who had not seen the code sampled 400 supplier-written numbers. They came from the generator's truth file. 125 found nothing on either backend. The query was normalised with no brand, so DU-ZR7208 kept its prefix and a Kestrel number lost its real leading zero. A query is now tried in every form a supplier might print, against both backends through one function. The same 400 give 0 misses on both.
  • A guard that did nothing. One mutant survived. The guard it removed was redundant with the line after it (indexed_version is set to the version that was sent, so a part edited mid send stays behind anyway). The dead condition was removed and a mutant for the real defect was added.

Run it

No account or key is needed. Docker, Python 3.13 and Git Bash on Windows 11 are what it was run with.

docker compose up -d --wait                # Postgres 17 on 5434, Meilisearch on 7701, Redis on 6381, waits until all three are healthy
python -m venv .venv && . .venv/Scripts/activate    # macOS or Linux: . .venv/bin/activate
pip install -r requirements-dev.txt
python manage.py migrate
python manage.py run_demo                  # generate, ingest, match, fitment, plans, index, then again (the saved 20,000 part run shows about 25 s of stages plus the index)

run_demo needs an empty database. It prints every stage with its timing and, without --brief, ends in a summary that matches the first table above. Windows 11 is the setup it was run on. The macOS and Linux activate line is the standard equivalent.

Then python manage.py runserver and, for example, curl "localhost:8000/api/parts/search/?q=zr%200014%20p". The feed runs table is at localhost:8000/runs/: an AG Grid page over /api/feed-runs/, sortable and filterable, refreshing every few seconds while a run is going.

The feed runs page: four runs in AG Grid, three succeeded and one failed on a renamed column, each with its read, written, unchanged and rejected counts

A screenshot of the real page against the local database after four runs of the sample feeds.

Tests

python -m pytest tests/ -o addopts=""      # 1,025 tests (1,023 in the last full run, two link guard tests came after), about 8 minutes, needs Postgres on 5434, Meilisearch on 7701 and, for one test that starts a real worker, Redis on 6381
python tools/mutation_check.py             # 323 guards, about 20 minutes, edits source in place: run it in a copy (--help)

The database tests use the compose Postgres and create their own test_camlobe database. The search tests skip when Meilisearch is down, and the CI workflow starts both.

1,023 tests passed in a full run by someone else on 2026-10-26. All 323 mutation guards were killed in a full run the same day. The run outputs, the earlier counts and the notes on the random worlds, the killed process and the mutation harness are in docs/tests.md.

Register: what ran and what did not

Everything ran on Docker on Windows 11, against stand-ins and generated data. The stand-ins are an SFTP server inside the test process, local fake REST, SOAP and shop sites, and sample X12 documents read by my own reader. The data generator's truth file is the matching oracle. The full table of what ran here and what is next to try is in docs/register.md.

Limits

  • HTTP scraping is built and was run against a local stand-in shop site and a local forwarding proxy. A live site's login, markup and limits will differ. So will a proxy service, a CAPTCHA or a web firewall. It checks robots.txt, spaces its requests, honours Retry-After and stops on a block or a challenge without trying to get past it. A page the site cut short, an empty table or a body shorter than announced ends the run as partial and never as a success. None of that is permission. Use it only on a site whose owner has allowed it, with its terms read (feeds).
  • Known limits of the scraper, not fixed. They are rowspan in a product table and a price cell with two bare whole amounts split by one space and no currency sign. 12 345 reads as one price, and $20 $15 is refused. A body that trickles bytes is bounded per socket read and not in total. A SOCKS proxy was only tried against a refused connection, never a working one.
  • A delisting rests on one snapshot per supplier. A supplier that sends two full feeds at once (brakes in one file, filters in another) must not be flagged. A feed that is truncated but reads cleanly is only caught when it would delist more than half the listings. A file cut inside a quote, or short of the header's fields in its last row, is a partial run.
  • Known limit, not fixed. An index rebuild can crash between the swap and the deletion of the staging index. If it is then resumed, the old index can be put back live. The sync cannot repair it, because it only sends parts whose version is behind. The cure is rebuild_search_index --restart.
  • More limits (paged sources, secrets in URLs, search, fitment, generated data, number rules, matching, the API, adapter expectations and the X12 reader) are in docs/limits.md.
  • Next steps for the name: an independent review of the mark in brand/ and a trademark search (brand file).

Stack

Python 3.13, Django 5.2, Django REST framework, Scrapy, PostgreSQL 17, Meilisearch, Celery with Redis, AG Grid Community, paramiko, zeep, requests with SOCKS support, defusedxml, beautifulsoup4 with lxml, pytest and Hypothesis, Docker Compose, GitHub Actions.

License

MIT, see LICENSE.

About

Django and Postgres pipeline for auto parts supplier feeds, with REST and Meilisearch search. Invented data.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages