{"id":23001,"library":"xblock","title":"Open edX XBlock Core Library","description":"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.","status":"active","version":"6.1.0","language":"python","source_language":"en","source_url":"https://github.com/openedx/XBlock","tags":["edx","openedx","learning","xblock","lms"],"install":[{"cmd":"pip install xblock","lang":"bash","label":"PyPI install"}],"dependencies":[{"reason":"Provides Fragment class used by XBlock for rendering","package":"web-fragments","optional":false},{"reason":"Filesystem abstraction for resource loading","package":"fs","optional":false},{"reason":"Caching backend for XBlock runtime","package":"python-memcached","optional":true}],"imports":[{"note":"XBlock class is in xblock.core module, not top-level xblock","wrong":"from xblock import XBlock","symbol":"XBlock","correct":"from xblock.core import XBlock"},{"note":"As of v4.0.0, Fragment moved to web-fragments package; old import still works but deprecated","wrong":"from xblock.fragment import Fragment","symbol":"Fragment","correct":"from web_fragments.fragment import Fragment"},{"note":null,"wrong":null,"symbol":"Scope","correct":"from xblock.fields import Scope"},{"note":null,"wrong":null,"symbol":"String","correct":"from xblock.fields import String"}],"quickstart":{"code":"from xblock.core import XBlock\nfrom xblock.fields import Integer, Scope\nfrom web_fragments.fragment import Fragment\n\nclass SimpleBlock(XBlock):\n    count = Integer(default=0, scope=Scope.user_state)\n\n    def student_view(self, context=None):\n        html = f'<p>Count: {self.count}</p>'\n        return Fragment(html)\n\n    @XBlock.json_handler\n    def increment(self, data, suffix=''):\n        self.count += 1\n        return {'count': self.count}","lang":"python","description":"Define a minimal XBlock with a student view and a JSON handler."},"warnings":[{"fix":"Use 'from web_fragments.fragment import Fragment' instead of 'from xblock.fragment import Fragment'.","message":"Fragment 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.","severity":"breaking","affected_versions":">=4.0.0"},{"fix":"Access runtime via 'self.runtime' directly.","message":"XBlock.runtime is deprecated. Use self.runtime instead.","severity":"deprecated","affected_versions":">=5.0.0"},{"fix":"Use Scope.user_state for user-specific data that persists per block instance.","message":"Scope.user_state is per-user, but if you want per-user per-block-instance you need Scope.user_state. Scope.preferences is deprecated.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Install web-fragments and use 'from web_fragments.fragment import Fragment'","cause":"Fragment moved to web-fragments package in XBlock v4.0.0","error":"ImportError: cannot import name 'Fragment' from 'xblock.fragment'"},{"fix":"Ensure your XBlock __init__ accepts and forwards runtime: def __init__(self, runtime, *args, **kwargs): super().__init__(runtime, *args, **kwargs)","cause":"XBlock subclasses should call super().__init__(**kwargs) and pass runtime as a keyword argument","error":"TypeError: __init__() got an unexpected keyword argument 'runtime'"},{"fix":"Make sure the runtime provides a scope_ids attribute, or set it before accessing fields with user-specific scopes.","cause":"XBlock requires scope_ids to be set by the runtime; usually from the definition or usage key","error":"AttributeError: 'MyBlock' object has no attribute 'scope_ids'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}