Usage

Interested in interacting with the Sample Programs library in Python? Then subete is the official way to do it!

Installation

To get started, download and install subete using pip:

pip install subete

Basic Usage

From there, you can import the subete library as follows:

import subete

Then, all that’s left to do is to load the Sample Programs repo:

repo = subete.load()

Keep in mind that the load() function relies on Git being available on the system to be able to clone the Sample Programs repo. Alternatively, you can download the Sample Programs repo yourself and supply the path as an argument:

repo = subete.load(source_dir="path/to/sample-programs/archive")

With that out of the way, the rest is up to you! Feel free to explore the repo as needed. For example, you can access the list of languages as follows:

languages = list(repo)

From there, you can browse the individual sample programs available for each language:

programs = list(languages)

Finally, you can access information about each individual program. For example, you can retrieve the raw code as follows:

code = programs[0].code()

There are many ways to interact with the repo. Feel free to use this Python API as needed.

Advanced Usage

Depending on your needs, Subete can be used to access information in more direct ways. For example, both the Repo and LanguageCollection objects are dictionaries under the hood. Rather than exposing that data, we made the objects directly subscriptable. For example, if you want to check out the Python collection, the following will get you there:

python_code = repo["Python"]

And to access an explicit program, you can use the any of the existing project names:

python_hello_world = repo["Python"]["Hello World"]

In addition to being subscriptable, both objects are also iterable. For example, to iterate over all of the languages in the repo, you can use the following:

for language in repo:
    print(language)

Unsurprisingly, the same can be done for each language:

for program in repo["Python"]:
    print(program)

Beyond that, the API is available for looking up any additional information you made need for each program or language.