Skip to main content

A library for easily accessing the Shadertoy API.

Project description

Shadertoy API for Python

Python Versions license

shadertoy-api is a library for easily accessing the Shadertoy API.
For more info about the Shadertoy API, refer to shadertoy.com/howto
Note: 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 API

To start using the Shadertoy API you first need to create an instance of the App class provided by shadertoy-api

>>> import shadertoy
>>> app = shadertoy.App(api_key)

To get an API key for your application you must have an account on shadertoy (go to shadertoy.com/signin).
Once logged in, you can create an API key at shadertoy.com/myapps

The App class provides access to all documented features of the Shadertoy API as of the time this was written.

Search the Shadertoy database

query(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 IDs

get_all_shaders()

Returns a list of the IDs of all available shaders.

Example

>>> all_shaders = app.get_all_shaders()
>>> len(all_shaders)
25859

Non-API features

shadertoy-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 files

download_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 have pillow installed, try this as well:

>>> from PIL import Image
>>> img = Image.open(media)
>>> img.show()

Download shader icons

download_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:

>>> from PIL import Image
>>> img = Image.open(icon)
>>> img.show()

Get embeddable shader URLs

get_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'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

shadertoy-api-1.0.2.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

shadertoy_api-1.0.2-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file shadertoy-api-1.0.2.tar.gz.

File metadata

  • Download URL: shadertoy-api-1.0.2.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.8.2 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.10.1 tqdm/4.64.1 CPython/3.5.3

File hashes

Hashes for shadertoy-api-1.0.2.tar.gz
Algorithm Hash digest
SHA256 97c2f6aa202dfb367a9f2d36d3e1b96b4daae9f7927326e7e1c10395fcd2622a
MD5 5f645d85367801dc34f7c146cd0fb992
BLAKE2b-256 915bb832c687d68ec3acb30b868ca453a7ad9f86b7032d7c00087dddf3080f9a

See more details on using hashes here.

File details

Details for the file shadertoy_api-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: shadertoy_api-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.8.2 requests/2.25.1 setuptools/50.3.2 requests-toolbelt/0.10.1 tqdm/4.64.1 CPython/3.5.3

File hashes

Hashes for shadertoy_api-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 f2323024dff4be394bdc3af39dc6137360e11c17d963c3f2e2851df972b21377
MD5 7f7d485df08f7b1454228c0c0036e8e1
BLAKE2b-256 aa4bb6fcea662bf37f7df7f80b919fdcf3cad8637c63cd7c35821a39e4d55e61

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page