ArticleHow To

Git Workflow For Scrapy Projects

Git Workflow for Scrapy Projects - Streamline your Scrapy projects with an efficient Git workflow. Improve collaboration and project management.

Pablo Hoffman

2 min read ·

Git Workflow For Scrapy Projects

Git workflow for Scrapy projects

Our customers often ask us what's the best workflow for working with Scrapy projects. A popular approach we have seen and used in the past is to split the spiders folder (typically project/spiders) into two folders: project/spiders_prod and project/spiders_dev, and use the SPIDER_MODULES setting to control which spiders are loaded on each environment. This works reasonably well until you have to make changes to common code used by many spiders (ie. code outside the spiders folder), for example, common base spiders.

Nowadays, DVCs (in particular, git) have become more popular and people are quite used to branching, so we recommend using a simple git workflow (similar to GitHub flow) where you branch for every change you make. You keep all changes in a branch while they're being tested and finally merge to master when they're finished. This means that the master branch is always stable and contains only "production-ready" spiders.

If you are using our Scrapy Cloud platform, you can have 2 projects (myproject-dev, myproject-prod) and use myproject-dev to test the changes in your branch.  scrapy deploy in Scrapy 0.17 now adds the branch name to the version name (when using version=GIT or version=HG), so you can see which branch you are going to run directly on the panel. This is particularly useful with large teams working on a single Scrapy project, to avoid stepping into each other when making changes to common code.

Here is a concrete example to illustrate how this workflow works:y

  1. the developer decides to work on issue 123 (could be a new spider or fixes to an existing spider)

  2. the developer creates a new branch to work on the issue

    git checkout -b issue123
    
  3. the developer finishes working on the code and deploys it to the panel (this assumes scrapy.cfg is configured with a deploy target, and using version=GIT - see here for more information)

    scrapy deploy dev
    
  4. the developer goes into the panel and runs the spider, where he'll see the branch name (issue123) that will be run

  5. the developer checks the scraped data looks fine through the item browser in the panel

  6. whenever issues are found, the developer makes more fixes (always working on the same branch) and deploys new versions

  7. once all issues are fixed, the developer merges the branch and deploys it to the production project

    git checkout master git merge issue123 git pull # make sure to pull latest code before deploying scrapy deploy prod
    

We recommend you keep your common spiders well-tested and use Spider Contracts extensively to test your final spiders. Otherwise, experience tells us that base spiders end up being copied (instead of reused) out of fear of breaking old spiders that depend on them, thus turning their maintenance into a nightmare.

Try Zyte API

Build your first scraper in minutes

Free trial, no credit card. From a single request to production in an afternoon.

Get started

Pablo Hoffman

Pablo has worked in open source for 13+ years. He founded Insophia in 2007 — the first Uruguayan company built exclusively on Python — where his team created and open-sourced Scrapy, now the standard Python web crawling framework. In 2010 he founded Scrapinghub (now Zyte) to buil…

More from this author

Continue reading

harness-engineering-3
AI

Harness Engineering #3- Headless mode: the minimal agent harness

Harness engineering part 3: headless mode runs a coding agent without the chat. Point it at a web page and get structured data back in about ten lines.

Ayan Pahwa12 min read
A stream of web pages flowing from a globe through a gateway into a vector database
Data gathering for AI

Web Scraping for RAG: Build a Reliable Pipeline with Zyte API, Qdrant and LangChain

Build a RAG pipeline that survives bot blocks and JavaScript pages: fetch LLM-ready Markdown with Zyte API, gate bad pages, and test it before deploying.

Ayan Pahwa
Inside Scrapy's RemoteControl extension
How To

Inside Scrapy's RemoteControl extension

Scrapy 2.19's RemoteControl extension runs a small authenticated HTTP server inside every crawl. How it starts, how it's secured, what the code you send can reach, and what you can do with it on a live crawl, plus the traps and what changes under scrapy-zyte-api.

John Rooney
One scrapy-playwright Spider, Three Browser Setups: Playwright, Patchright, and Zyte
How To

One scrapy-playwright Spider, Three Browser Setups: Playwright, Patchright, and Zyte

One Scrapy spider, three browser setups: stock Playwright, Patchright via the new PLAYWRIGHT_BROWSER_PROVIDER hook, and a remote browser on Zyte over CDP. Same spider and selectors throughout, only the browser changes.

John Rooney
playwright-zyte-cdp
How To

Running Playwright at scale: connecting to the Zyte CDP browser

We've released our CDP Browser, ideal for those with existing Playwright scripts looking for better access, as well as developers who need granular control over a browser, but don't want the hassle of running locally.

John Rooney
Zyte Blog — field notes from the world of data extraction
How To

The Modern Web Scraping Method You NEED to Know

Learn how to scrape data in json format from a websites API

John Rooney11 min read

The Community · Newsletter

The best of Zyte and the data web, in your inbox.

One curated edition — new articles, product updates, and the stories shaping the data web. No noise.