Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
188 commits
Select commit Hold shift + click to select a range
4b16efe
Started object-orientation based RestAPI querying
kzscisoft Nov 11, 2024
da886d9
Fix generic alert class
kzscisoft Nov 11, 2024
3c06c0c
Add staging to RestAPI calls
kzscisoft Nov 12, 2024
3b0b00c
Added Run object and simplified decorator
kzscisoft Nov 12, 2024
9cd7f90
Added artifact object and committing to creation
kzscisoft Nov 13, 2024
52ca992
Improved alert tests and added user alert
kzscisoft Nov 13, 2024
2daa8b4
Added stats and sorted tests
kzscisoft Nov 13, 2024
f56e32f
Add storage objects
kzscisoft Nov 14, 2024
f40b7f1
Added read-only mode for multi object retrieval
kzscisoft Nov 15, 2024
00d86a9
Start modification of upper run class
kzscisoft Nov 18, 2024
d2b23ff
Fixed recursive delete
kzscisoft Nov 20, 2024
4414315
Added custom URL class for mutable path
kzscisoft Nov 22, 2024
612b95a
Use custom URL class, fix URLs for artifacts and make read-only default
kzscisoft Nov 22, 2024
5d86ea6
Continue swapping out old API
kzscisoft Dec 2, 2024
90f121e
Merge branch 'dev' into feature/api-repro
kzscisoft Dec 2, 2024
409b30a
Fix read only mode for server object retrieval
kzscisoft Dec 2, 2024
b42488a
Further test fixes and added julia and js metadata
kzscisoft Dec 5, 2024
a6f6d8f
Merge branch 'dev' into feature/api-repro
kzscisoft Dec 9, 2024
a0c43fa
Merge branch 'dev' into feature/api-repro
kzscisoft Dec 9, 2024
1bf7205
Further fixes towards working tests for v2
kzscisoft Dec 10, 2024
1173cb8
Fix wrong headers during run update for artifact
kzscisoft Dec 16, 2024
36bbd5a
Use lock files for python environment, support Poetry and UV
kzscisoft Dec 16, 2024
c36e396
Fix more tests
kzscisoft Dec 17, 2024
57db61d
Modified alert status setting
kzscisoft Dec 18, 2024
e96c69e
Continue trying to address artifact object
kzscisoft Dec 18, 2024
a7f5b5f
Refactor the object upload
kzscisoft Dec 19, 2024
ef0547c
Fix validation issue
kzscisoft Dec 19, 2024
a3dc10e
Fixed artifact unit test
kzscisoft Dec 19, 2024
93cefaa
Fix artifact retrieval
kzscisoft Jan 2, 2025
7197a52
Fixed typing.Self so that it also works for 3.10
wk9874 Jan 6, 2025
66beb76
Added online, offline and local tags to unit tests
wk9874 Jan 6, 2025
954d787
Changed _tag to _tenant
wk9874 Jan 6, 2025
75b50e3
Added write_only decorator to alert classes and fixed test
wk9874 Jan 6, 2025
4297b5e
Reset changes to add cached instead of staged
wk9874 Jan 7, 2025
a35ce36
Fix folder modification test
wk9874 Jan 7, 2025
10da623
Fix dataframe conversion
kzscisoft Jan 7, 2025
a5432de
Removed erronous get_status for alerts
wk9874 Jan 7, 2025
17fa181
Updated validation error formatter
wk9874 Jan 7, 2025
af9226e
Remove deprecated visibility for folders, and updated storage class
kzscisoft Jan 8, 2025
158a536
Fix online folder test
kzscisoft Jan 8, 2025
1d73937
Merge branch 'feature/api-repro' into wk9874/api_refactor_fixes
wk9874 Jan 8, 2025
f852b4a
Added new arguments for tenant
wk9874 Jan 8, 2025
b361038
Fixed typing
wk9874 Jan 8, 2025
d81dff8
Addressed MR comments
wk9874 Jan 8, 2025
d99e840
Changed is_enabled to enabled
wk9874 Jan 8, 2025
e82d0a0
Fix use of Folder.delete in tests and ensure | used for typing
kzscisoft Jan 8, 2025
3ca0f14
Changed is_enabled to enabled
wk9874 Jan 8, 2025
8fdc571
Changed enabled to is_enabled in init
wk9874 Jan 8, 2025
b83a4a6
Fix S3 storage test
kzscisoft Jan 8, 2025
44611a0
Merge pull request #648 from simvue-io/wk9874/tenant_refactor
kzscisoft Jan 8, 2025
4bf345a
Merge branch 'feature/api-repro' into wk9874/api_refactor_fixes
kzscisoft Jan 8, 2025
0e0b911
Merge pull request #646 from simvue-io/wk9874/api_refactor_fixes
kzscisoft Jan 8, 2025
a46ed6a
Fix Stats
kzscisoft Jan 8, 2025
aac65f6
Set read only to false in alert modification test
wk9874 Jan 8, 2025
e52f96a
Updated user object
kzscisoft Jan 8, 2025
f9f3a26
Merge branch 'feature/api-repro' of github.com:simvue-io/python-api i…
kzscisoft Jan 8, 2025
4e08934
Set read-only to false in tag modification test
wk9874 Jan 8, 2025
0ee6075
Made created immutable
wk9874 Jan 8, 2025
4c6238c
Fix datetime format when retrieving times for run
kzscisoft Jan 8, 2025
205f5dd
Merge branch 'feature/api-repro' of github.com:simvue-io/python-api i…
kzscisoft Jan 8, 2025
c644b23
Changed datetime format of S3 storage and updated test
wk9874 Jan 8, 2025
55a79c1
Merge branch 'feature/api-repro' of github.com:simvue-io/python-api i…
wk9874 Jan 8, 2025
bfa85ea
Remove Ts from date formats
wk9874 Jan 9, 2025
09b7492
Remove url slash at end if identifier is blank
wk9874 Jan 9, 2025
97ced62
Started update of artifact class
kzscisoft Jan 10, 2025
00afcc0
Fixed wrong fake URL for storage test
kzscisoft Jan 10, 2025
bcc81ed
Merge branch 'feature/api-repro' of github.com:simvue-io/python-api i…
kzscisoft Jan 10, 2025
d776268
Modify Artifact to new specification
kzscisoft Jan 10, 2025
efce7de
Continue test fixes
kzscisoft Jan 10, 2025
24cbbe8
Fixed bug where GET is called even if instance constructed from argum…
kzscisoft Jan 10, 2025
50d5dc1
Fix data streaming to download
kzscisoft Jan 13, 2025
c12358b
Fix artifact file test
kzscisoft Jan 13, 2025
50d1187
Try using 'url' for download
kzscisoft Jan 14, 2025
2a3a155
Break down alert creation function
kzscisoft Jan 14, 2025
cdfc572
Few more test fixes and using correct query for retrieving an artifact
kzscisoft Jan 14, 2025
e48d6ef
Further client class and test fixes
kzscisoft Jan 15, 2025
699771f
Fix generator typing
kzscisoft Jan 15, 2025
5139f18
Added created member to Folder and Tag classes
kzscisoft Jan 16, 2025
156e4bb
Fix datetime format and a few more bugs
kzscisoft Jan 17, 2025
3cd12c5
Add to_dict member to SimvueObject
kzscisoft Jan 17, 2025
2f32a78
Allow None as description
kzscisoft Jan 17, 2025
a934ee8
Added Metrics and Events classes
kzscisoft Jan 17, 2025
5efb5b8
More test fixes
kzscisoft Jan 20, 2025
a245815
Added User test
kzscisoft Jan 20, 2025
6061607
Started updating typing and fixed dependency for typing
kzscisoft Jan 20, 2025
e515fb4
Remove constraints on tenacity and psutil
kzscisoft Jan 20, 2025
4ef1a19
More typing adjustments
kzscisoft Jan 20, 2025
6c73d70
More typing adjustments
kzscisoft Jan 20, 2025
bdc55e5
Added descriptions to range alert tests to pass validation
wk9874 Jan 20, 2025
ec5068e
Added description to threshold alert tests
wk9874 Jan 20, 2025
2d32b1d
Added metric names endpoint
kzscisoft Jan 20, 2025
defedd3
Merge branch 'feature/api-repro' of github.com:simvue-io/python-api i…
kzscisoft Jan 20, 2025
9f923e4
Fix wrong parameter for metrics object functions
kzscisoft Jan 20, 2025
219d277
Added stat file header
kzscisoft Jan 20, 2025
58fc721
Fix CI using env key
kzscisoft Jan 20, 2025
aa95829
Fix bad filter string when updating folder details
kzscisoft Jan 21, 2025
ec1c8c5
Merge branch 'dev' into feature/api-repro
kzscisoft Jan 21, 2025
e5fe6c2
Fix user test
kzscisoft Jan 21, 2025
b014219
Fixed UTC time
wk9874 Jan 21, 2025
6e92dd1
Merge branch 'feature/api-repro' of github.com:simvue-io/python-api i…
wk9874 Jan 21, 2025
d5a9843
Changed caching to different files and folders for types and runs
wk9874 Jan 21, 2025
3cdbb5d
Fixed test_log_metrics
wk9874 Jan 21, 2025
1c63863
Add to_dict checks
kzscisoft Jan 21, 2025
4247772
Add to_dict checks and added correct expect type for metrics names
kzscisoft Jan 21, 2025
3ddfe79
Undo commenting
wk9874 Jan 22, 2025
e4ea857
Merge branch 'wk9874/caching' into feature/api-repro
wk9874 Jan 22, 2025
c1aca1a
Started new sender
kzscisoft Jan 22, 2025
126d409
Add obj_type to cached info
kzscisoft Jan 22, 2025
cb6a1c7
Created offline object initialiser function
kzscisoft Jan 22, 2025
b0e6e8c
Allow arbitary number of args for each low level class new method
kzscisoft Jan 22, 2025
0a6045f
Add cache file removal to uploading
kzscisoft Jan 22, 2025
650b282
Add further tweaks for server changes and test fixes
kzscisoft Jan 24, 2025
2a5e532
Merge branch 'feature/api-repro' of github.com:simvue-io/python-api i…
kzscisoft Jan 24, 2025
f190dda
Run sourcery linting/fixing
kzscisoft Jan 24, 2025
588d063
Modernise typing
kzscisoft Jan 24, 2025
5349e2f
Changed back to typing.Optional where string type
wk9874 Jan 24, 2025
7128f77
Stop abort test crashing pytest
wk9874 Jan 24, 2025
49f9ff1
Added upload submodule and started tests for offline
kzscisoft Jan 24, 2025
1f6237e
Merge branch 'feature/api-repro' of github.com:simvue-io/python-api i…
kzscisoft Jan 24, 2025
21983cb
Updated monitor processes test with mark
wk9874 Jan 24, 2025
1881fe1
Merge branch 'feature/api-repro' of github.com:simvue-io/python-api i…
wk9874 Jan 24, 2025
80e0c63
Added uploader to offline test
kzscisoft Jan 24, 2025
d92da37
Merge branch 'feature/api-repro' of github.com:simvue-io/python-api i…
kzscisoft Jan 24, 2025
17d294c
Fix selective uploading
kzscisoft Jan 24, 2025
2e9436a
Fix and simplify to_dict method
kzscisoft Jan 24, 2025
b2862f3
Added loads of stuff for uploader
wk9874 Jan 24, 2025
6db3468
Fix alert raise test
kzscisoft Jan 27, 2025
65d4b63
Adding fixes to upload
wk9874 Jan 27, 2025
4a2c26b
Added parallel thread processing
wk9874 Jan 27, 2025
a81472f
Getting uploader to work with artifacts
wk9874 Jan 27, 2025
e55b4c8
Getting uploader to work with artifacts
wk9874 Jan 27, 2025
360afc6
Merge branch 'feature/api-repro' into wk9874/uploader
wk9874 Jan 27, 2025
afa63dc
Fix and shorten file save test
kzscisoft Jan 28, 2025
3bef0f6
Fix two tests
kzscisoft Jan 28, 2025
3db61b7
Updates to sender and getting tests passing
wk9874 Jan 28, 2025
c9d7615
Merge branch 'feature/api-repro' into wk9874/uploader
wk9874 Jan 28, 2025
6b90106
Fix naming of runs in metrics return
kzscisoft Jan 28, 2025
3840f45
Got alerts working with offline mode
wk9874 Jan 28, 2025
630eddc
Stopped duplicate alert upload
wk9874 Jan 28, 2025
9c1d8e1
Added threading lock
wk9874 Jan 29, 2025
045fc23
Renamed id mapping
wk9874 Jan 29, 2025
3756314
Added docstrings
wk9874 Jan 29, 2025
f244b92
Tighter constraint on abort and allow alternative user agent spec
kzscisoft Jan 29, 2025
2ad3c90
Fixing offline artifact test
wk9874 Jan 29, 2025
011fe1e
Merge branch 'feature/api-repro' into wk9874/uploader
wk9874 Jan 29, 2025
9fdaff1
Improving and fixing offline folder tests
wk9874 Jan 29, 2025
20e8615
Add missing properties to User
kzscisoft Jan 29, 2025
4c987a4
Added whoami to stats
kzscisoft Jan 29, 2025
1178379
Changes to get offline range alert tests passing
wk9874 Jan 29, 2025
59b049a
Fixing threshold alert offline tests
wk9874 Jan 30, 2025
77ecbf0
Migrated pyproject.toml file
kzscisoft Jan 30, 2025
2f2f800
Fixed abort test
kzscisoft Jan 30, 2025
2959efb
Fix metadata for Poetry/PyPA hybrids
kzscisoft Jan 30, 2025
aecb71e
Fixed offline run tests
wk9874 Jan 30, 2025
9f7f734
Move offline mode statement to init
kzscisoft Jan 30, 2025
ba66777
Added refresh method
wk9874 Jan 30, 2025
67bd63c
Tons of test fixes
wk9874 Jan 30, 2025
9758009
Fix S3 test
wk9874 Jan 31, 2025
3579395
Fix missing return statement for folder
kzscisoft Jan 31, 2025
a088f60
Merge branch 'feature/api-repro' into wk9874/uploader
wk9874 Jan 31, 2025
f569ddb
Deleted stuff from bin sender and set defaults
wk9874 Jan 31, 2025
ec78959
Lots of renaming to allow offline to work
wk9874 Jan 31, 2025
e93b373
Changing enabled to is_enabled and similar
wk9874 Jan 31, 2025
f683134
Merge branch 'dev' into feature/api-repro
kzscisoft Feb 3, 2025
f46ae33
Review changes
wk9874 Feb 4, 2025
780305f
Added sender bin script
wk9874 Feb 4, 2025
1690279
Added more docstrings
kzscisoft Feb 4, 2025
0b706a5
Bug fixes and add missing uploaded=True to artifact upload
kzscisoft Feb 5, 2025
de362b4
Merge branch 'feature/api-repro' into wk9874/uploader
kzscisoft Feb 5, 2025
3fb25f6
Further fixes towards offline mode
kzscisoft Feb 5, 2025
f0f18b0
Added missing events unit test
kzscisoft Feb 5, 2025
eac2d2d
Separate artifacts into subobjects
kzscisoft Feb 6, 2025
5edecd5
Fix online artifact refactor
kzscisoft Feb 7, 2025
f231040
Fix method ordering in new artifact
kzscisoft Feb 7, 2025
f7dbad9
More fixes
kzscisoft Feb 7, 2025
120087f
Fix online mode file upload
kzscisoft Feb 7, 2025
88eb40d
Fixing offline and read only propogatin
wk9874 Feb 7, 2025
dc3e273
Fixes
wk9874 Feb 7, 2025
257b57e
Lots of fixes fdor aertifact offline
wk9874 Feb 7, 2025
b43897a
Started fixing object upload tests
wk9874 Feb 7, 2025
6bbc2f7
Changes to make object offline mode work
wk9874 Feb 7, 2025
e2ba66b
delete object file once sent
wk9874 Feb 7, 2025
d37274a
Improved events alert tests
wk9874 Feb 7, 2025
5a8d3a5
Further offline fixes
kzscisoft Feb 10, 2025
e7a71fb
Fixed execute process test
wk9874 Feb 10, 2025
9bf09ba
UserAlert wip
wk9874 Feb 10, 2025
60961d2
Removed debug
kzscisoft Feb 10, 2025
1a604e1
Bump version to alpha for v2
kzscisoft Feb 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,5 @@ offline/

# Vagrant
Vagrantfile

.sourcery*
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
* Add support for defining Simvue run defaults using `tool.simvue` in a project `pyproject.toml` file.
* Drop support for INI based configuration files.
* Retrieve all metric values if `max_points` is unspecified or set to `None`.
* Add support for PyTorch in Python 3.13
* Create lower level API for directly interacting with the Simvue RestAPI endpoints.
* **Removes support for Python <3.10 due to dependency constraints.**
* Separates `create_alert` into specific methods `create_event_alert` etc.
## [v1.1.4](https://github.com/simvue-io/client/releases/tag/v1.1.4) - 2024-12-11

* Remove incorrect identifier reference for latest Simvue servers during reconnection.
Expand Down
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ if __name__ == "__main__":
run.save_file('params.in', 'input')

# Add an alert (the alert definition will be created if necessary)
run.create_alert(name='loss-too-high', # Name
source='metrics', # Source
rule='is above', # Rule
metric='loss', # Metric
frequency=1, # Frequency
window=1, # Window
threshold=10, # Threshold
notification='email') # Notification type
run.create_metric_threshold_alert(
name='loss-too-high', # Name
rule='is above', # Rule
metric='loss', # Metric
frequency=1, # Frequency
window=1, # Window
threshold=10, # Threshold
notification='email' # Notification type
)

...

Expand Down
2 changes: 1 addition & 1 deletion examples/Geant4/geant4_simvue.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
@click.option("--momentum", type=float, default=10)
@click.option("--events", type=int, default=100)
def geant4_simvue_example(
g4_binary: str, config: typing.Optional[str], ci: bool, momentum: float, events: int
g4_binary: str, config: str | None, ci: bool, momentum: float, events: int
) -> None:
@mp_file_parse.file_parser
def root_file_parser(
Expand Down
625 changes: 456 additions & 169 deletions poetry.lock

Large diffs are not rendered by default.

81 changes: 44 additions & 37 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[tool.poetry]
[project]
name = "simvue"
version = "1.1.4"
version = "2.0.0a0"
description = "Simulation tracking and monitoring"
authors = ["Simvue Development Team <info@simvue.io>"]
authors = [
{name = "Simvue Development Team", email = "info@simvue.io"}
]
license = "Apache v2"
requires-python = ">=3.10,<3.14"
readme = "README.md"
homepage = "https://simvue.io"
repository = "https://github.com/simvue-io/python-api"
documentation = "https://docs.simvue.io"
classifiers = [
"Development Status :: 5 - Production/Stable",
"Intended Audience :: Science/Research",
Expand All @@ -33,34 +33,37 @@ keywords = [
"alerting",
"metrics-gathering"
]
dependencies = [
"requests (>=2.32.3,<3.0.0)",
"pydantic (>=2.10.6,<3.0.0)",
"tabulate (>=0.9.0,<0.10.0)",
"msgpack (>=1.1.0,<2.0.0)",
"pyjwt (>=2.10.1,<3.0.0)",
"pandas (>=2.2.3,<3.0.0)",
"toml (>=0.10.2,<0.11.0)",
"click (>=8.1.8,<9.0.0)",
"gitpython (>=3.1.44,<4.0.0)",
"humanfriendly (>=10.0,<11.0)",
"randomname (>=0.2.1,<0.3.0)",
"codecarbon (>=2.8.3,<3.0.0)",
"numpy (>=2.2.2,<3.0.0)",
"flatdict (>=4.0.1,<5.0.0)",
"semver (>=3.0.4,<4.0.0)",
"email-validator (>=2.2.0,<3.0.0)",
"psutil (>=6.1.1,<7.0.0)",
"tenacity (>=9.0.0,<10.0.0)",
"typing-extensions (>=4.12.2,<5.0.0) ; python_version < \"3.11\"",
]

[tool.poetry.dependencies]
python = "^3.10,<3.14"
dill = "^0.3.7"
requests = "^2.31.0"
msgpack = "^1.0.7"
tenacity = ">=8.2.3,<10.0.0"
PyJWT = "^2.8.0"
psutil = ">=5.9.8,<7.0.0"
pydantic = "^2.5.3"
pandas = "^2.2.0"
plotly = {version = ">=5.18,<7.0", optional = true}
matplotlib = {version = "^3.8.2", optional = true}
typing_extensions = { version = "^4.11.0", python = "<3.10" }
toml = "^0.10.2"
click = "^8.1.7"
gitpython = "^3.1.43"
humanfriendly = "^10.0"
tabulate = "^0.9.0"
randomname = "^0.2.1"
codecarbon = "^2.7.1"
numpy = "^2.1.2"
semver = "^3.0.2"
[project.urls]
homepage = "https://simvue.io"
repository = "https://github.com/simvue-io/python-api"
documentation = "https://docs.simvue.io"

[tool.poetry.extras]
plot = ["matplotlib", "plotly"]
[project.optional-dependencies]
plot = ["plotly (>=6.0.0,<7.0.0)", "matplotlib (>=3.10.0,<4.0.0)"]

[tool.poetry.scripts]
[project.scripts]
simvue_sender = "simvue.bin.sender:run"

[tool.poetry.group.dev.dependencies]
Expand All @@ -72,16 +75,13 @@ pytest-mock = "^3.14.0"
pytest-sugar = "^1.0.0"
pytest-xdist = "^3.6.1"
jinja2 = "^3.1.4"
types-requests = "^2.32.0.20241016"
interrogate = "^1.7.0"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[[tool.poetry.source]]
name = "PyPI"
priority = "primary"


[tool.ruff]
lint.extend-select = ["C901", "T201"]
lint.mccabe.max-complexity = 11
Expand All @@ -93,6 +93,7 @@ testpaths = [
"tests"
]
markers = [
"codecarbon: tests for emission metrics",
"client: tests of Simvue client",
"converters: tests for Simvue object converters",
"dispatch: test data dispatcher",
Expand All @@ -104,11 +105,17 @@ markers = [
"api: tests of RestAPI functionality",
"unix: tests for UNIX systems only",
"metadata: tests of metadata gathering functions",
"proxies: tests for remote/offline Simvue proxies"
"proxies: tests for remote/offline Simvue proxies",
"online: tests for online functionality",
"offline: tests for offline functionality",
"local: tests of functionality which do not involve a server or writing to an offline cache file"
]

[tool.interrogate]
ignore-init-method = true
fail-under = 95
verbose = 1
exclude = ["docs", "tests"]

[tool.mypy]
ignore_missing_imports = true
8 changes: 8 additions & 0 deletions simvue/api/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""
Simvue API
==========

Module contains methods for interacting with a Simvue server
including accessing/updating objects.

"""
35 changes: 35 additions & 0 deletions simvue/api/objects/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""
Simvue API Objects
==================

The following module defines objects which provide exact representations
of information accessible via the Simvue RestAPI, this provides a lower
level interface towards the development of additional tools/frameworks.

"""

from .administrator import Tenant as Tenant, User as User
from .alert import (
Alert as Alert,
EventsAlert as EventsAlert,
MetricsThresholdAlert as MetricsThresholdAlert,
MetricsRangeAlert as MetricsRangeAlert,
UserAlert as UserAlert,
)
from .storage import (
S3Storage as S3Storage,
FileStorage as FileStorage,
Storage as Storage,
)
from .artifact import (
FileArtifact as FileArtifact,
ObjectArtifact as ObjectArtifact,
Artifact as Artifact,
)

from .stats import Stats as Stats
from .run import Run as Run
from .tag import Tag as Tag
from .folder import Folder as Folder, get_folder_from_path as get_folder_from_path
from .events import Events as Events
from .metrics import Metrics as Metrics
16 changes: 16 additions & 0 deletions simvue/api/objects/administrator/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
Simvue Admin Objects
====================

These are Simvue objects only accessible to an administrator of
the server.

"""

from .tenant import Tenant as Tenant
from .user import User as User

__all__ = [
"Tenant",
"User",
]
131 changes: 131 additions & 0 deletions simvue/api/objects/administrator/tenant.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
"""
Simvue Tenants
==============

Contains a class for remotely connecting to Simvue tenants, or defining
a new tenant given relevant arguments.

"""

try:
from typing import Self
except ImportError:
from typing_extensions import Self
import pydantic

from simvue.api.objects.base import write_only, SimvueObject, staging_check


class Tenant(SimvueObject):
"""Class for interacting with a tenant instance on the server."""

@classmethod
@pydantic.validate_call
def new(
cls,
*,
name: str,
is_enabled: bool = True,
max_request_rate: int = 0,
max_runs: int = 0,
max_data_volume: int = 0,
offline: bool = False,
) -> Self:
"""Create a new tenant on the Simvue server.

Requires administrator privileges.

Parameters
----------
name: str
the name for this tenant
is_enabled: bool, optional
whether to enable the tenant on creation, default is True
max_request_rate: int, optional
the maximum request rate allowed for this tenant, default is no limit.
max_runs: int, optional
the maximum number of runs allowed within this tenant, default is no limit.
max_data_volume: int, optional
the maximum volume of data allowed within this tenant, default is no limit.
offline: bool, optional
create in offline mode, default is False.

Returns
-------
Tenant
a tenant instance with staged changes

"""
return Tenant(
name=name,
is_enabled=is_enabled,
max_request_rate=max_request_rate,
max_runs=max_runs,
max_data_volume=max_data_volume,
_read_only=False,
_offline=offline,
)

@property
def name(self) -> str:
"""Retrieve the name of the tenant"""
return self._get_attribute("name")

@name.setter
@write_only
@pydantic.validate_call
def name(self, name: str) -> None:
"""Change name of tenant"""
self._staging["name"] = name

@property
@staging_check
def is_enabled(self) -> bool:
"""Retrieve if tenant is enabled"""
return self._get_attribute("is_enabled")

@is_enabled.setter
@write_only
@pydantic.validate_call
def is_enabled(self, is_enabled: bool) -> None:
"""Enable/disable tenant"""
self._staging["is_enabled"] = is_enabled

@property
@staging_check
def max_request_rate(self) -> int:
"""Retrieve the tenant's maximum request rate"""
return self._get_attribute("max_request_rate")

@max_request_rate.setter
@write_only
@pydantic.validate_call
def max_request_rate(self, max_request_rate: int) -> None:
"""Update tenant's maximum request rate"""
self._staging["max_request_rate"] = max_request_rate

@property
@staging_check
def max_runs(self) -> int:
"""Retrieve the tenant's maximum runs"""
return self._get_attribute("max_runs")

@max_runs.setter
@write_only
@pydantic.validate_call
def max_runs(self, max_runs: int) -> None:
"""Update tenant's maximum runs"""
self._staging["max_runs"] = max_runs

@property
@staging_check
def max_data_volume(self) -> int:
"""Retrieve the tenant's maximum data volume"""
return self._get_attribute("max_data_volume")

@max_data_volume.setter
@write_only
@pydantic.validate_call
def max_data_volume(self, max_data_volume: int) -> None:
"""Update tenant's maximum data volume"""
self._staging["max_data_volume"] = max_data_volume
Loading
Loading