aiosunshine 0.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,122 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # OSX useful to ignore
7
+ *.DS_Store
8
+ .AppleDouble
9
+ .LSOverride
10
+
11
+ # Thumbnails
12
+ ._*
13
+
14
+ # Files that might appear in the root of a volume
15
+ .DocumentRevisions-V100
16
+ .fseventsd
17
+ .Spotlight-V100
18
+ .TemporaryItems
19
+ .Trashes
20
+ .VolumeIcon.icns
21
+ .com.apple.timemachine.donotpresent
22
+
23
+ # Directories potentially created on remote AFP share
24
+ .AppleDB
25
+ .AppleDesktop
26
+ Network Trash Folder
27
+ Temporary Items
28
+ .apdisk
29
+
30
+ # C extensions
31
+ *.so
32
+
33
+ # Distribution / packaging
34
+ .Python
35
+ env/
36
+ build/
37
+ develop-eggs/
38
+ dist/
39
+ downloads/
40
+ eggs/
41
+ .eggs/
42
+ lib/
43
+ lib64/
44
+ parts/
45
+ sdist/
46
+ var/
47
+ *.egg-info/
48
+ .installed.cfg
49
+ *.egg
50
+
51
+ # PyInstaller
52
+ # Usually these files are written by a python script from a template
53
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
54
+ *.manifest
55
+ *.spec
56
+
57
+ # Installer logs
58
+ pip-log.txt
59
+ pip-delete-this-directory.txt
60
+
61
+ # Unit test / coverage reports
62
+ htmlcov/
63
+ .tox/
64
+ .coverage
65
+ .coverage.*
66
+ .cache
67
+ nosetests.xml
68
+ coverage.xml
69
+ *,cover
70
+ .hypothesis/
71
+ .pytest_cache/
72
+
73
+ # Translations
74
+ *.mo
75
+ *.pot
76
+
77
+ # Django stuff:
78
+ *.log
79
+
80
+ # Sphinx documentation
81
+ docs/_build/
82
+
83
+ # pyenv
84
+ .python-version
85
+
86
+ # virtualenv
87
+ .venv
88
+ venv/
89
+ ENV/
90
+
91
+ # mypy
92
+ .mypy_cache/
93
+
94
+ # ruff
95
+ .ruff_cache
96
+
97
+ # Visual Studio Code
98
+ .vscode
99
+
100
+ # IntelliJ Idea family of suites
101
+ .idea
102
+ *.iml
103
+
104
+ ## File-based project format:
105
+ *.ipr
106
+ *.iws
107
+
108
+ ## mpeltonen/sbt-idea plugin
109
+ .idea_modules/
110
+
111
+ # PyBuilder
112
+ target/
113
+
114
+ # Cookiecutter
115
+ output/
116
+ python_boilerplate/
117
+
118
+ # Node
119
+ node_modules/
120
+
121
+ # Deepcode AI
122
+ .dccache
@@ -0,0 +1,21 @@
1
+ # MIT License
2
+
3
+ Copyright (c) 2026 Joost Lekkerkerker
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,185 @@
1
+ Metadata-Version: 2.5
2
+ Name: aiosunshine
3
+ Version: 0.0.1
4
+ Summary: Asynchronous Python client for Sunshine.
5
+ Project-URL: Homepage, https://github.com/the-component-factory/python-sunshine
6
+ Project-URL: Repository, https://github.com/the-component-factory/python-sunshine
7
+ Project-URL: Documentation, https://github.com/the-component-factory/python-sunshine
8
+ Project-URL: Bug Tracker, https://github.com/the-component-factory/python-sunshine/issues
9
+ Project-URL: Changelog, https://github.com/the-component-factory/python-sunshine/releases
10
+ Author-email: Joost Lekkerkerker <joostlek@outlook.com>
11
+ Maintainer-email: Joost Lekkerkerker <joostlek@outlook.com>
12
+ License-Expression: MIT
13
+ License-File: LICENSE.md
14
+ Keywords: Sunshine,api,async,client,gamestream
15
+ Classifier: Development Status :: 5 - Production/Stable
16
+ Classifier: Framework :: AsyncIO
17
+ Classifier: Intended Audience :: Developers
18
+ Classifier: Natural Language :: English
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3.13
21
+ Classifier: Programming Language :: Python :: 3.14
22
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
23
+ Requires-Python: <4,>=3.13
24
+ Requires-Dist: aiohttp>=3.0.0
25
+ Requires-Dist: defusedxml>=0.7.1
26
+ Requires-Dist: mashumaro<4,>=3.11
27
+ Requires-Dist: orjson>=3.9.0
28
+ Requires-Dist: yarl>=1.6.0
29
+ Description-Content-Type: text/markdown
30
+
31
+ # Python: Sunshine
32
+
33
+ [![GitHub Release][releases-shield]][releases]
34
+ [![Python Versions][python-versions-shield]][pypi]
35
+ ![Project Stage][project-stage-shield]
36
+ ![Project Maintenance][maintenance-shield]
37
+ [![License][license-shield]](LICENSE.md)
38
+
39
+ [![Build Status][build-shield]][build]
40
+ [![Code Coverage][codecov-shield]][codecov]
41
+
42
+ Asynchronous Python client for [Sunshine](https://github.com/LizardByte/Sunshine), the self-hosted game stream host for Moonlight.
43
+
44
+ ## About
45
+
46
+ This package allows you to read the state of a Sunshine host and control it.
47
+ It uses the GameStream API, which needs no login, and the Web UI API, which
48
+ needs the Web UI username and password.
49
+
50
+ ## Installation
51
+
52
+ ```bash
53
+ pip install aiosunshine
54
+ ```
55
+
56
+ ## Usage
57
+
58
+ ```python
59
+ import asyncio
60
+
61
+ from aiosunshine import SunshineClient
62
+
63
+
64
+ async def main() -> None:
65
+ async with SunshineClient("192.168.1.2", "username", "password") as client:
66
+ server_info = await client.get_server_info()
67
+ print(server_info.hostname, server_info.streaming)
68
+
69
+ for paired_client in await client.get_paired_clients():
70
+ print(paired_client.name)
71
+
72
+ await client.close_app()
73
+
74
+
75
+ asyncio.run(main())
76
+ ```
77
+
78
+ ## Changelog & Releases
79
+
80
+ This repository keeps a change log using [GitHub's releases][releases]
81
+ functionality. The format of the log is based on
82
+ [Keep a Changelog][keepchangelog].
83
+
84
+ Releases are based on [Semantic Versioning][semver], and use the format
85
+ of ``MAJOR.MINOR.PATCH``. In a nutshell, the version will be incremented
86
+ based on the following:
87
+
88
+ - ``MAJOR``: Incompatible or major changes.
89
+ - ``MINOR``: Backwards-compatible new features and enhancements.
90
+ - ``PATCH``: Backwards-compatible bugfixes and package updates.
91
+
92
+ ## Contributing
93
+
94
+ This is an active open-source project. We are always open to people who want to
95
+ use the code or contribute to it.
96
+
97
+ We've set up a separate document for our
98
+ [contribution guidelines](.github/CONTRIBUTING.md).
99
+
100
+ Thank you for being involved! :heart_eyes:
101
+
102
+ ## Setting up development environment
103
+
104
+ This Python project is fully managed using the [uv][uv] dependency manager. But also relies on the use of NodeJS for certain checks during development.
105
+
106
+ You need at least:
107
+
108
+ - Python 3.13+
109
+ - [uv][uv-install]
110
+ - NodeJS 12+ (including NPM)
111
+
112
+ To install all packages, including all development requirements:
113
+
114
+ ```bash
115
+ npm install
116
+ uv sync --all-groups
117
+ ```
118
+
119
+ As this repository uses the [prek][prek] framework, all changes
120
+ are linted and tested with each commit. You can run all checks and tests
121
+ manually, using the following command:
122
+
123
+ ```bash
124
+ uv run prek run --all-files
125
+ ```
126
+
127
+ To run just the Python tests:
128
+
129
+ ```bash
130
+ uv run pytest
131
+ ```
132
+
133
+ ## Authors & contributors
134
+
135
+ The content is by [Joost Lekkerkerker][joostlek].
136
+
137
+ For a full list of all authors and contributors,
138
+ check [the contributor's page][contributors].
139
+
140
+ ## License
141
+
142
+ MIT License
143
+
144
+ Copyright (c) 2026 Joost Lekkerkerker
145
+
146
+ Permission is hereby granted, free of charge, to any person obtaining a copy
147
+ of this software and associated documentation files (the "Software"), to deal
148
+ in the Software without restriction, including without limitation the rights
149
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
150
+ copies of the Software, and to permit persons to whom the Software is
151
+ furnished to do so, subject to the following conditions:
152
+
153
+ The above copyright notice and this permission notice shall be included in all
154
+ copies or substantial portions of the Software.
155
+
156
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
157
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
158
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
159
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
160
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
161
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
162
+ SOFTWARE.
163
+
164
+ [build-shield]: https://github.com/the-component-factory/python-sunshine/actions/workflows/tests.yaml/badge.svg
165
+ [build]: https://github.com/the-component-factory/python-sunshine/actions
166
+ [codecov-shield]: https://codecov.io/gh/the-component-factory/python-sunshine/branch/master/graph/badge.svg
167
+ [codecov]: https://codecov.io/gh/the-component-factory/python-sunshine
168
+ [commits-shield]: https://img.shields.io/github/commit-activity/y/the-component-factory/python-sunshine.svg
169
+ [commits]: https://github.com/the-component-factory/python-sunshine/commits/master
170
+ [contributors]: https://github.com/the-component-factory/python-sunshine/graphs/contributors
171
+ [joostlek]: https://github.com/joostlek
172
+ [keepchangelog]: http://keepachangelog.com/en/1.0.0/
173
+ [license-shield]: https://img.shields.io/github/license/the-component-factory/python-sunshine.svg
174
+ [maintenance-shield]: https://img.shields.io/maintenance/yes/2026.svg
175
+ [poetry-install]: https://python-poetry.org/docs/#installation
176
+ [poetry]: https://python-poetry.org
177
+ [prek]: https://prek.j178.dev/
178
+ [uv]: https://docs.astral.sh/uv/
179
+ [uv-install]: https://docs.astral.sh/uv/getting-started/installation/
180
+ [project-stage-shield]: https://img.shields.io/badge/project%20stage-stable-green.svg
181
+ [python-versions-shield]: https://img.shields.io/pypi/pyversions/aiosunshine
182
+ [releases-shield]: https://img.shields.io/github/release/the-component-factory/python-sunshine.svg
183
+ [releases]: https://github.com/the-component-factory/python-sunshine/releases
184
+ [semver]: http://semver.org/spec/v2.0.0.html
185
+ [pypi]: https://pypi.org/project/aiosunshine/
@@ -0,0 +1,155 @@
1
+ # Python: Sunshine
2
+
3
+ [![GitHub Release][releases-shield]][releases]
4
+ [![Python Versions][python-versions-shield]][pypi]
5
+ ![Project Stage][project-stage-shield]
6
+ ![Project Maintenance][maintenance-shield]
7
+ [![License][license-shield]](LICENSE.md)
8
+
9
+ [![Build Status][build-shield]][build]
10
+ [![Code Coverage][codecov-shield]][codecov]
11
+
12
+ Asynchronous Python client for [Sunshine](https://github.com/LizardByte/Sunshine), the self-hosted game stream host for Moonlight.
13
+
14
+ ## About
15
+
16
+ This package allows you to read the state of a Sunshine host and control it.
17
+ It uses the GameStream API, which needs no login, and the Web UI API, which
18
+ needs the Web UI username and password.
19
+
20
+ ## Installation
21
+
22
+ ```bash
23
+ pip install aiosunshine
24
+ ```
25
+
26
+ ## Usage
27
+
28
+ ```python
29
+ import asyncio
30
+
31
+ from aiosunshine import SunshineClient
32
+
33
+
34
+ async def main() -> None:
35
+ async with SunshineClient("192.168.1.2", "username", "password") as client:
36
+ server_info = await client.get_server_info()
37
+ print(server_info.hostname, server_info.streaming)
38
+
39
+ for paired_client in await client.get_paired_clients():
40
+ print(paired_client.name)
41
+
42
+ await client.close_app()
43
+
44
+
45
+ asyncio.run(main())
46
+ ```
47
+
48
+ ## Changelog & Releases
49
+
50
+ This repository keeps a change log using [GitHub's releases][releases]
51
+ functionality. The format of the log is based on
52
+ [Keep a Changelog][keepchangelog].
53
+
54
+ Releases are based on [Semantic Versioning][semver], and use the format
55
+ of ``MAJOR.MINOR.PATCH``. In a nutshell, the version will be incremented
56
+ based on the following:
57
+
58
+ - ``MAJOR``: Incompatible or major changes.
59
+ - ``MINOR``: Backwards-compatible new features and enhancements.
60
+ - ``PATCH``: Backwards-compatible bugfixes and package updates.
61
+
62
+ ## Contributing
63
+
64
+ This is an active open-source project. We are always open to people who want to
65
+ use the code or contribute to it.
66
+
67
+ We've set up a separate document for our
68
+ [contribution guidelines](.github/CONTRIBUTING.md).
69
+
70
+ Thank you for being involved! :heart_eyes:
71
+
72
+ ## Setting up development environment
73
+
74
+ This Python project is fully managed using the [uv][uv] dependency manager. But also relies on the use of NodeJS for certain checks during development.
75
+
76
+ You need at least:
77
+
78
+ - Python 3.13+
79
+ - [uv][uv-install]
80
+ - NodeJS 12+ (including NPM)
81
+
82
+ To install all packages, including all development requirements:
83
+
84
+ ```bash
85
+ npm install
86
+ uv sync --all-groups
87
+ ```
88
+
89
+ As this repository uses the [prek][prek] framework, all changes
90
+ are linted and tested with each commit. You can run all checks and tests
91
+ manually, using the following command:
92
+
93
+ ```bash
94
+ uv run prek run --all-files
95
+ ```
96
+
97
+ To run just the Python tests:
98
+
99
+ ```bash
100
+ uv run pytest
101
+ ```
102
+
103
+ ## Authors & contributors
104
+
105
+ The content is by [Joost Lekkerkerker][joostlek].
106
+
107
+ For a full list of all authors and contributors,
108
+ check [the contributor's page][contributors].
109
+
110
+ ## License
111
+
112
+ MIT License
113
+
114
+ Copyright (c) 2026 Joost Lekkerkerker
115
+
116
+ Permission is hereby granted, free of charge, to any person obtaining a copy
117
+ of this software and associated documentation files (the "Software"), to deal
118
+ in the Software without restriction, including without limitation the rights
119
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
120
+ copies of the Software, and to permit persons to whom the Software is
121
+ furnished to do so, subject to the following conditions:
122
+
123
+ The above copyright notice and this permission notice shall be included in all
124
+ copies or substantial portions of the Software.
125
+
126
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
127
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
128
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
129
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
130
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
131
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
132
+ SOFTWARE.
133
+
134
+ [build-shield]: https://github.com/the-component-factory/python-sunshine/actions/workflows/tests.yaml/badge.svg
135
+ [build]: https://github.com/the-component-factory/python-sunshine/actions
136
+ [codecov-shield]: https://codecov.io/gh/the-component-factory/python-sunshine/branch/master/graph/badge.svg
137
+ [codecov]: https://codecov.io/gh/the-component-factory/python-sunshine
138
+ [commits-shield]: https://img.shields.io/github/commit-activity/y/the-component-factory/python-sunshine.svg
139
+ [commits]: https://github.com/the-component-factory/python-sunshine/commits/master
140
+ [contributors]: https://github.com/the-component-factory/python-sunshine/graphs/contributors
141
+ [joostlek]: https://github.com/joostlek
142
+ [keepchangelog]: http://keepachangelog.com/en/1.0.0/
143
+ [license-shield]: https://img.shields.io/github/license/the-component-factory/python-sunshine.svg
144
+ [maintenance-shield]: https://img.shields.io/maintenance/yes/2026.svg
145
+ [poetry-install]: https://python-poetry.org/docs/#installation
146
+ [poetry]: https://python-poetry.org
147
+ [prek]: https://prek.j178.dev/
148
+ [uv]: https://docs.astral.sh/uv/
149
+ [uv-install]: https://docs.astral.sh/uv/getting-started/installation/
150
+ [project-stage-shield]: https://img.shields.io/badge/project%20stage-stable-green.svg
151
+ [python-versions-shield]: https://img.shields.io/pypi/pyversions/aiosunshine
152
+ [releases-shield]: https://img.shields.io/github/release/the-component-factory/python-sunshine.svg
153
+ [releases]: https://github.com/the-component-factory/python-sunshine/releases
154
+ [semver]: http://semver.org/spec/v2.0.0.html
155
+ [pypi]: https://pypi.org/project/aiosunshine/
@@ -0,0 +1,185 @@
1
+ [project]
2
+ name = "aiosunshine"
3
+ version = "0.0.1"
4
+ description = "Asynchronous Python client for Sunshine."
5
+ authors = [{ name = "Joost Lekkerkerker", email = "joostlek@outlook.com" }]
6
+ requires-python = ">=3.13,<4"
7
+ readme = "README.md"
8
+ license = "MIT"
9
+ maintainers = [{ name = "Joost Lekkerkerker", email = "joostlek@outlook.com" }]
10
+ keywords = [
11
+ "Sunshine",
12
+ "gamestream",
13
+ "api",
14
+ "async",
15
+ "client",
16
+ ]
17
+ classifiers = [
18
+ "Development Status :: 5 - Production/Stable",
19
+ "Framework :: AsyncIO",
20
+ "Intended Audience :: Developers",
21
+ "Natural Language :: English",
22
+ "Programming Language :: Python :: 3.13",
23
+ "Programming Language :: Python :: 3.14",
24
+ "Programming Language :: Python :: 3",
25
+ "Topic :: Software Development :: Libraries :: Python Modules",
26
+ ]
27
+ dependencies = [
28
+ "aiohttp>=3.0.0",
29
+ "yarl>=1.6.0",
30
+ "mashumaro>=3.11,<4",
31
+ "orjson>=3.9.0",
32
+ "defusedxml>=0.7.1",
33
+ ]
34
+
35
+ [project.urls]
36
+ Homepage = "https://github.com/the-component-factory/python-sunshine"
37
+ Repository = "https://github.com/the-component-factory/python-sunshine"
38
+ Documentation = "https://github.com/the-component-factory/python-sunshine"
39
+ "Bug Tracker" = "https://github.com/the-component-factory/python-sunshine/issues"
40
+ Changelog = "https://github.com/the-component-factory/python-sunshine/releases"
41
+
42
+ [dependency-groups]
43
+ dev = [
44
+ "aiohttp<3.15",
45
+ "codespell==2.4.3",
46
+ "covdefaults==2.3.0",
47
+ "coverage[toml]==7.17.5",
48
+ "mypy==2.4.1",
49
+ "prek==0.5.12",
50
+ "pre-commit-hooks==6.0.0",
51
+ "pylint==4.1.5",
52
+ "pytest==9.2.0",
53
+ "pytest-asyncio==1.4.1.post1",
54
+ "pytest-cov==7.1.0",
55
+ "ruff==0.17.4",
56
+ "safety==3.8.1",
57
+ "yamllint==1.38.0",
58
+ "syrupy==6.1.1",
59
+ "aiointercept==1.0.0",
60
+ "types-defusedxml==0.7.0.20260504",
61
+ ]
62
+
63
+ [tool.uv]
64
+ default-groups = "all"
65
+
66
+ [tool.hatch.build.targets.sdist]
67
+ include = ["src/aiosunshine"]
68
+
69
+ [tool.hatch.build.targets.wheel]
70
+ include = ["src/aiosunshine"]
71
+
72
+ [tool.hatch.build.targets.wheel.sources]
73
+ "src/aiosunshine" = "aiosunshine"
74
+
75
+ [build-system]
76
+ requires = ["hatchling"]
77
+ build-backend = "hatchling.build"
78
+
79
+ [tool.coverage.report]
80
+ show_missing = true
81
+ fail_under = 50
82
+
83
+ [tool.coverage.run]
84
+ plugins = ["covdefaults"]
85
+ source = ["aiosunshine"]
86
+
87
+ [tool.mypy]
88
+ # Specify the target platform details in config, so your developers are
89
+ # free to run mypy on Windows, Linux, or macOS and get consistent
90
+ # results.
91
+ platform = "linux"
92
+ python_version = "3.13"
93
+
94
+ # show error messages from unrelated files
95
+ follow_imports = "normal"
96
+
97
+ # suppress errors about unsatisfied imports
98
+ ignore_missing_imports = true
99
+
100
+ # be strict
101
+ check_untyped_defs = true
102
+ disallow_any_generics = true
103
+ disallow_incomplete_defs = true
104
+ disallow_subclassing_any = true
105
+ disallow_untyped_calls = true
106
+ disallow_untyped_decorators = true
107
+ disallow_untyped_defs = true
108
+ no_implicit_optional = true
109
+ strict_optional = true
110
+ warn_incomplete_stub = true
111
+ warn_no_return = true
112
+ warn_redundant_casts = true
113
+ warn_return_any = true
114
+ warn_unused_configs = true
115
+ warn_unused_ignores = true
116
+
117
+ [tool.pylint.MASTER]
118
+ ignore = [
119
+ "tests",
120
+ ]
121
+
122
+ [tool.pylint.BASIC]
123
+ good-names = [
124
+ "_",
125
+ "ex",
126
+ "fp",
127
+ "i",
128
+ "id",
129
+ "j",
130
+ "k",
131
+ "on",
132
+ "Run",
133
+ "T",
134
+ ]
135
+
136
+ [tool.pylint.DESIGN]
137
+ max-attributes = 8
138
+
139
+ [tool.pylint."MESSAGES CONTROL"]
140
+ disable = [
141
+ "duplicate-code",
142
+ "format",
143
+ "unsubscriptable-object",
144
+ "too-many-instance-attributes",
145
+ "wrong-import-order",
146
+ "too-many-arguments",
147
+ "too-many-positional-arguments",
148
+ ]
149
+
150
+ [tool.pylint.SIMILARITIES]
151
+ ignore-imports = true
152
+
153
+ [tool.pylint.FORMAT]
154
+ max-line-length = 88
155
+
156
+ [tool.pytest.ini_options]
157
+ addopts = "--cov"
158
+ asyncio_mode = "auto"
159
+
160
+ [tool.ruff.lint]
161
+ ignore = [
162
+ "ANN401", # Opinioated warning on disallowing dynamically typed expressions
163
+ "COM812", # Conflicts with other rules
164
+ "CPY001", # This project doesn't use copyright headers
165
+ "D203", # Conflicts with other rules
166
+ "D213", # Conflicts with other rules
167
+ "D417", # False positives in some occasions
168
+ "ISC001", # Conflicts with other rules
169
+ "PLR0917", # Too many positional arguments, also disabled in pylint
170
+ "PLR2004", # Just annoying, not really useful
171
+ ]
172
+ select = ["ALL"]
173
+
174
+ [tool.ruff.lint.flake8-pytest-style]
175
+ fixture-parentheses = false
176
+ mark-parentheses = false
177
+
178
+ [tool.ruff.lint.isort]
179
+ known-first-party = ["aiosunshine"]
180
+ force-sort-within-sections = true
181
+ split-on-trailing-comma = false
182
+ combine-as-imports = true
183
+
184
+ [tool.ruff.lint.mccabe]
185
+ max-complexity = 25
@@ -0,0 +1,18 @@
1
+ """Asynchronous Python client for Sunshine."""
2
+
3
+ from .exceptions import (
4
+ SunshineAuthenticationError,
5
+ SunshineConnectionError,
6
+ SunshineError,
7
+ )
8
+ from .models import PairedClient, ServerInfo
9
+ from .sunshine import SunshineClient
10
+
11
+ __all__ = [
12
+ "PairedClient",
13
+ "ServerInfo",
14
+ "SunshineAuthenticationError",
15
+ "SunshineClient",
16
+ "SunshineConnectionError",
17
+ "SunshineError",
18
+ ]
@@ -0,0 +1,13 @@
1
+ """Asynchronous Python client for Sunshine."""
2
+
3
+
4
+ class SunshineError(Exception):
5
+ """Generic exception."""
6
+
7
+
8
+ class SunshineConnectionError(SunshineError):
9
+ """Sunshine cannot be reached."""
10
+
11
+
12
+ class SunshineAuthenticationError(SunshineError):
13
+ """The Web UI username or password is wrong."""
@@ -0,0 +1,42 @@
1
+ """Models for Sunshine."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from dataclasses import dataclass, field
6
+
7
+ from mashumaro import field_options
8
+ from mashumaro.mixins.orjson import DataClassORJSONMixin
9
+
10
+
11
+ @dataclass(frozen=True)
12
+ class ServerInfo:
13
+ """State reported by the GameStream /serverinfo endpoint."""
14
+
15
+ unique_id: str
16
+ hostname: str
17
+ version: str
18
+ current_app_id: int
19
+
20
+ @property
21
+ def streaming(self) -> bool:
22
+ """Return True if an app is streaming."""
23
+ return self.current_app_id > 0
24
+
25
+
26
+ @dataclass(frozen=True)
27
+ class PairedClient(DataClassORJSONMixin):
28
+ """A Moonlight client that is paired with Sunshine."""
29
+
30
+ name: str
31
+ uuid: str
32
+ # Sunshine versions before client toggles do not send this field.
33
+ enabled: bool = True
34
+
35
+
36
+ @dataclass(frozen=True)
37
+ class PairedClientsResponse(DataClassORJSONMixin):
38
+ """Response of the /api/clients/list endpoint."""
39
+
40
+ clients: list[PairedClient] = field(
41
+ default_factory=list, metadata=field_options(alias="named_certs")
42
+ )
File without changes
@@ -0,0 +1,158 @@
1
+ """Asynchronous Python client for Sunshine."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import asyncio
6
+ import base64
7
+ from dataclasses import dataclass
8
+ from http import HTTPStatus
9
+ from typing import Self
10
+ from xml.etree.ElementTree import ParseError
11
+
12
+ from aiohttp import ClientError, ClientSession, ServerDisconnectedError
13
+ from aiohttp.hdrs import METH_GET, METH_POST
14
+ from defusedxml import ElementTree
15
+ from yarl import URL
16
+
17
+ from aiosunshine.exceptions import (
18
+ SunshineAuthenticationError,
19
+ SunshineConnectionError,
20
+ SunshineError,
21
+ )
22
+ from aiosunshine.models import PairedClient, PairedClientsResponse, ServerInfo
23
+
24
+ VERSION = "1"
25
+
26
+
27
+ @dataclass
28
+ class SunshineClient:
29
+ """Main class for handling connections with a Sunshine host.
30
+
31
+ The GameStream API is plain HTTP and needs no login. The Web UI API uses
32
+ HTTPS with a self-signed certificate and Basic auth.
33
+ """
34
+
35
+ host: str
36
+ username: str | None = None
37
+ password: str | None = None
38
+ session: ClientSession | None = None
39
+ gamestream_port: int = 47989
40
+ web_ui_port: int = 47990
41
+ request_timeout: int = 10
42
+ _close_session: bool = False
43
+
44
+ @property
45
+ def web_ui_url(self) -> URL:
46
+ """Return the base URL of the Web UI."""
47
+ return URL.build(scheme="https", host=self.host, port=self.web_ui_port)
48
+
49
+ async def _request(self, method: str, url: URL) -> str:
50
+ """Handle a request to Sunshine."""
51
+ if self.session is None:
52
+ self.session = ClientSession()
53
+ self._close_session = True
54
+
55
+ headers = {"User-Agent": f"python-sunshine/{VERSION}"}
56
+ if self.username is not None and self.password is not None:
57
+ credentials = f"{self.username}:{self.password}".encode()
58
+ headers["Authorization"] = f"Basic {base64.b64encode(credentials).decode()}"
59
+
60
+ try:
61
+ async with asyncio.timeout(self.request_timeout):
62
+ response = await self.session.request(
63
+ method,
64
+ url,
65
+ headers=headers,
66
+ # Without a username, Sunshine redirects to its welcome page.
67
+ allow_redirects=False,
68
+ ssl=False,
69
+ )
70
+ body = await response.text()
71
+ except TimeoutError as err:
72
+ msg = f"Timeout occurred while connecting to {url}"
73
+ raise SunshineConnectionError(msg) from err
74
+ except ClientError as err:
75
+ msg = f"Error occurred while communicating with {url}: {err}"
76
+ raise SunshineConnectionError(msg) from err
77
+
78
+ if response.status == HTTPStatus.UNAUTHORIZED or response.status in (
79
+ HTTPStatus.MOVED_PERMANENTLY,
80
+ HTTPStatus.FOUND,
81
+ HTTPStatus.TEMPORARY_REDIRECT,
82
+ ):
83
+ msg = f"Authentication failed for {url} (status {response.status})"
84
+ raise SunshineAuthenticationError(msg)
85
+ if response.status >= HTTPStatus.BAD_REQUEST:
86
+ msg = f"Unexpected status {response.status} from {url}: {body}"
87
+ raise SunshineError(msg)
88
+
89
+ return body
90
+
91
+ async def _web_request(self, method: str, path: str) -> str:
92
+ """Handle a request to the Web UI API."""
93
+ return await self._request(method, self.web_ui_url.joinpath(path))
94
+
95
+ async def get_server_info(self) -> ServerInfo:
96
+ """Return the current server state."""
97
+ url = URL.build(
98
+ scheme="http",
99
+ host=self.host,
100
+ port=self.gamestream_port,
101
+ path="/serverinfo",
102
+ )
103
+ body = await self._request(METH_GET, url)
104
+ try:
105
+ root = ElementTree.fromstring(body)
106
+ except ParseError as err:
107
+ msg = f"Invalid XML response from {url}"
108
+ raise SunshineError(msg) from err
109
+
110
+ return ServerInfo(
111
+ unique_id=root.findtext("uniqueid", ""),
112
+ hostname=root.findtext("hostname", self.host),
113
+ version=root.findtext("appversion", ""),
114
+ current_app_id=int(root.findtext("currentgame", "0")),
115
+ )
116
+
117
+ async def get_paired_clients(self) -> list[PairedClient]:
118
+ """Return the Moonlight clients that are paired with Sunshine."""
119
+ body = await self._web_request(METH_GET, "api/clients/list")
120
+ return PairedClientsResponse.from_json(body).clients
121
+
122
+ async def close_app(self) -> None:
123
+ """Close the app that is streaming."""
124
+ await self._web_request(METH_POST, "api/apps/close")
125
+
126
+ async def restart(self) -> None:
127
+ """Restart the Sunshine process."""
128
+ try:
129
+ await self._web_request(METH_POST, "api/restart")
130
+ except SunshineConnectionError as err:
131
+ # Sunshine restarts before it sends a response, so the connection drops.
132
+ if not isinstance(err.__cause__, ServerDisconnectedError):
133
+ raise
134
+
135
+ async def close(self) -> None:
136
+ """Close open client session."""
137
+ if self.session and self._close_session:
138
+ await self.session.close()
139
+
140
+ async def __aenter__(self) -> Self:
141
+ """Async enter.
142
+
143
+ Returns
144
+ -------
145
+ The SunshineClient object.
146
+
147
+ """
148
+ return self
149
+
150
+ async def __aexit__(self, *_exc_info: object) -> None:
151
+ """Async exit.
152
+
153
+ Args:
154
+ ----
155
+ _exc_info: Exec type.
156
+
157
+ """
158
+ await self.close()