Getting started with numerous.sdk#
Installing numerous.sdk#
We recommend that you work inside a virtual environment. You can create one manually, if your code editor or IDE does not do it automatically.
# Create the virtual environment
python -m venv venv
# And activate it in the relevant way:
./venv/bin/activate # on unix based systems
.\venv\Scripts\activate # on Windows based systems
Installing numerous.sdk is simple.
pip.#pip install numerous.sdk
Initializing the JobClient#
The basis of using the SDK is to create a JobClient, and
use that to communicate with the platform to set
JobStatus, reading and writing data, and more.
Below is a simple example of how to initialize the
JobClient with the
connect() static method.
This is the usual way the client is initialized when running inside a job on the numerous platform.
from datetime import timedelta
from math import pi, sin
from numerous.sdk import JobClient, JobStatus
with JobClient.connect() as job:
job.status = JobStatus.RUNNING
job.message = "Sine waving"
for t in job.job_time.range(step=timedelta(minutes=1)):
elapsed = job.job_time.start_to_time(t).total_seconds()
if job.job_time.duration: # updates progress if the job has an end time
job.progress = elapsed / job.job_time.duration.total_seconds()
oscillations_per_second = 1 / (60 * 60)
one_sine_wave_every_hour = sin(2 * pi * oscillations_per_second * elapsed)
job.writer.row(t, {"sine": one_sine_wave_every_hour})
job.status = JobStatus.FINISHED
job.message = "Done waving"
Running your code locally, against a scenario on the platform#
Go to your scenario on the numerous platform and click the Run Job button. Then, click the Edit job code button, and copy the commands from the section named Initialising a new repository.
Run the commands in your command line terminal, making sure my-first-repo is replaced with the folder containing the file with the Python code from the example above.
cd my_project_folder
numerous init
numerous config --remote REMOTE URL
# The CLI will prompt you to accept the value
numerous checkout --scenario PROJECT_ID:SCENARIO_ID
# You will be prompted to login with the credentials you use on the platform.
Now you are ready to run the example. If you save the example in
my_project_folder/example.py (and you are inside my_project_folder), you can
just run python example.py, and it should run, and you can see the results on the
scenario page on the platform!