Package: brython-server
Brython-ServerBrython-Serveris a Flask-based web application focused on providing a simple
Python 3 development environment where source files are hosted on Github.You can tryBrython-Serverto get a feel for how it works.Brief InstructionsWhen the page loads, you can begin writing Python 3 code right away. To
execute your code, press therunbutton.Github SupportTo load Python 3 source code hosted on Github, you must should first log in to
Github with theloginbutton. Github will ask you to authorize Brython-Server
in the next page.To load your source, paste the Github URL of your source file or repository
into the text control at the top of the page. Press<Enter>or therefreshbutton to retrieve the source from Github.You may make any changes you want to the source code and re-run it. If you would
like to save your work back to Github, just press thecommitbutton.Google Drive SupportThe Google Driveloadandsavebuttons will activate Google Drive
authentication and authorization dialog where you may confirm your desire to let
Brython-Server access your Google Drive. This confirmation is required periodically.The Google Driveloadbutton directs you to a standard Google Drive file picking
screen. Only compatible text files are available to pick. Once you have selected a file,
the URL for the file will be displayed in the upper left edit window.The Google Drivesavebutton will upload any changes you have made to a file since
you downloaded it, but only if you own or have edit priveleges on the file. If you didn't
download a file first, thesavebutton will prompt you for a new file name.
In this case, Brython-Server will create a new file with your chosen name in the root
of your Google Drive.If you previouslyload-ed or refreshed an existing file from Google Drive then thesavebutton will simply udate your file with any changes you have made since then.Authorizing Google Drive will also add the Brython-Server app to your Google Drive.
This will give you a customnewfile type in Google Drive, and a custom option
under the Google DriveOpen withcontext menu.Note: files that were not created by Brython-Server may not be opened from theloadbutton unless you previously opened them with the Google DriveOpen withcontext
menu.Note: working with any Github repository or Google Drive source files will require you
to have an account with these services. If you use these services to access files
that are not modifiable by you, you will be able to edit them locally in the
Brython-Server page but will not be able to commit or save any changes back to their
original source unless you have the priveleges to do so.TurtleBrython-Server supports the Python turtle to the extent that it is supported by
the underlying Brython interpreter. Its usage is simple, but slightly non-standard.
For example:frombrythonserverimportturtlet=turtle.Turtle()t.forward(100)t.right(90)t.forward(100)turtle.done()GgameBrython-Server includes built-in support for the Ggame graphics engine. For example,
a trivial program from theGgame documentation:fromggameimportApp,ImageAsset,Sprite# Create a displayed object at 100,100 using an image assetSprite(ImageAsset("bunny.png"),(100,100))# Create the app, with a default stageAPP=App()# Run the appAPP.run()DeploymentThe best way to install Brython-Server is with pip and virtualenv, using Python 3.11+.
Create and activate your virtual environment then install Brython-Server with:python3.11-mpipinstallbrython-serverRequirementsThe essential requirements for Brython-Server are met when you install with pip.
In addition, for a production install you will needgunicorn.Brython-Server will useBrythonas
its Python interpreter and andGgameas its graphics engine. The correct versions of each will automatically be used
when you install Brython-Server using pip.Environment VariablesA full Brython-Server installation that is capable of interacting with Github
should have several environment variables set for production use:Required for Github functionality:githubtoken  (an optional Github personal access token)githubsecret (Github oauth secret)githubclientid (Github oauth client id)Required for Google Drive functionality:googleclientid (Google Client ID)googleapikey (Google API Key. Brython Server requires the drive/files
and filePicker APIs)googleappid (Google Application ID)Required for creating a "personalized" Brython-Server instance:sitetitle (A string that will be displayed as the "name of the site")sitecontact (An e-mail address to use for contact)siteurl (A full URL to the website)flasksecret (A Flask application secret key)Note: to generate a unique, random Flask secret key, enter the following in
a Python console:>>>importos>>>os.urandom(24)Use the string that results as the value of the flasksecret environment
variable.ExecutionTo run the server in stand-alone development mode (never in production!)
execute (for example) from the Python 3 shell:Python3.11.7(main,Dec82023,18:56:58)[GCC11.4.0]onlinuxType"help","copyright","credits"or"license"formoreinformation.>>>frombrythonserver.mainimportAPP>>>APP.run(host="0.0.0.0",port=8080)*ServingFlaskapp'brythonserver.main'(lazyloading)*Environment:productionWARNING:Thisisadevelopmentserver.Donotuseitinaproductiondeployment.UseaproductionWSGIserverinstead.*Debugmode:off*Runningonalladdresses(0.0.0.0)WARNING:Thisisadevelopmentserver.Donotuseitinaproductiondeployment.*Runningonhttp://127.0.0.1:8080*Runningonhttp://192.168.111.50:8080(PressCTRL+Ctoquit)To run the server in a production environment, use gunicorn:$gunicorn-b0.0.0.0:3000-w4brythonserver.main:APPDevelopment EnvironmentTo begin working with Brython Server in development environment:Clone this repository and cd into it.Create a virtual environment:python3.11 -m venv envActivate the virtual environment:source env/bin/activateInstall the dependencies:python3.11 -m pip install -r requirements.txtOther DependenciesYour development environment will need black and standardjs to
execute therun_testsandrun_js_testsscripts (in the scripts folder).ExecutionPrior to executing the server in your development environment you will have to
perform the following manual steps to populate the Brython distribution files
where Brython Server can access them:cd~/workspace/brython-server
mkdir-pbrythonserver/static/brythoncdbrythonserver/static/brython
python3.11-mbrython--updateNow you should be able to run Brython Server in your development environment
using a script similar to this:exportgithubclientid=<insertyourgithubclientidhere>exportgithubsecret=<insertyourgithubsecrethere>exportgithubtoken=<insertyourpersonalgithubtokenhere>exportgoogleclientid='<insert your google client id here>.apps.googleusercontent.com'exportgoogleapikey='<insert your google api key here>'exportgoogleappid='<insert your google app id here>'exportsitetitle="<insert the name of your development site here>"exportsitecontact=<insertane-mailaddresshere>exportsiteurl=<inserttheurlforyourdevelopmentpagehere>exportPORT=<useyourportnumberhere>sourcebrython-server/env/bin/activatecdbrython-server
python3.11-mpipinstall-rrequirements.txtpushdbrythonserver/static/brython
brython-cliinstallpopdpython3.11wsgi.py