Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Scrapy · Class

Field

scrapy.Field is a dictionary-like metadata container used to declare fields on Scrapy Item subclasses. It can store configuration such as a serializer, while Scrapy records declared fields in Item.fields.

How it works

Field is a metadata container used when declaring Scrapy item attributes. It behaves like a plain dictionary, so metadata can be supplied as keyword arguments; the declared Field objects are collected in the item’s fields mapping rather than remaining as class attributes.

Syntax

class scrapy.Field

Parameters

NameTypeDescription
**kwargsAnyOptional field metadata supplied as dictionary entries, commonly through keyword arguments such as serializer.

Returns

A plain dictionary containing the supplied field metadata.

Key points

  • Use Field declarations to keep per-field metadata alongside the item schema.
  • A field declaration centralizes metadata instead of scattering it across crawler components.
  • Item subclasses declare fields as class attributes, and Scrapy collects those declarations.
  • The Item schema rejects unknown field names, helping catch misspellings.
  • Item.fields maps each declared name to its corresponding Field metadata dictionary.

Common mistakes

  • Field is not a specialized field-value object: it is simply a dictionary alias and adds no behavior of its own.
  • Do not expect the declaration attribute to contain the Field after item construction; inspect the item’s fields mapping instead.

Example: Declare fields on an item

import scrapy

class Product(scrapy.Item):
    name = scrapy.Field()
    price = scrapy.Field(serializer=float)

product = Product(name="Book", price="12.50")
assert product["price"] == "12.50"
assert product.fields["name"] == {}

Declare item fields with Field and optionally place metadata such as a serializer in the field mapping.

When to use it

Declare item fields

Define the schema of scraped records with named attributes.

Store field metadata

Attach serializer or other processing metadata to a field.

Examine Item.fields

Inspect the complete declared schema of an Item subclass.

Interview questions

QWhat is scrapy.Field?

Field is used to declare an item field and hold metadata for it. The class itself is a plain dictionary alias, without extra functionality or attributes.

Follow-up: Where can declaration metadata be inspected after class creation? In the Item.fields mapping, whose values are the Field objects used in the declaration.

QHow can Field carry field metadata?

A Field can be created without metadata or with metadata entries such as serializer=str. Those entries provide a central place to describe how the field is handled internally.

Follow-up: Does Field itself run the serializer? No; it stores metadata, while other Scrapy processing uses that metadata.

QHow is Field used in an Item declaration?

Fields are declared as class attributes on an Item subclass, for example name = scrapy.Field(). Scrapy processes those declarations and stores them in the item’s fields attribute.

Follow-up: What does the fields mapping contain? All declared fields, including fields that have not yet been populated.

  • scrapy.Item
  • Item.fields
  • itemadapter
  • serializer

Source: Items — Scrapy 2.19.0 documentation. Checked 2026-10-15.