EngineClient#
- class gamspy.EngineClient(host: str, username: str = '', password: str = '', jwt: str = '', namespace: str = 'global', extra_model_files: list[str] = [], engine_options: dict | None = None, remove_results: bool = False, is_blocking: bool = True)[source]#
Bases:
object
GAMS Engine Client.
- Parameters:
- hoststr
Host address.
- usernamestr, optional
Username
- passwordstr, optional
Password
- jwtstr, optional
JWT Token
- namespacestr, optional
Namespace, by default “global”
- extra_model_fileslist[str], optional
extra_model_files, by default []
- engine_optionsdict | None, optional
GAMS Engine options, by default None
- remove_resultsbool, optional
Whether to remove the results from GAMS Engine Server, by default False
- is_blockingbool, optional
Synchronous (blocking) or asynchronous, by default True
Methods
get_request_headers
Examples
>>> import gamspy as gp >>> client = gp.EngineClient(host="https://engine.gams.com/api/", username="<username>", password="<password>")
- class gamspy._backend.engine.Job(client: EngineClient)[source]#
Bases:
Endpoint
Methods
delete_results
(token)Delete request to /jobs/{token} which deletes the job results.
get
(token)Get request to /jobs/{token} which returns the details of a job.
get_logs
(token)Get request to /jobs/{token}/unread-logs which returns stdout of a job.
get_results
(token, working_directory)Get request to /jobs/{token}/result which downloads the job results.
post
(working_directory, gms_file[, pf_file])Post request to /jobs which submits a new job to be solved.
- delete_results(token: str)[source]#
Delete request to /jobs/{token} which deletes the job results. Refer to https://engine.gams.com/api/ for more details.
- Parameters:
- tokenstr
Job token
- Raises:
- EngineClientException
If job data does not exist in GAMS Engine.
- EngineClientException
If delete request has failed.
- get(token: str) tuple[int, str, int | None] [source]#
Get request to /jobs/{token} which returns the details of a job. Refer to https://engine.gams.com/api/ for more details.
- Parameters:
- tokenstr
Job token
- Returns:
- tuple[int, str, int]
Job status, job status message, and gams exit code
- Raises:
- EngineClientException
If get request has failed.
- get_logs(token: str) tuple[str, bool] [source]#
Get request to /jobs/{token}/unread-logs which returns stdout of a job. Refer to https://engine.gams.com/api/ for more details.
- Parameters:
- tokenstr
Job token
- Returns:
- tuple[str, bool]
Current output buffer and queue finished status
- Raises:
- EngineClientException
If get request has failed.
- get_results(token: str, working_directory: str)[source]#
Get request to /jobs/{token}/result which downloads the job results. Downloaded results are unpacked to working directory. Refer to https://engine.gams.com/api/ for more details.
- Parameters:
- tokenstr
Job token
- working_directorystr
Working directory
- Raises:
- EngineClientException
If get request has failed.
- post(working_directory: str, gms_file: str, pf_file: str | None = None) str [source]#
Post request to /jobs which submits a new job to be solved. Refer to https://engine.gams.com/api/ for more details.
- Parameters:
- working_directorystr
Working directory
- gms_filestr
Name of the gms file
- pf_file: str | None
Name of the pf file
- Returns:
- str
Token
- Raises:
- EngineClientException
If post request has failed.
- class gamspy._backend.engine.Auth(client: EngineClient)[source]#
Bases:
Endpoint
Methods
login
([expires_in, scope])Creates a JSON Web Token(JWT) for authentication (username and password in request body)
logout
()Invalidates all of your JSON Web Tokens(JWTs)
post
([expires_in, scope])Creates a JSON Web Token(JWT) for authentication
- login(expires_in: int = 14400, scope: list[str] | None = None) str [source]#
Creates a JSON Web Token(JWT) for authentication (username and password in request body)
- Parameters:
- expires_inint, optional
Expiration time for the token, by default 14400
- scope: list[str], optional
Scope of the token, by default None
- Returns:
- str
- post(expires_in: int = 14400, scope: list[str] | None = None) str [source]#
Creates a JSON Web Token(JWT) for authentication
- Parameters:
- expires_inint, optional
Expiration time, by default 14400
- scopelist[str] | None, optional
Scope of the token, by default None
- Returns:
- str
token
- Raises:
- EngineClientException
In case bad request
- EngineClientException
In case unauthorized request
- EngineClientException
In case there is an internal error
- GamspyException
In case the status code is unrecognized