Package: shadertoy-api
Shadertoy API for Pythonshadertoy-api is a library for easily accessing the Shadertoy API.For more info about the Shadertoy API, refer toshadertoy.com/howtoNote: only shaders listed as Public+API are available through the Shadertoy API.Also, I (the author of this library) don't have any connections with the shadertoy
development team, in case you are wondering.Using the Shadertoy APITo start using the Shadertoy API you first need to create an instance of the App class provided by shadertoy-api>>>importshadertoy>>>app=shadertoy.App(api_key)To get an API key for your application you must have an account onshadertoy(go toshadertoy.com/signin).Once logged in, you can create an API key atshadertoy.com/myappsThe App class provides access to all documented features of the Shadertoy API as of the time this was written.Search the Shadertoy databasequery(keywords=[],sort_by=None,filter=None,start_index=0,num_shaders="all")Queries the shadertoy database for shaders matching the given filter
and returns a list with the given number of their IDs, starting at the
given index and sorted by the given classifier.Classifiers: "name", "love", "popular", "newest", "hot"Filters: "vr", "soundoutput", "soundinput", "webcam", "multipass", "musicstream"A list of all classifiers and filters is provided by shadertoy-api>>>shadertoy.classifiers('name','love','popular','newest','hot')>>>shadertoy.filters('vr','soundoutput','soundinput','webcam','multipass','musicstream')Example>>>app.query(keywords=["fluid","simulation"],sort_by="newest",num_shaders=10)['DsSSzm','fdcyzr','NldXWf','ftySzR','NtKGRc','7tKGzK','7tyGW1','slKGRw','7ttGR4','sdd3zj']Get shader data (name, creator, description, likes, views, code, input media...)get_shader(shader_id)Returns a dictionary containing data about the shader with the given ID.Example>>>shader=app.get_shader("WdVXWy")>>>shader["info"]["name"]'molten bismuth'Get all available shader IDsget_all_shaders()Returns a list of the IDs of all available shaders.Example>>>all_shaders=app.get_all_shaders()>>>len(all_shaders)25859Non-API featuresshadertoy-api also provides some non-API utilities through the App class including
downloading shadertoy media files and shader icons, getting URLs for embedding
shaders in webapps, and possibly more in the future!Download Shadertoy media filesdownload_media_file(path)Downloads a shadertoy media file from the given path (relative to shadertoy.com)
and returns it as a file-like io.BytesIO object.Example>>>Image_input0=shader["renderpass"][0]["inputs"][0]>>>media=app.download_media_file(Image_input0["src"])>>>type(media)<class'_io.BytesIO'>If you havepillowinstalled, try this as well:>>>fromPILimportImage>>>img=Image.open(media)>>>img.show()Download shader iconsdownload_shader_icon(shader_id)Downloads the icon for the shader with the given id and returns it as a
file-like io.BytesIO object (note that shader icons are in JPEG format).Example>>>icon=app.download_shader_icon("WdVXWy")>>>type(icon)<class'_io.BytesIO'>With pillow installed, try this:>>>fromPILimportImage>>>img=Image.open(icon)>>>img.show()Get embeddable shader URLsget_embeddable_url(shader_id,enable_gui=True,start_time=10,paused=True,muted=False)Returns an embeddable URL for the shader with the given id, and configures
it with the given initial settings.Example>>>embeddable_url=app.get_embeddable_url("WdVXWy")>>>embeddable_url'https://www.shadertoy.com/embed/WdVXWy?gui=true&t=10&paused=true&muted=false'