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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.458s · 41MB
glibcpy 3.10–3.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}
Errors
Common errors & fixes
ImportError: cannot import name 'Fragment' from 'xblock.fragment'
Fragment moved to web-fragments package in XBlock v4.0.0
fixInstall 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
fixEnsure 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
fixMake 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