Package: openedx-blockstore
PurposeBlockstore is a system for storing versioned, reusable educational content for Open edX.It is designed as a replacement formodulestore. It is meant to be a lower-level service than the modulestore, and is designed around the concept of storing small, reusable pieces of content, rather than large, fixed content structures such as courses. For Open edX, Blockstore is designed to facilitate a much greater level of content re-use than is currently possible, enable new adaptive learning features, and enable delivery of learning content in new ways (not just large traditional courses).ComparisonSystemModulestoreBlockstoreGoalDesigned to store courses consisting of a hierarchy of XModules (and later, XBlocks)Designed around the concept of storing small, reusable pieces of content which are simply files. Can be used for content libraries, courses, or any other purpose.Stores data inMongoDBS3 (or similar)Stores XBlock data asJSON field data, with “settings” and “content” fields separated in different documentsOLXContent re-useVery limited supportBuilt in supportFocusIncludes deeply integrated XModule runtime, increasing complexityNot aware of XBlocks; XBlock runtime is implementedseparatelyAssociated XBlock runtime (LMS)LmsModuleSystemBlockstoreXBlockRuntimeImage/PDF/other asset files used for each XBlock are storedIn MongoDB at the course level (contentstore/GridFS)Alongside each XBlock’s OLX file. Associated with the individual XBlock, not the course.Blockstore was originally developed by Harvard’sLabXchangeand theAmgen Foundation, along withedX.Current StatusAs ofApril 2022(“master” version of Open edX) or theNutmegnamed release of Open edX, Blockstore is included as a django app within Open edX platform. Seemoving blockstore into edx-platformfor an explanation of this. Prior to those versions, Blockstore was only available as an independent application, and was not included in any Open edX installations by default.Blockstore is used to power theContent Libraries v2feature of Open edX. It isnotdirectly used for course functionality, nor for the “v1” Content Libraries feature.Design DetailsSeeDESIGNfor an overview of Blockstore’s design as it exists today. See“Blockstore Design”on the wiki for historical context.Getting StartedThe easiest way to try out the “Content Libraries v2” feature along with Blockstore is to use the Tutor devstack andthe library-authoring MFE Tutor plugin. See that plugin’s README for details.Running Integration TestsOpen edX includes some integration tests for Blockstore, which run by default as part of the test suite. To run them manually, from a Studio/CMS shell, run these commands:python -Wd -m pytest --ds=cms.envs.test openedx/core/lib/blockstore_api/ openedx/core/djangolib/tests/test_blockstore_cache.py openedx/core/djangoapps/content_libraries/tests/
python -Wd -m pytest --ds=lms.envs.test openedx/core/lib/blockstore_api/ openedx/core/djangolib/tests/test_blockstore_cache.py openedx/core/djangoapps/content_libraries/tests/To run these integration tests while using Elasticsearch, addEDXAPP_ENABLE_ELASTICSEARCH_FOR_TESTS=1to the beginning of the above commands. To run these integration tests while using a specific container’s version of Elasticsearch, also addEDXAPP_TEST_ELASTICSEARCH_HOSTwith a specific container name on the above commands:EDXAPP_ENABLE_ELASTICSEARCH_FOR_TESTS=1 EDXAPP_TEST_ELASTICSEARCH_HOST=edx.devstack.elasticsearch710 python -Wd -m pytest ...Using in ProductionBy default, blockstore is run as an app inside of Open edX. Enable it using the waffle switchblockstore.use_blockstore_app_api.If you need to run blockstore as a separate service (e.g. for scalability or performance reasons), you can deploy blockstore in production usingthe blockstore ansible role.Development in DevstackIf you want to develop blockstore as a local python package installed in edx-platform, use the following steps:Prerequisite: Have an Open edXDevstackproperly installed and working. Your devstack must use the Nutmeg release of Open edX (or newer) or be tracking themasterbranch ofedx-platform.To run blockstore as an app inside of Open edX, enable it by activating the waffle switchblockstore.use_blockstore_app_apiin LMS or Studio admin.Clone this repo in thesrc/directory, a sibling directory of your devstack folder.In your devstack directory, run the following commands in order:# bring up the lms +studio containers
make dev.up.large-and-slow
# Bring up the studio shell
make dev.shell.studio
# Unistall the pypi blockstore
pip uninstall openedx-blockstore #You will need to confirm the unistall with "Y".
#Install your local blockstore.
pip install -e /edx/src/blockstore/
exit

# do the same in the LMS
make dev.shell.lms
# Unistall the pypi blockstore
pip uninstall openedx-blockstore #You will need to confirm the unistall with "Y".
#Install your local blockstore.
pip install -e /edx/src/blockstore/
exit

#restart the servers to bring in changes.
make dev.restart-devserver.lms dev.restart-devserver.studio

# you can see that your env is now installed openedx-blockstore from a local directory ``/edx/src/blockstore`` by running:
make dev.shell.lms
pip listSeeing your changes will sometimes require running make requirements and then restarting the container.You’re probably also going to want to create a collection and organization for using content libraries from the devstack command line, using:# Create a "Collection" that new content libraries / xblocks can be created within:
 docker exec -t edx.devstack.lms bash -c "source ~/.bashrc && echo \"from blockstore.apps.bundles.models import Collection; coll, _ = Collection.objects.get_or_create(title='Devstack Content Collection', uuid='11111111-2111-4111-8111-111111111111')\" | ./manage.py lms shell"
# Create an "Organization":
docker exec -t edx.devstack.lms bash -c "source /edx/app/edxapp/edxapp_env && echo \"from organizations.models import Organization; Organization.objects.get_or_create(short_name='DeveloperInc', defaults={'name': 'DeveloperInc', 'active': True})\" | python /edx/app/edxapp/edx-platform/manage.py lms shell"The Library Authoring MFE will want to know about that collection idusing a ENV variable.Then restart Studio and the LMS (makedev.restart-devserver.lmsdev.restart-devserver.studio).You then can begin setting up thelibrary authoring MFEto use the feature of blockstore for content libraries V2.Running and testing as a separate serviceBlockstore was initially developed as an independently deployed application, which runs in a separate container/proccess from the LMS. It is still possible to run blockstore that way, both in production and development.To run it as an independent application in development:Prerequisite: Have an Open edXDevstackproperly installed and working. Your devstack must use the Nutmeg release of Open edX (or newer) or be tracking themasterbranch ofedx-platform.Clone this repo andcdinto it.To start the django development server inside a docker container, run this on
your host machine:make easyserverBlockstore is now running athttp://localhost:18250/. Now we need to configure Studio/LMS to work with it.Run these commands on your host computer:# Create a service user for the edx-platform to use when authenticating and making API calls
docker exec -t edx.devstack.blockstore bash -c "source ~/.bashrc && echo \"from django.contrib.auth import get_user_model; from rest_framework.authtoken.models import Token; User = get_user_model(); edxapp_user, _ = User.objects.get_or_create(username='edxapp'); Token.objects.get_or_create(user=edxapp_user, key='edxapp-insecure-devstack-key')\" | ./manage.py shell"
# Configure the LMS and Studio to use the key
docker exec -t edx.devstack.lms bash -c "grep BLOCKSTORE_API_AUTH_TOKEN /edx/app/edxapp/edx-platform/lms/envs/private.py || echo BLOCKSTORE_API_AUTH_TOKEN = \'edxapp-insecure-devstack-key\' >> /edx/app/edxapp/edx-platform/lms/envs/private.py"
docker exec -t edx.devstack.studio bash -c "grep BLOCKSTORE_API_AUTH_TOKEN /edx/app/edxapp/edx-platform/cms/envs/private.py || echo BLOCKSTORE_API_AUTH_TOKEN = \'edxapp-insecure-devstack-key\' >> /edx/app/edxapp/edx-platform/cms/envs/private.py"
# Create a "Collection" that new content libraries / xblocks can be created within:
docker exec -t edx.devstack.blockstore bash -c "source ~/.bashrc && echo \"from blockstore.apps.bundles.models import Collection; coll, _ = Collection.objects.get_or_create(title='Devstack Content Collection', uuid='11111111-2111-4111-8111-111111111111')\" | ./manage.py shell"
# Create an "Organization":
docker exec -t edx.devstack.lms bash -c "source /edx/app/edxapp/edxapp_env && echo \"from organizations.models import Organization; Organization.objects.get_or_create(short_name='DeveloperInc', defaults={'name': 'DeveloperInc', 'active': True})\" | python /edx/app/edxapp/edx-platform/manage.py lms shell"Then restart Studio and the LMS (makedev.restart-devserver.lmsdev.restart-devserver.studio).Now you should be able to use Blockstore in Studio.To edit Blockstore content libraries in Studio, you’ll need to install eitherthe Content Libraries v2 FrontendorRamshackle. Alternatively, you can use theContent Libraries v2 REST APIto create content programmatically.To use Blockstore library content in a course, open your course in Studio. In its advanced settings, addlibrary_sourcedto the list of “advanced block types”. In the “Unit Edit View” in Studio, find the green “Add New Component” buttons. Click Advanced > Library Sourced Content. Edit the new Library Sourced Content XBlock to enter the XBlock ID of the library content that you’d like to use. It should be similar tolb:DeveloperInc:MyLibrary:1(note:lb:is short for “Library Block” and should not be confused with thelib:prefix used to identify a library).Optional: To log in to Blockstore in your web browser directly, you’ll need to configure SSO with your devstack. Most people won’t need to do this, but it’s helpful for debugging or development.Go tohttp://localhost:18000/admin/oauth2_provider/application/and add a new applicationSet “Client id” toblockstore-sso-keySet “Redirect uris” tohttp://localhost:18250/complete/edx-oauth2/Set “Client type” to “Confidential”Set “Authorization grant type” to “Authorization code”Set “Name” toblockstore-ssoCheck “Skip authorization”Press “Save and continue editing”Go tohttp://localhost:18000/admin/oauth_dispatch/applicationaccess/Click “Add Application Access +”, choose Application:blockstore-ssoand set Scopes touser_id, then hit “Save”Copyblockstore/settings/private.py.exampletoblockstore/settings/private.pyInprivate.py, setSOCIAL_AUTH_EDX_OAUTH2_SECRETto the random “Client secret” value.Now you can login athttp://localhost:18250/login/Optional: If running an Open edX devstack under a project name different
than the default (support for which was introduced
[here](https://github.com/openedx/devstack/pull/532)), simply exportOPENEDX_PROJECT_NAMEand substitute the container names in the commands
above accordingly.Optional: to run the unit tests in this mode:Get into the blockstore container:makeblockstore-shellAnd then runmake testOptional: to run the integration tests in this mode:Open edX includes some integration tests for Blockstore. To run them with a separate blockstore instance, first start an isolated test version of blockstore by runningmake testserverfrom theblockstorerepo root directory on your host computer. Then, frommake dev.shell.studio, run these commands:EDXAPP_RUN_BLOCKSTORE_TESTS=1 python-Wd-mpytest--ds=cms.envs.testopenedx/core/lib/blockstore_api/ openedx/core/djangolib/tests/test_blockstore_cache.py openedx/core/djangoapps/content_libraries/tests/EDXAPP_RUN_BLOCKSTORE_TESTS=1 python-Wd-mpytest--ds=lms.envs.testopenedx/core/lib/blockstore_api/ openedx/core/djangolib/tests/test_blockstore_cache.py openedx/core/djangoapps/content_libraries/tests/Getting HelpAsk questions and discuss this project onSlackor theOpen edX Community Discussion Forum.ContributingContributions are welcome. Please readHow To Contributefor details.The Open edX Code of ConductAll community members are expected to follow theOpen edX Code of Conduct.PeopleThe assigned maintainers for this component and other project details may be
found inBackstage. Backstage pulls this data from thecatalog-info.yamlfile in this repo.Reporting Security IssuesPlease do not report security issues in public. Please emailsecurity@edx.org.Change LogUnreleased[1.4.0] - 2023-08-07AddedAdded support for Django 4.2[1.3.1] - 2023-03-06ChangedAdds migration file that was missing from v1.3.0.[1.3.0] - 2023-02-06AddedAdds support for installing this package as a wheel (pip installopenedx-blockstore) rather than having to use editable mode (pip install-e./blockstore).ChangedFixes a bug where a new bundle’s collection could not be set via Django admin.Various configuration and build tooling fixes. See commit log of 1.2.0…1.3.0 for full details.[1.2.0] - 2021-01-25AddedAdds API unit tests to improve test coverage.ChangedUpdates the Python API to use the models directly.[1.1.0] - 2021-10-25AddedMove apps/api to apps/rest_api.Copy edx-platform/openedx/core/lib/blockstore_api to blockstore/apps/api.
This code has been copied over so it is easier to review the Python API
implementation in development.Make code into an installable package.