Registry / web-framework / xblock

xblock

JSON →
library6.3.0pypypi✓ verified 85d ago

XBlock is the core library for the Open edX learning platform component architecture. It provides the framework for creating, managing, and rendering course content blocks with support for runtime integration, user state, and scoring. Current version is 6.1.0, with releases every few months.

pip install xblock
INSTALL
IMPORT
SIG · XBLOCK
X
xblock
web-frameworkpythonv6.3.0
Install
4.0s avg
Import
445ms
Disk
49MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v6.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.458s · 41MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 4.0s · import 0.432s · 42MB
49MB installed
● package 49MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

XBlock
from xblock.core import XBlock
from xblock import XBlock
XBlock class is in xblock.core module, not top-level xblock
Fragment
from web_fragments.fragment import Fragment
from xblock.fragment import Fragment
As of v4.0.0, Fragment moved to web-fragments package; old import still works but deprecated
Scope
from xblock.fields import Scope
String
from xblock.fields import String

Define a minimal XBlock with a student view and a JSON handler.

from xblock.core import XBlock from xblock.fields import Integer, Scope from web_fragments.fragment import Fragment class SimpleBlock(XBlock): count = Integer(default=0, scope=Scope.user_state) def student_view(self, context=None): html = f'<p>Count: {self.count}</p>' return Fragment(html) @XBlock.json_handler def increment(self, data, suffix=''): self.count += 1 return {'count': self.count}
Debug
Known issues
breakingFragment class moved from xblock.fragment to web_fragments.fragment in v4.0.0. The old import path still works via a compatibility shim but will be removed in a future release.
fix
Use 'from web_fragments.fragment import Fragment' instead of 'from xblock.fragment import Fragment'.
affects: >=4.0.0
deprecatedXBlock.runtime is deprecated. Use self.runtime instead.
fix
Access runtime via 'self.runtime' directly.
affects: >=5.0.0
gotchaScope.user_state is per-user, but if you want per-user per-block-instance you need Scope.user_state. Scope.preferences is deprecated.
fix
Use Scope.user_state for user-specific data that persists per block instance.
affects: all
Errors
Common errors & fixes
ImportError: cannot import name 'Fragment' from 'xblock.fragment'
Fragment moved to web-fragments package in XBlock v4.0.0
fix
Install web-fragments and use 'from web_fragments.fragment import Fragment'
TypeError: __init__() got an unexpected keyword argument 'runtime'
XBlock subclasses should call super().__init__(**kwargs) and pass runtime as a keyword argument
fix
Ensure your XBlock __init__ accepts and forwards runtime: def __init__(self, runtime, *args, **kwargs): super().__init__(runtime, *args, **kwargs)
AttributeError: 'MyBlock' object has no attribute 'scope_ids'
XBlock requires scope_ids to be set by the runtime; usually from the definition or usage key
fix
Make sure the runtime provides a scope_ids attribute, or set it before accessing fields with user-specific scopes.
Upgrade
Version history
6.3.0latest on PyPI · released Jun 12, 2026
Audit
Dependencies
web-fragmentsrequiredProvides Fragment class used by XBlock for rendering
fsrequiredFilesystem abstraction for resource loading
python-memcachedoptionalCaching backend for XBlock runtime
Agent activity
36 hits · last 30 days
node
32
OpenAI (training)
1
Resources
xblock — pip install xblock · libregistry