Compare commits

..

50 Commits

Author SHA1 Message Date
d5dbeadda3 fix
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-11-29 10:33:22 -08:00
ed36086040 working samples
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-11-29 10:32:31 -08:00
9f8069decb one working
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-11-29 09:04:49 -08:00
faaeb3a472 pydantic
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-11-29 00:39:14 -08:00
bc3d698539 switch to pydantic
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-11-28 23:50:50 -08:00
d9d73522fd fixes
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-11-28 17:22:38 -08:00
243ed3222a updates
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-11-28 17:07:29 -08:00
098e1fa97d fixes
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-11-28 17:05:43 -08:00
738659dfbc fixes
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-11-28 16:43:20 -08:00
5054fd19d3 fixes
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-11-28 16:37:47 -08:00
058b4dc40a got further
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-11-28 15:17:44 -08:00
373b5ef4ae better
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-11-28 14:29:16 -08:00
6b8807feea improvements
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-11-28 14:16:05 -08:00
b6aa9ab98b better working ws
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-11-28 13:13:13 -08:00
be246702fd Bump urllib3 from 1.26.15 to 1.26.18 (#161)
Bumps [urllib3](https://github.com/urllib3/urllib3) from 1.26.15 to 1.26.18.
- [Release notes](https://github.com/urllib3/urllib3/releases)
- [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst)
- [Commits](https://github.com/urllib3/urllib3/compare/1.26.15...1.26.18)

---
updated-dependencies:
- dependency-name: urllib3
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-27 16:01:44 -08:00
68d7a6d9a3 Bump pillow from 10.0.0 to 10.0.1 (#158)
Bumps [pillow](https://github.com/python-pillow/Pillow) from 10.0.0 to 10.0.1.
- [Release notes](https://github.com/python-pillow/Pillow/releases)
- [Changelog](https://github.com/python-pillow/Pillow/blob/main/CHANGES.rst)
- [Commits](https://github.com/python-pillow/Pillow/compare/10.0.0...10.0.1)

---
updated-dependencies:
- dependency-name: pillow
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-11-27 16:01:35 -08:00
6b2fe3decb Update api spec (#162)
* YOYO NEW API SPEC!

* I have generated the latest API!

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-11-27 16:01:20 -08:00
4f29f55190 updates
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-10-17 19:39:06 -07:00
6ad21a2c87 Update api spec (#159)
* YOYO NEW API SPEC!

* I have generated the latest API!

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-10-17 15:35:56 -07:00
036965255a Update api spec (#157)
* YOYO NEW API SPEC!

* I have generated the latest API!

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-10-12 11:02:59 -05:00
4120a139cd Update api spec (#152)
* YOYO NEW API SPEC!

* I have generated the latest API!

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-09-29 18:04:23 -07:00
12c164620b updates
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-09-29 16:05:40 -07:00
31cd9e532d bump version
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-09-29 15:52:28 -07:00
29b0200c4c Update api spec (#145)
* YOYO NEW API SPEC!

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-09-29 15:51:03 -07:00
ba3fb82a86 Bump pytest from 7.4.1 to 7.4.2 (#146)
Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.4.1 to 7.4.2.
- [Release notes](https://github.com/pytest-dev/pytest/releases)
- [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst)
- [Commits](https://github.com/pytest-dev/pytest/compare/7.4.1...7.4.2)

---
updated-dependencies:
- dependency-name: pytest
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-29 15:26:35 -07:00
4c10c47b4a Bump ruff from 0.0.286 to 0.0.291 (#151)
Bumps [ruff](https://github.com/astral-sh/ruff) from 0.0.286 to 0.0.291.
- [Release notes](https://github.com/astral-sh/ruff/releases)
- [Changelog](https://github.com/astral-sh/ruff/blob/main/BREAKING_CHANGES.md)
- [Commits](https://github.com/astral-sh/ruff/compare/v0.0.286...v0.0.291)

---
updated-dependencies:
- dependency-name: ruff
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-29 15:22:27 -07:00
2e279da9c1 Bump httpx from 0.24.0 to 0.25.0 (#147)
Bumps [httpx](https://github.com/encode/httpx) from 0.24.0 to 0.25.0.
- [Release notes](https://github.com/encode/httpx/releases)
- [Changelog](https://github.com/encode/httpx/blob/master/CHANGELOG.md)
- [Commits](https://github.com/encode/httpx/compare/0.24.0...0.25.0)

---
updated-dependencies:
- dependency-name: httpx
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-29 15:17:30 -07:00
12e5baef9e Bump types-toml from 0.10.8.6 to 0.10.8.7 (#144)
Bumps [types-toml](https://github.com/python/typeshed) from 0.10.8.6 to 0.10.8.7.
- [Commits](https://github.com/python/typeshed/commits)

---
updated-dependencies:
- dependency-name: types-toml
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-29 15:14:19 -07:00
0ef8f505ad Bump sphinx-autodoc-typehints from 1.19.1 to 1.24.0 (#141)
Bumps [sphinx-autodoc-typehints](https://github.com/tox-dev/sphinx-autodoc-typehints) from 1.19.1 to 1.24.0.
- [Release notes](https://github.com/tox-dev/sphinx-autodoc-typehints/releases)
- [Changelog](https://github.com/tox-dev/sphinx-autodoc-typehints/blob/main/CHANGELOG.md)
- [Commits](https://github.com/tox-dev/sphinx-autodoc-typehints/compare/1.19.1...1.24.0)

---
updated-dependencies:
- dependency-name: sphinx-autodoc-typehints
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-29 15:09:19 -07:00
01a73859d4 Update api spec (#140)
* YOYO NEW API SPEC!

* bump version

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fixes

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* I have generated the latest API!

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-09-06 11:27:00 -07:00
f63509a1eb Bump pytest from 7.3.1 to 7.4.1 (#138)
Bumps [pytest](https://github.com/pytest-dev/pytest) from 7.3.1 to 7.4.1.
- [Release notes](https://github.com/pytest-dev/pytest/releases)
- [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst)
- [Commits](https://github.com/pytest-dev/pytest/compare/7.3.1...7.4.1)

---
updated-dependencies:
- dependency-name: pytest
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-06 11:04:43 -07:00
7cb8d5327f Bump jsonpatch from 1.32 to 1.33 (#137)
Bumps [jsonpatch](https://github.com/stefankoegl/python-json-patch) from 1.32 to 1.33.
- [Commits](https://github.com/stefankoegl/python-json-patch/compare/v1.32...v1.33)

---
updated-dependencies:
- dependency-name: jsonpatch
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-06 11:01:18 -07:00
1f9a787c15 Bump types-python-dateutil from 2.8.19.12 to 2.8.19.14 (#134)
Bumps [types-python-dateutil](https://github.com/python/typeshed) from 2.8.19.12 to 2.8.19.14.
- [Commits](https://github.com/python/typeshed/commits)

---
updated-dependencies:
- dependency-name: types-python-dateutil
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-06 10:58:42 -07:00
3e2c9450dc Bump pytest-cov from 4.0.0 to 4.1.0 (#136)
Bumps [pytest-cov](https://github.com/pytest-dev/pytest-cov) from 4.0.0 to 4.1.0.
- [Changelog](https://github.com/pytest-dev/pytest-cov/blob/master/CHANGELOG.rst)
- [Commits](https://github.com/pytest-dev/pytest-cov/compare/v4.0.0...v4.1.0)

---
updated-dependencies:
- dependency-name: pytest-cov
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-06 10:51:02 -07:00
eb8d1b77bb Bump actions/checkout from 3 to 4 (#139)
* Bump actions/checkout from 3 to 4

Bumps [actions/checkout](https://github.com/actions/checkout) from 3 to 4.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v3...v4)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <support@github.com>

* I have generated the latest API!

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-09-06 10:47:43 -07:00
d5184bf172 Bump pytest-asyncio from 0.21.0 to 0.21.1 (#133)
Bumps [pytest-asyncio](https://github.com/pytest-dev/pytest-asyncio) from 0.21.0 to 0.21.1.
- [Release notes](https://github.com/pytest-dev/pytest-asyncio/releases)
- [Commits](https://github.com/pytest-dev/pytest-asyncio/compare/v0.21.0...v0.21.1)

---
updated-dependencies:
- dependency-name: pytest-asyncio
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-09-06 10:47:22 -07:00
3cad86c5a3 updates
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-08-30 18:39:19 -07:00
63824cd04f Update api spec (#132)
* YOYO NEW API SPEC!

* I have generated the latest API!

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-08-30 18:30:23 -07:00
816904419e Bump tornado from 6.3.1 to 6.3.3 (#130)
Bumps [tornado](https://github.com/tornadoweb/tornado) from 6.3.1 to 6.3.3.
- [Changelog](https://github.com/tornadoweb/tornado/blob/master/docs/releases.rst)
- [Commits](https://github.com/tornadoweb/tornado/compare/v6.3.1...v6.3.3)

---
updated-dependencies:
- dependency-name: tornado
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-08-30 18:30:12 -07:00
e68857f4c9 Bump certifi from 2022.12.7 to 2023.7.22 (#131)
Bumps [certifi](https://github.com/certifi/python-certifi) from 2022.12.7 to 2023.7.22.
- [Commits](https://github.com/certifi/python-certifi/compare/2022.12.07...2023.07.22)

---
updated-dependencies:
- dependency-name: certifi
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-08-30 18:30:00 -07:00
db1bd33c79 fixes
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-08-30 16:59:35 -07:00
dea0d637fe fixes
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-08-30 16:24:09 -07:00
2e1c75769f updates
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-08-30 16:18:39 -07:00
8162fa1964 Update api spec (#127)
* YOYO NEW API SPEC!

* bump version

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* updates

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* some fixes

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fixes #128

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* mypy fixes

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fixes

Signed-off-by: Jess Frazelle <github@jessfraz.com>

* fixes

Signed-off-by: Jess Frazelle <github@jessfraz.com>

---------

Signed-off-by: Jess Frazelle <github@jessfraz.com>
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-08-30 15:59:51 -07:00
d737fb4e8f Update ruff requirement from ^0.0.284 to ^0.0.286 (#129)
Updates the requirements on [ruff](https://github.com/astral-sh/ruff) to permit the latest version.
- [Release notes](https://github.com/astral-sh/ruff/releases)
- [Changelog](https://github.com/astral-sh/ruff/blob/main/BREAKING_CHANGES.md)
- [Commits](https://github.com/astral-sh/ruff/compare/v0.0.284...v0.0.286)

---
updated-dependencies:
- dependency-name: ruff
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-08-30 12:24:05 -07:00
686ec0cb36 bump versino
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-08-17 14:39:54 -07:00
f522911d7b Update api spec (#125)
* YOYO NEW API SPEC!

* I have generated the latest API!

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2023-08-17 14:30:53 -07:00
1e693890ef fix
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-08-17 14:13:56 -07:00
755a4fd789 Revert "fixes"
This reverts commit 581c06a943.
2023-08-17 14:02:51 -07:00
581c06a943 fixes
Signed-off-by: Jess Frazelle <github@jessfraz.com>
2023-08-17 14:01:41 -07:00
298 changed files with 24433 additions and 32319 deletions

View File

@ -15,7 +15,7 @@ jobs:
black:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4

View File

@ -22,7 +22,7 @@ jobs:
python-version: [3.8, 3.9]
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:

View File

@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:

View File

@ -16,7 +16,7 @@ jobs:
if: ${{ github.event.pull_request.head.repo.full_name == github.repository }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}
- name: Run generate

View File

@ -8,7 +8,7 @@ jobs:
name: make-release
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: '3.x'

View File

@ -15,7 +15,7 @@ jobs:
mypy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4

View File

@ -15,7 +15,7 @@ jobs:
ruff:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4

View File

@ -15,7 +15,7 @@ jobs:
name: update-spec
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: make generate
shell: bash
run: |
@ -34,7 +34,7 @@ jobs:
echo "No files changed, proceeding";
fi
# Checkout the docs repo since we will want to update the files there.
- uses: actions/checkout@v3
- uses: actions/checkout@v4
with:
repository: 'kittycad/website'
path: 'docs'

3
.gitignore vendored
View File

@ -22,10 +22,11 @@ dmypy.json
/coverage.xml
/.coverage
poetry.lock
testing
# Sphinx documentation
docs/_build/
docs/_autosummary/
docs/html/_sources/
snapshot.png

1939
assets/ORIGINALVOXEL-3.obj Normal file

File diff suppressed because it is too large Load Diff

16
generate/float.py.jinja2 Normal file
View File

@ -0,0 +1,16 @@
from typing import Any
from pydantic import GetCoreSchemaHandler
from pydantic_core import CoreSchema, core_schema
class {{name}}(float):
"""{{description}}"""
def __float__(self) -> float:
return self
@classmethod
def __get_pydantic_core_schema__(
cls, source_type: Any, handler: GetCoreSchemaHandler
) -> CoreSchema:
return core_schema.no_info_after_validator_function(cls, handler(float))

View File

@ -1,4 +1,6 @@
from typing import Any, Dict, Optional, Union, List
from typing import Iterator, Any, Dict, Optional, Union, List
import json
import bson
from websockets.sync.client import connect as ws_connect
from websockets.client import connect as ws_connect_async
@ -16,26 +18,37 @@ from ...types import Response
def _get_kwargs(
{% for arg in args %}
{% if arg.in_query %}
{% if arg.is_optional == False %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endif %}
{% endfor %}
*,
client: Client,
{% for arg in args %}
{% if arg.in_query %}
{% if arg.is_optional %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endif %}
{% endfor %}
) -> Dict[str, Any]:
url = "{{url_template}}".format(client.base_url{% for arg in args %}{% if arg.in_url %}, {{arg.name}}={{arg.name}}{% endif %}{% endfor %}) # noqa: E501
{% for arg in args %}
{% if arg.in_query %}
if {{arg.name}} is not None:
{% if arg.type == "bool" %}
if "?" in url:
url = url + "&{{arg.name}}=" + str({{arg.name}}).lower()
else:
url = url + "?{{arg.name}}=" + str({{arg.name}}).lower()
{% else %}
if "?" in url:
url = url + "&{{arg.name}}=" + str({{arg.name}})
else:
url = url + "?{{arg.name}}=" + str({{arg.name}})
{% endif %}
{% endif %}
{% endfor %}
@ -48,66 +61,140 @@ def _get_kwargs(
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
{% if has_request_body %}"content": body,{% endif %}
}
def sync(
{% for arg in args %}
{% if arg.in_query %}
{% if arg.is_optional == False %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endif %}
{% endfor %}
*,
client: Client,
{% for arg in args %}
{% if arg.in_query %}
{% if arg.is_optional %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endif %}
{% endfor %}
) -> ClientConnection:
{%if docs%}"""{{docs}}""" # noqa: E501{% endif %}
kwargs = _get_kwargs(
{% for arg in args %}
{% if arg.in_query %}
{{arg.name}}={{arg.name}},
{% endif %}
{% endfor %}
client=client,
)
with ws_connect(kwargs["url"].replace("https://", "wss://"), additional_headers=kwargs["headers"]) as websocket:
return websocket # type: ignore
# Return an error if we got here.
return Error(message="An error occurred while connecting to the websocket.")
return ws_connect(kwargs["url"].replace("http", "ws"), additional_headers=kwargs["headers"], close_timeout=120, max_size=None) # type: ignore
async def asyncio(
{% for arg in args %}
{% if arg.in_query %}
{% if arg.is_optional == False %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endif %}
{% endfor %}
*,
client: Client,
{% for arg in args %}
{% if arg.in_query %}
{% if arg.is_optional %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endif %}
{% endfor %}
) -> WebSocketClientProtocol:
{%if docs%}"""{{docs}}""" # noqa: E501{% endif %}
kwargs = _get_kwargs(
{% for arg in args %}
{% if arg.in_query %}
{{arg.name}}={{arg.name}},
{% endif %}
{% endfor %}
client=client,
)
async with ws_connect_async(kwargs["url"].replace("https://", "wss://"), extra_headers=kwargs["headers"]) as websocket:
return websocket
return await ws_connect_async(kwargs["url"].replace("http", "ws"), extra_headers=kwargs["headers"], close_timeout=120, max_size=None)
# Return an error if we got here.
return Error(message="An error occurred while connecting to the websocket.")
{% if has_request_body %}
class WebSocket:
"""A websocket connection to the API endpoint."""
ws: ClientConnection
def __init__(self,
{% for arg in args %}
{% if arg.in_query %}
{% if arg.is_optional == False %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endif %}
{% endfor %}
client: Client,
{% for arg in args %}
{% if arg.in_query %}
{% if arg.is_optional %}
{{arg.name}}: {{arg.type}},
{% endif %}
{% endif %}
{% endfor %}
):
self.ws = sync(
{% for arg in args %}
{% if arg.in_query %}
{{arg.name}},
{% endif %}
{% endfor %}
client=client,
)
def __enter__(self,
):
return self
def __exit__(self, exc_type, exc_value, traceback):
self.close()
def __iter__(self) -> Iterator[{{response_type}}]:
"""
Iterate on incoming messages.
The iterator calls :meth:`recv` and yields messages in an infinite loop.
It exits when the connection is closed normally. It raises a
:exc:`~websockets.exceptions.ConnectionClosedError` exception after a
protocol error or a network failure.
"""
for message in self.ws:
yield {{response_type}}(**json.loads(message))
def send(self, data:{% for arg in args %}{%if arg.name == "body" %}{{arg.type}}{% endif %}{% endfor %}):
"""Send data to the websocket."""
self.ws.send(json.dumps(data.model_dump()))
def send_binary(self, data:{% for arg in args %}{%if arg.name == "body" %}{{arg.type}}{% endif %}{% endfor %}):
"""Send data as bson to the websocket."""
self.ws.send(bson.encode(data.model_dump())) # type: ignore
def recv(self) -> {{response_type}}:
"""Receive data from the websocket."""
message = self.ws.recv(timeout=60)
return {{response_type}}(**json.loads(message))
def close(self):
"""Close the websocket."""
self.ws.close()
{%endif%}

View File

@ -28,10 +28,17 @@ def _get_kwargs(
{% for arg in args %}
{% if arg.in_query %}
if {{arg.name}} is not None:
{% if arg.type == "bool" %}
if "?" in url:
url = url + "&{{arg.name}}=" + str({{arg.name}}).lower()
else:
url = url + "?{{arg.name}}=" + str({{arg.name}}).lower()
{% else %}
if "?" in url:
url = url + "&{{arg.name}}=" + str({{arg.name}})
else:
url = url + "?{{arg.name}}=" + str({{arg.name}})
{% endif %}
{% endif %}
{% endfor %}

File diff suppressed because it is too large Load Diff

16
generate/int.py.jinja2 Normal file
View File

@ -0,0 +1,16 @@
from typing import Any
from pydantic import GetCoreSchemaHandler
from pydantic_core import CoreSchema, core_schema
class {{name}}(int):
"""{{description}}"""
def __int__(self) -> int:
return self
@classmethod
def __get_pydantic_core_schema__(
cls, source_type: Any, handler: GetCoreSchemaHandler
) -> CoreSchema:
return core_schema.no_info_after_validator_function(cls, handler(int))

21
generate/object.py.jinja2 Normal file
View File

@ -0,0 +1,21 @@
import datetime
from typing import List, Optional, Dict, Union, Any, Literal
from uuid import UUID
from pydantic import BaseModel, Base64Bytes, AnyUrl
from pydantic_extra_types.phone_numbers import PhoneNumber
from .base64data import Base64Data
{% for import in imports %}
{{ import }}
{% endfor %}
class {{ name }}(BaseModel):
"""{{ description }}"""
{% for field in fields %}
{% if field.value %}
{{ field.name }}: Literal[{{ field.value }}] = {{ field.value }}
{% else %}
{{ field.name }}: {{ field.type }}
{% endif %}
{% endfor %}

View File

@ -5,10 +5,15 @@ set -o pipefail
# Fix for ci.
git config --global --add safe.directory /home/user/src
git add kittycad/models/base64data.py
git add kittycad/models/empty.py
# Cleanup old stuff.
rm -rf kittycad/models
rm -rf kittycad/api
git checkout kittycad/api/file/*_with_base64_helper.py &>/dev/null
git checkout kittycad/models/base64data.py
git checkout kittycad/models/empty.py
# Generate new.
poetry run python generate/generate.py

16
generate/str.py.jinja2 Normal file
View File

@ -0,0 +1,16 @@
from typing import Any
from pydantic import GetCoreSchemaHandler
from pydantic_core import CoreSchema, core_schema
class {{name}}(str):
"""{{description}}"""
def __str__(self) -> str:
return self
@classmethod
def __get_pydantic_core_schema__(
cls, source_type: Any, handler: GetCoreSchemaHandler
) -> CoreSchema:
return core_schema.no_info_after_validator_function(cls, handler(str))

View File

@ -0,0 +1,21 @@
from typing import Dict, Any, Union, Type, TypeVar
from pydantic import RootModel, Field
from typing_extensions import Annotated
{% if tag %}
{{name}} = RootModel[Annotated[Union[
{% for type in types %}
{{type.name}},
{% endfor %}
], Field(discriminator='{{tag}}')]]
{% else %}
{{name}} = RootModel[Union[
{% for type in types %}
{{type.name}},
{% endfor %}
]]
{% endif %}

File diff suppressed because one or more lines are too long

View File

@ -1,137 +0,0 @@
from typing import Any, Dict, Optional, Union
import httpx
from ...client import Client
from ...models.error import Error
from ...models.file_export_format import FileExportFormat
from ...models.image_type import ImageType
from ...models.mesh import Mesh
from ...types import Response
def _get_kwargs(
input_format: ImageType,
output_format: FileExportFormat,
body: bytes,
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/ai/image-to-3d/{input_format}/{output_format}".format(
client.base_url,
input_format=input_format,
output_format=output_format,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()
return {
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
"content": body,
}
def _parse_response(*, response: httpx.Response) -> Optional[Union[Mesh, Error]]:
if response.status_code == 200:
response_200 = Mesh.from_dict(response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
return response_5XX
return Error.from_dict(response.json())
def _build_response(
*, response: httpx.Response
) -> Response[Optional[Union[Mesh, Error]]]:
return Response(
status_code=response.status_code,
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
)
def sync_detailed(
input_format: ImageType,
output_format: FileExportFormat,
body: bytes,
*,
client: Client,
) -> Response[Optional[Union[Mesh, Error]]]:
kwargs = _get_kwargs(
input_format=input_format,
output_format=output_format,
body=body,
client=client,
)
response = httpx.post(
verify=client.verify_ssl,
**kwargs,
)
return _build_response(response=response)
def sync(
input_format: ImageType,
output_format: FileExportFormat,
body: bytes,
*,
client: Client,
) -> Optional[Union[Mesh, Error]]:
"""This is an alpha endpoint. It will change in the future. The current output is honestly pretty bad. So if you find this endpoint, you get what you pay for, which currently is nothing. But in the future will be made a lot better.""" # noqa: E501
return sync_detailed(
input_format=input_format,
output_format=output_format,
body=body,
client=client,
).parsed
async def asyncio_detailed(
input_format: ImageType,
output_format: FileExportFormat,
body: bytes,
*,
client: Client,
) -> Response[Optional[Union[Mesh, Error]]]:
kwargs = _get_kwargs(
input_format=input_format,
output_format=output_format,
body=body,
client=client,
)
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
response = await _client.post(**kwargs)
return _build_response(response=response)
async def asyncio(
input_format: ImageType,
output_format: FileExportFormat,
body: bytes,
*,
client: Client,
) -> Optional[Union[Mesh, Error]]:
"""This is an alpha endpoint. It will change in the future. The current output is honestly pretty bad. So if you find this endpoint, you get what you pay for, which currently is nothing. But in the future will be made a lot better.""" # noqa: E501
return (
await asyncio_detailed(
input_format=input_format,
output_format=output_format,
body=body,
client=client,
)
).parsed

View File

@ -1,131 +0,0 @@
from typing import Any, Dict, Optional, Union
import httpx
from ...client import Client
from ...models.error import Error
from ...models.file_export_format import FileExportFormat
from ...models.mesh import Mesh
from ...types import Response
def _get_kwargs(
output_format: FileExportFormat,
prompt: str,
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/ai/text-to-3d/{output_format}".format(
client.base_url,
output_format=output_format,
) # noqa: E501
if prompt is not None:
if "?" in url:
url = url + "&prompt=" + str(prompt)
else:
url = url + "?prompt=" + str(prompt)
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()
return {
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
}
def _parse_response(*, response: httpx.Response) -> Optional[Union[Mesh, Error]]:
if response.status_code == 200:
response_200 = Mesh.from_dict(response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
return response_5XX
return Error.from_dict(response.json())
def _build_response(
*, response: httpx.Response
) -> Response[Optional[Union[Mesh, Error]]]:
return Response(
status_code=response.status_code,
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
)
def sync_detailed(
output_format: FileExportFormat,
prompt: str,
*,
client: Client,
) -> Response[Optional[Union[Mesh, Error]]]:
kwargs = _get_kwargs(
output_format=output_format,
prompt=prompt,
client=client,
)
response = httpx.post(
verify=client.verify_ssl,
**kwargs,
)
return _build_response(response=response)
def sync(
output_format: FileExportFormat,
prompt: str,
*,
client: Client,
) -> Optional[Union[Mesh, Error]]:
"""This is an alpha endpoint. It will change in the future. The current output is honestly pretty bad. So if you find this endpoint, you get what you pay for, which currently is nothing. But in the future will be made a lot better.""" # noqa: E501
return sync_detailed(
output_format=output_format,
prompt=prompt,
client=client,
).parsed
async def asyncio_detailed(
output_format: FileExportFormat,
prompt: str,
*,
client: Client,
) -> Response[Optional[Union[Mesh, Error]]]:
kwargs = _get_kwargs(
output_format=output_format,
prompt=prompt,
client=client,
)
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
response = await _client.post(**kwargs)
return _build_response(response=response)
async def asyncio(
output_format: FileExportFormat,
prompt: str,
*,
client: Client,
) -> Optional[Union[Mesh, Error]]:
"""This is an alpha endpoint. It will change in the future. The current output is honestly pretty bad. So if you find this endpoint, you get what you pay for, which currently is nothing. But in the future will be made a lot better.""" # noqa: E501
return (
await asyncio_detailed(
output_format=output_format,
prompt=prompt,
client=client,
)
).parsed

View File

@ -0,0 +1,135 @@
from typing import Any, Dict, Optional, Union
import httpx
from ...client import Client
from ...models.error import Error
from ...models.file_export_format import FileExportFormat
from ...models.text_to_cad import TextToCad
from ...models.text_to_cad_create_body import TextToCadCreateBody
from ...types import Response
def _get_kwargs(
output_format: FileExportFormat,
body: TextToCadCreateBody,
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/ai/text-to-cad/{output_format}".format(
client.base_url,
output_format=output_format,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()
return {
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
"content": body,
}
def _parse_response(*, response: httpx.Response) -> Optional[Union[TextToCad, Error]]:
if response.status_code == 201:
response_201 = TextToCad(**response.json())
return response_201
if response.status_code == 400:
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error(**response.json())
return response_5XX
return Error(**response.json())
def _build_response(
*, response: httpx.Response
) -> Response[Optional[Union[TextToCad, Error]]]:
return Response(
status_code=response.status_code,
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
)
def sync_detailed(
output_format: FileExportFormat,
body: TextToCadCreateBody,
*,
client: Client,
) -> Response[Optional[Union[TextToCad, Error]]]:
kwargs = _get_kwargs(
output_format=output_format,
body=body,
client=client,
)
response = httpx.post(
verify=client.verify_ssl,
**kwargs,
)
return _build_response(response=response)
def sync(
output_format: FileExportFormat,
body: TextToCadCreateBody,
*,
client: Client,
) -> Optional[Union[TextToCad, Error]]:
"""Because our source of truth for the resulting model is a STEP file, you will always have STEP file contents when you list your generated models. Any other formats you request here will also be returned when you list your generated models.
This operation is performed asynchronously, the `id` of the operation will be returned. You can use the `id` returned from the request to get status information about the async operation from the `/async/operations/{id}` endpoint.
One thing to note, if you hit the cache, this endpoint will return right away. So you only have to wait if the status is not `Completed` or `Failed`.
This is an alpha endpoint. It will change in the future. The current output is honestly pretty bad. So if you find this endpoint, you get what you pay for, which currently is nothing. But in the future will be made a lot better.
""" # noqa: E501
return sync_detailed(
output_format=output_format,
body=body,
client=client,
).parsed
async def asyncio_detailed(
output_format: FileExportFormat,
body: TextToCadCreateBody,
*,
client: Client,
) -> Response[Optional[Union[TextToCad, Error]]]:
kwargs = _get_kwargs(
output_format=output_format,
body=body,
client=client,
)
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
response = await _client.post(**kwargs)
return _build_response(response=response)
async def asyncio(
output_format: FileExportFormat,
body: TextToCadCreateBody,
*,
client: Client,
) -> Optional[Union[TextToCad, Error]]:
"""Because our source of truth for the resulting model is a STEP file, you will always have STEP file contents when you list your generated models. Any other formats you request here will also be returned when you list your generated models.
This operation is performed asynchronously, the `id` of the operation will be returned. You can use the `id` returned from the request to get status information about the async operation from the `/async/operations/{id}` endpoint.
One thing to note, if you hit the cache, this endpoint will return right away. So you only have to wait if the status is not `Completed` or `Failed`.
This is an alpha endpoint. It will change in the future. The current output is honestly pretty bad. So if you find this endpoint, you get what you pay for, which currently is nothing. But in the future will be made a lot better.
""" # noqa: E501
return (
await asyncio_detailed(
output_format=output_format,
body=body,
client=client,
)
).parsed

View File

@ -0,0 +1,126 @@
from typing import Any, Dict, Optional
import httpx
from ...client import Client
from ...models.ai_feedback import AiFeedback
from ...models.error import Error
from ...types import Response
def _get_kwargs(
id: str,
feedback: AiFeedback,
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/user/text-to-cad/{id}".format(
client.base_url,
id=id,
) # noqa: E501
if feedback is not None:
if "?" in url:
url = url + "&feedback=" + str(feedback)
else:
url = url + "?feedback=" + str(feedback)
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()
return {
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
}
def _parse_response(*, response: httpx.Response) -> Optional[Error]:
return None
if response.status_code == 400:
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error(**response.json())
return response_5XX
return Error(**response.json())
def _build_response(*, response: httpx.Response) -> Response[Optional[Error]]:
return Response(
status_code=response.status_code,
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
)
def sync_detailed(
id: str,
feedback: AiFeedback,
*,
client: Client,
) -> Response[Optional[Error]]:
kwargs = _get_kwargs(
id=id,
feedback=feedback,
client=client,
)
response = httpx.post(
verify=client.verify_ssl,
**kwargs,
)
return _build_response(response=response)
def sync(
id: str,
feedback: AiFeedback,
*,
client: Client,
) -> Optional[Error]:
"""This endpoint requires authentication by any KittyCAD user. The user must be the owner of the text-to-CAD model, in order to give feedback.""" # noqa: E501
return sync_detailed(
id=id,
feedback=feedback,
client=client,
).parsed
async def asyncio_detailed(
id: str,
feedback: AiFeedback,
*,
client: Client,
) -> Response[Optional[Error]]:
kwargs = _get_kwargs(
id=id,
feedback=feedback,
client=client,
)
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
response = await _client.post(**kwargs)
return _build_response(response=response)
async def asyncio(
id: str,
feedback: AiFeedback,
*,
client: Client,
) -> Optional[Error]:
"""This endpoint requires authentication by any KittyCAD user. The user must be the owner of the text-to-CAD model, in order to give feedback.""" # noqa: E501
return (
await asyncio_detailed(
id=id,
feedback=feedback,
client=client,
)
).parsed

View File

@ -3,18 +3,19 @@ from typing import Any, Dict, Optional, Union
import httpx
from ...client import Client
from ...models.ai_prompt import AiPrompt
from ...models.error import Error
from ...models.modeling_cmd_req import ModelingCmdReq
from ...types import Response
def _get_kwargs(
body: ModelingCmdReq,
id: str,
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/modeling/cmd".format(
url = "{}/ai-prompts/{id}".format(
client.base_url,
id=id,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
@ -25,26 +26,25 @@ def _get_kwargs(
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
"content": body,
}
def _parse_response(*, response: httpx.Response) -> Optional[Union[dict, Error]]:
def _parse_response(*, response: httpx.Response) -> Optional[Union[AiPrompt, Error]]:
if response.status_code == 200:
response_200 = response.json()
response_200 = AiPrompt(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(
*, response: httpx.Response
) -> Response[Optional[Union[dict, Error]]]:
) -> Response[Optional[Union[AiPrompt, Error]]]:
return Response(
status_code=response.status_code,
content=response.content,
@ -54,16 +54,16 @@ def _build_response(
def sync_detailed(
body: ModelingCmdReq,
id: str,
*,
client: Client,
) -> Response[Optional[Union[dict, Error]]]:
) -> Response[Optional[Union[AiPrompt, Error]]]:
kwargs = _get_kwargs(
body=body,
id=id,
client=client,
)
response = httpx.post(
response = httpx.get(
verify=client.verify_ssl,
**kwargs,
)
@ -72,44 +72,44 @@ def sync_detailed(
def sync(
body: ModelingCmdReq,
id: str,
*,
client: Client,
) -> Optional[Union[dict, Error]]:
"""Response depends on which command was submitted, so unfortunately the OpenAPI schema can't generate the right response type.""" # noqa: E501
) -> Optional[Union[AiPrompt, Error]]:
"""This endpoint requires authentication by a KittyCAD employee.""" # noqa: E501
return sync_detailed(
body=body,
id=id,
client=client,
).parsed
async def asyncio_detailed(
body: ModelingCmdReq,
id: str,
*,
client: Client,
) -> Response[Optional[Union[dict, Error]]]:
) -> Response[Optional[Union[AiPrompt, Error]]]:
kwargs = _get_kwargs(
body=body,
id=id,
client=client,
)
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
response = await _client.post(**kwargs)
response = await _client.get(**kwargs)
return _build_response(response=response)
async def asyncio(
body: ModelingCmdReq,
id: str,
*,
client: Client,
) -> Optional[Union[dict, Error]]:
"""Response depends on which command was submitted, so unfortunately the OpenAPI schema can't generate the right response type.""" # noqa: E501
) -> Optional[Union[AiPrompt, Error]]:
"""This endpoint requires authentication by a KittyCAD employee.""" # noqa: E501
return (
await asyncio_detailed(
body=body,
id=id,
client=client,
)
).parsed

View File

@ -4,18 +4,18 @@ import httpx
from ...client import Client
from ...models.error import Error
from ...models.modeling_cmd_req_batch import ModelingCmdReqBatch
from ...models.modeling_outcomes import ModelingOutcomes
from ...models.text_to_cad import TextToCad
from ...types import Response
def _get_kwargs(
body: ModelingCmdReqBatch,
id: str,
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/modeling/cmd-batch".format(
url = "{}/user/text-to-cad/{id}".format(
client.base_url,
id=id,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
@ -26,28 +26,25 @@ def _get_kwargs(
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
"content": body,
}
def _parse_response(
*, response: httpx.Response
) -> Optional[Union[ModelingOutcomes, Error]]:
def _parse_response(*, response: httpx.Response) -> Optional[Union[TextToCad, Error]]:
if response.status_code == 200:
response_200 = ModelingOutcomes.from_dict(response.json())
response_200 = TextToCad(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(
*, response: httpx.Response
) -> Response[Optional[Union[ModelingOutcomes, Error]]]:
) -> Response[Optional[Union[TextToCad, Error]]]:
return Response(
status_code=response.status_code,
content=response.content,
@ -57,16 +54,16 @@ def _build_response(
def sync_detailed(
body: ModelingCmdReqBatch,
id: str,
*,
client: Client,
) -> Response[Optional[Union[ModelingOutcomes, Error]]]:
) -> Response[Optional[Union[TextToCad, Error]]]:
kwargs = _get_kwargs(
body=body,
id=id,
client=client,
)
response = httpx.post(
response = httpx.get(
verify=client.verify_ssl,
**kwargs,
)
@ -75,40 +72,44 @@ def sync_detailed(
def sync(
body: ModelingCmdReqBatch,
id: str,
*,
client: Client,
) -> Optional[Union[ModelingOutcomes, Error]]:
) -> Optional[Union[TextToCad, Error]]:
"""This endpoint requires authentication by any KittyCAD user. The user must be the owner of the text-to-CAD model.""" # noqa: E501
return sync_detailed(
body=body,
id=id,
client=client,
).parsed
async def asyncio_detailed(
body: ModelingCmdReqBatch,
id: str,
*,
client: Client,
) -> Response[Optional[Union[ModelingOutcomes, Error]]]:
) -> Response[Optional[Union[TextToCad, Error]]]:
kwargs = _get_kwargs(
body=body,
id=id,
client=client,
)
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
response = await _client.post(**kwargs)
response = await _client.get(**kwargs)
return _build_response(response=response)
async def asyncio(
body: ModelingCmdReqBatch,
id: str,
*,
client: Client,
) -> Optional[Union[ModelingOutcomes, Error]]:
) -> Optional[Union[TextToCad, Error]]:
"""This endpoint requires authentication by any KittyCAD user. The user must be the owner of the text-to-CAD model.""" # noqa: E501
return (
await asyncio_detailed(
body=body,
id=id,
client=client,
)
).parsed

View File

@ -0,0 +1,159 @@
from typing import Any, Dict, Optional, Union
import httpx
from ...client import Client
from ...models.ai_prompt_results_page import AiPromptResultsPage
from ...models.created_at_sort_mode import CreatedAtSortMode
from ...models.error import Error
from ...types import Response
def _get_kwargs(
sort_by: CreatedAtSortMode,
*,
client: Client,
limit: Optional[int] = None,
page_token: Optional[str] = None,
) -> Dict[str, Any]:
url = "{}/ai-prompts".format(
client.base_url,
) # noqa: E501
if limit is not None:
if "?" in url:
url = url + "&limit=" + str(limit)
else:
url = url + "?limit=" + str(limit)
if page_token is not None:
if "?" in url:
url = url + "&page_token=" + str(page_token)
else:
url = url + "?page_token=" + str(page_token)
if sort_by is not None:
if "?" in url:
url = url + "&sort_by=" + str(sort_by)
else:
url = url + "?sort_by=" + str(sort_by)
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()
return {
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
}
def _parse_response(
*, response: httpx.Response
) -> Optional[Union[AiPromptResultsPage, Error]]:
if response.status_code == 200:
response_200 = AiPromptResultsPage(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error(**response.json())
return response_5XX
return Error(**response.json())
def _build_response(
*, response: httpx.Response
) -> Response[Optional[Union[AiPromptResultsPage, Error]]]:
return Response(
status_code=response.status_code,
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
)
def sync_detailed(
sort_by: CreatedAtSortMode,
*,
client: Client,
limit: Optional[int] = None,
page_token: Optional[str] = None,
) -> Response[Optional[Union[AiPromptResultsPage, Error]]]:
kwargs = _get_kwargs(
limit=limit,
page_token=page_token,
sort_by=sort_by,
client=client,
)
response = httpx.get(
verify=client.verify_ssl,
**kwargs,
)
return _build_response(response=response)
def sync(
sort_by: CreatedAtSortMode,
*,
client: Client,
limit: Optional[int] = None,
page_token: Optional[str] = None,
) -> Optional[Union[AiPromptResultsPage, Error]]:
"""For text-to-cad prompts, this will always return the STEP file contents as well as the format the user originally requested.
This endpoint requires authentication by a KittyCAD employee.
The AI prompts are returned in order of creation, with the most recently created AI prompts first.
""" # noqa: E501
return sync_detailed(
limit=limit,
page_token=page_token,
sort_by=sort_by,
client=client,
).parsed
async def asyncio_detailed(
sort_by: CreatedAtSortMode,
*,
client: Client,
limit: Optional[int] = None,
page_token: Optional[str] = None,
) -> Response[Optional[Union[AiPromptResultsPage, Error]]]:
kwargs = _get_kwargs(
limit=limit,
page_token=page_token,
sort_by=sort_by,
client=client,
)
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
response = await _client.get(**kwargs)
return _build_response(response=response)
async def asyncio(
sort_by: CreatedAtSortMode,
*,
client: Client,
limit: Optional[int] = None,
page_token: Optional[str] = None,
) -> Optional[Union[AiPromptResultsPage, Error]]:
"""For text-to-cad prompts, this will always return the STEP file contents as well as the format the user originally requested.
This endpoint requires authentication by a KittyCAD employee.
The AI prompts are returned in order of creation, with the most recently created AI prompts first.
""" # noqa: E501
return (
await asyncio_detailed(
limit=limit,
page_token=page_token,
sort_by=sort_by,
client=client,
)
).parsed

View File

@ -0,0 +1,159 @@
from typing import Any, Dict, Optional, Union
import httpx
from ...client import Client
from ...models.created_at_sort_mode import CreatedAtSortMode
from ...models.error import Error
from ...models.text_to_cad_results_page import TextToCadResultsPage
from ...types import Response
def _get_kwargs(
sort_by: CreatedAtSortMode,
*,
client: Client,
limit: Optional[int] = None,
page_token: Optional[str] = None,
) -> Dict[str, Any]:
url = "{}/user/text-to-cad".format(
client.base_url,
) # noqa: E501
if limit is not None:
if "?" in url:
url = url + "&limit=" + str(limit)
else:
url = url + "?limit=" + str(limit)
if page_token is not None:
if "?" in url:
url = url + "&page_token=" + str(page_token)
else:
url = url + "?page_token=" + str(page_token)
if sort_by is not None:
if "?" in url:
url = url + "&sort_by=" + str(sort_by)
else:
url = url + "?sort_by=" + str(sort_by)
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()
return {
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
}
def _parse_response(
*, response: httpx.Response
) -> Optional[Union[TextToCadResultsPage, Error]]:
if response.status_code == 200:
response_200 = TextToCadResultsPage(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error(**response.json())
return response_5XX
return Error(**response.json())
def _build_response(
*, response: httpx.Response
) -> Response[Optional[Union[TextToCadResultsPage, Error]]]:
return Response(
status_code=response.status_code,
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
)
def sync_detailed(
sort_by: CreatedAtSortMode,
*,
client: Client,
limit: Optional[int] = None,
page_token: Optional[str] = None,
) -> Response[Optional[Union[TextToCadResultsPage, Error]]]:
kwargs = _get_kwargs(
limit=limit,
page_token=page_token,
sort_by=sort_by,
client=client,
)
response = httpx.get(
verify=client.verify_ssl,
**kwargs,
)
return _build_response(response=response)
def sync(
sort_by: CreatedAtSortMode,
*,
client: Client,
limit: Optional[int] = None,
page_token: Optional[str] = None,
) -> Optional[Union[TextToCadResultsPage, Error]]:
"""This will always return the STEP file contents as well as the format the user originally requested.
This endpoint requires authentication by any KittyCAD user. It returns the text-to-CAD models for the authenticated user.
The text-to-CAD models are returned in order of creation, with the most recently created text-to-CAD models first.
""" # noqa: E501
return sync_detailed(
limit=limit,
page_token=page_token,
sort_by=sort_by,
client=client,
).parsed
async def asyncio_detailed(
sort_by: CreatedAtSortMode,
*,
client: Client,
limit: Optional[int] = None,
page_token: Optional[str] = None,
) -> Response[Optional[Union[TextToCadResultsPage, Error]]]:
kwargs = _get_kwargs(
limit=limit,
page_token=page_token,
sort_by=sort_by,
client=client,
)
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
response = await _client.get(**kwargs)
return _build_response(response=response)
async def asyncio(
sort_by: CreatedAtSortMode,
*,
client: Client,
limit: Optional[int] = None,
page_token: Optional[str] = None,
) -> Optional[Union[TextToCadResultsPage, Error]]:
"""This will always return the STEP file contents as well as the format the user originally requested.
This endpoint requires authentication by any KittyCAD user. It returns the text-to-CAD models for the authenticated user.
The text-to-CAD models are returned in order of creation, with the most recently created text-to-CAD models first.
""" # noqa: E501
return (
await asyncio_detailed(
limit=limit,
page_token=page_token,
sort_by=sort_by,
client=client,
)
).parsed

View File

@ -33,15 +33,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[ApiCallWithPrice, Error]]:
if response.status_code == 200:
response_200 = ApiCallWithPrice.from_dict(response.json())
response_200 = ApiCallWithPrice(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -33,15 +33,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[ApiCallWithPrice, Error]]:
if response.status_code == 200:
response_200 = ApiCallWithPrice.from_dict(response.json())
response_200 = ApiCallWithPrice(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -39,15 +39,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[List[ApiCallQueryGroup], Error]]:
if response.status_code == 200:
response_200 = [ApiCallQueryGroup.from_dict(item) for item in response.json()]
response_200 = [ApiCallQueryGroup(**item) for item in response.json()]
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -10,6 +10,7 @@ from ...models.file_density import FileDensity
from ...models.file_mass import FileMass
from ...models.file_surface_area import FileSurfaceArea
from ...models.file_volume import FileVolume
from ...models.text_to_cad import TextToCad
from ...types import Response
@ -44,6 +45,7 @@ def _parse_response(
FileVolume,
FileDensity,
FileSurfaceArea,
TextToCad,
Error,
]
]:
@ -52,7 +54,7 @@ def _parse_response(
try:
if not isinstance(data, dict):
raise TypeError()
option_file_conversion = FileConversion.from_dict(data)
option_file_conversion = FileConversion(**data)
return option_file_conversion
except ValueError:
pass
@ -61,7 +63,7 @@ def _parse_response(
try:
if not isinstance(data, dict):
raise TypeError()
option_file_center_of_mass = FileCenterOfMass.from_dict(data)
option_file_center_of_mass = FileCenterOfMass(**data)
return option_file_center_of_mass
except ValueError:
pass
@ -70,7 +72,7 @@ def _parse_response(
try:
if not isinstance(data, dict):
raise TypeError()
option_file_mass = FileMass.from_dict(data)
option_file_mass = FileMass(**data)
return option_file_mass
except ValueError:
pass
@ -79,7 +81,7 @@ def _parse_response(
try:
if not isinstance(data, dict):
raise TypeError()
option_file_volume = FileVolume.from_dict(data)
option_file_volume = FileVolume(**data)
return option_file_volume
except ValueError:
pass
@ -88,7 +90,7 @@ def _parse_response(
try:
if not isinstance(data, dict):
raise TypeError()
option_file_density = FileDensity.from_dict(data)
option_file_density = FileDensity(**data)
return option_file_density
except ValueError:
pass
@ -97,19 +99,28 @@ def _parse_response(
try:
if not isinstance(data, dict):
raise TypeError()
option_file_surface_area = FileSurfaceArea.from_dict(data)
option_file_surface_area = FileSurfaceArea(**data)
return option_file_surface_area
except ValueError:
pass
except TypeError:
pass
try:
if not isinstance(data, dict):
raise TypeError()
option_text_to_cad = TextToCad(**data)
return option_text_to_cad
except ValueError:
raise
except TypeError:
raise
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(
@ -123,6 +134,7 @@ def _build_response(
FileVolume,
FileDensity,
FileSurfaceArea,
TextToCad,
Error,
]
]
@ -148,6 +160,7 @@ def sync_detailed(
FileVolume,
FileDensity,
FileSurfaceArea,
TextToCad,
Error,
]
]
@ -177,6 +190,7 @@ def sync(
FileVolume,
FileDensity,
FileSurfaceArea,
TextToCad,
Error,
]
]:
@ -205,6 +219,7 @@ async def asyncio_detailed(
FileVolume,
FileDensity,
FileSurfaceArea,
TextToCad,
Error,
]
]
@ -232,6 +247,7 @@ async def asyncio(
FileVolume,
FileDensity,
FileSurfaceArea,
TextToCad,
Error,
]
]:

View File

@ -53,15 +53,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[ApiCallWithPriceResultsPage, Error]]:
if response.status_code == 200:
response_200 = ApiCallWithPriceResultsPage.from_dict(response.json())
response_200 = ApiCallWithPriceResultsPage(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -55,15 +55,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[ApiCallWithPriceResultsPage, Error]]:
if response.status_code == 200:
response_200 = ApiCallWithPriceResultsPage.from_dict(response.json())
response_200 = ApiCallWithPriceResultsPage(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -61,15 +61,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[AsyncApiCallResultsPage, Error]]:
if response.status_code == 200:
response_200 = AsyncApiCallResultsPage.from_dict(response.json())
response_200 = AsyncApiCallResultsPage(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -53,15 +53,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[ApiCallWithPriceResultsPage, Error]]:
if response.status_code == 200:
response_200 = ApiCallWithPriceResultsPage.from_dict(response.json())
response_200 = ApiCallWithPriceResultsPage(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -29,15 +29,15 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Union[ApiToken, Error]]:
if response.status_code == 201:
response_201 = ApiToken.from_dict(response.json())
response_201 = ApiToken(**response.json())
return response_201
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -31,12 +31,12 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Error]:
return None
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(*, response: httpx.Response) -> Response[Optional[Error]]:

View File

@ -31,15 +31,15 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Union[ApiToken, Error]]:
if response.status_code == 200:
response_200 = ApiToken.from_dict(response.json())
response_200 = ApiToken(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -53,15 +53,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[ApiTokenResultsPage, Error]]:
if response.status_code == 200:
response_200 = ApiTokenResultsPage.from_dict(response.json())
response_200 = ApiTokenResultsPage(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -29,12 +29,12 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Error]:
return None
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(*, response: httpx.Response) -> Response[Optional[Error]]:

View File

@ -31,15 +31,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[AppClientInfo, Error]]:
if response.status_code == 200:
response_200 = AppClientInfo.from_dict(response.json())
response_200 = AppClientInfo(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -31,12 +31,12 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Error]:
return None
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(*, response: httpx.Response) -> Response[Optional[Error]]:

View File

@ -4,7 +4,6 @@ from websockets.client import WebSocketClientProtocol, connect as ws_connect_asy
from websockets.sync.client import ClientConnection, connect as ws_connect
from ...client import Client
from ...models.error import Error
def _get_kwargs(
@ -34,14 +33,7 @@ def sync(
client=client,
)
with ws_connect(
kwargs["url"].replace("https://", "wss://"),
additional_headers=kwargs["headers"],
) as websocket:
return websocket # type: ignore
# Return an error if we got here.
return Error(message="An error occurred while connecting to the websocket.")
return ws_connect(kwargs["url"].replace("http", "ws"), additional_headers=kwargs["headers"], close_timeout=120, max_size=None) # type: ignore
async def asyncio(
@ -54,10 +46,9 @@ async def asyncio(
client=client,
)
async with ws_connect_async(
kwargs["url"].replace("https://", "wss://"), extra_headers=kwargs["headers"]
) as websocket:
return websocket
# Return an error if we got here.
return Error(message="An error occurred while connecting to the websocket.")
return await ws_connect_async(
kwargs["url"].replace("http", "ws"),
extra_headers=kwargs["headers"],
close_timeout=120,
max_size=None,
)

View File

@ -41,15 +41,15 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Union[CodeOutput, Error]]:
if response.status_code == 200:
response_200 = CodeOutput.from_dict(response.json())
response_200 = CodeOutput(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -49,15 +49,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[FileCenterOfMass, Error]]:
if response.status_code == 201:
response_201 = FileCenterOfMass.from_dict(response.json())
response_201 = FileCenterOfMass(**response.json())
return response_201
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(
@ -101,7 +101,7 @@ def sync(
client: Client,
) -> Optional[Union[FileCenterOfMass, Error]]:
"""We assume any file given to us has one consistent unit throughout. We also assume the file is at the proper scale.
This endpoint returns the cartesian co-ordinate in world space measure units.
This endpoint returns the cartesian coordinate in world space measure units.
In the future, we will use the units inside the file if they are given and do any conversions if necessary for the calculation. But currently, that is not supported.
Get the center of mass of an object in a CAD file. If the file is larger than 25MB, it will be performed asynchronously.
If the operation is performed asynchronously, the `id` of the operation will be returned. You can use the `id` returned from the request to get status information about the async operation from the `/async/operations/{id}` endpoint.
@ -143,7 +143,7 @@ async def asyncio(
client: Client,
) -> Optional[Union[FileCenterOfMass, Error]]:
"""We assume any file given to us has one consistent unit throughout. We also assume the file is at the proper scale.
This endpoint returns the cartesian co-ordinate in world space measure units.
This endpoint returns the cartesian coordinate in world space measure units.
In the future, we will use the units inside the file if they are given and do any conversions if necessary for the calculation. But currently, that is not supported.
Get the center of mass of an object in a CAD file. If the file is larger than 25MB, it will be performed asynchronously.
If the operation is performed asynchronously, the `id` of the operation will be returned. You can use the `id` returned from the request to get status information about the async operation from the `/async/operations/{id}` endpoint.

View File

@ -39,15 +39,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[FileConversion, Error]]:
if response.status_code == 201:
response_201 = FileConversion.from_dict(response.json())
response_201 = FileConversion(**response.json())
return response_201
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -1,58 +0,0 @@
import base64
from typing import Any, Optional, Tuple, Union
from ...api.file.create_file_conversion import asyncio as fc_asyncio, sync as fc_sync
from ...client import Client
from ...models import Error, FileConversion, FileExportFormat, FileImportFormat
def sync(
src_format: FileImportFormat,
output_format: FileExportFormat,
body: bytes,
*,
client: Client,
) -> Optional[Union[Any, Tuple[FileConversion, bytes], Error]]:
"""Convert a CAD file from one format to another. If the file being converted is larger than a certain size it will be performed asynchronously. This function automatically base64 encodes the request body and base64 decodes the request output."""
encoded = base64.b64encode(body)
fc = fc_sync(
src_format=src_format,
output_format=output_format,
body=encoded,
client=client,
)
if isinstance(fc, FileConversion) and fc.output != "":
if isinstance(fc.output, str):
b = base64.b64decode(fc.output + "===")
return (fc, b)
return fc
async def asyncio(
src_format: FileImportFormat,
output_format: FileExportFormat,
body: bytes,
*,
client: Client,
) -> Optional[Union[Any, Tuple[FileConversion, bytes], Error]]:
"""Convert a CAD file from one format to another. If the file being converted is larger than a certain size it will be performed asynchronously. This function automatically base64 encodes the request body and base64 decodes the request output."""
encoded = base64.b64encode(body)
fc = await fc_asyncio(
src_format=src_format,
output_format=output_format,
body=encoded,
client=client,
)
if isinstance(fc, FileConversion) and fc.output != "":
if isinstance(fc.output, str):
b = base64.b64decode(fc.output + "===")
return (fc, b)
return fc

View File

@ -62,15 +62,15 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Union[FileDensity, Error]]:
if response.status_code == 201:
response_201 = FileDensity.from_dict(response.json())
response_201 = FileDensity(**response.json())
return response_201
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -62,15 +62,15 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Union[FileMass, Error]]:
if response.status_code == 201:
response_201 = FileMass.from_dict(response.json())
response_201 = FileMass(**response.json())
return response_201
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -49,15 +49,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[FileSurfaceArea, Error]]:
if response.status_code == 201:
response_201 = FileSurfaceArea.from_dict(response.json())
response_201 = FileSurfaceArea(**response.json())
return response_201
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -47,15 +47,15 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Union[FileVolume, Error]]:
if response.status_code == 201:
response_201 = FileVolume.from_dict(response.json())
response_201 = FileVolume(**response.json())
return response_201
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -1,47 +0,0 @@
import base64
from typing import Any, Optional, Tuple, Union
from ...api.api_calls.get_async_operation import asyncio as fc_asyncio, sync as fc_sync
from ...client import Client
from ...models import Error
from ...models.file_conversion import FileConversion
def sync(
id: str,
*,
client: Client,
) -> Optional[Union[Any, Tuple[FileConversion, bytes], Error]]:
"""Get the status of a file conversion. This function automatically base64 decodes the output response if there is one."""
fc = fc_sync(
id=id,
client=client,
)
if isinstance(fc, FileConversion) and fc.output != "":
if isinstance(fc.output, str):
b = base64.b64decode(fc.output + "===")
return (fc, b)
return fc
async def asyncio(
id: str,
*,
client: Client,
) -> Optional[Union[Any, Tuple[FileConversion, bytes], Error]]:
"""Get the status of a file conversion. This function automatically base64 decodes the output response if there is one."""
fc = await fc_asyncio(
id=id,
client=client,
)
if isinstance(fc, FileConversion) and fc.output != "":
if isinstance(fc.output, str):
b = base64.b64decode(fc.output + "===")
return (fc, b)
return fc

View File

@ -34,15 +34,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[VerificationToken, Error]]:
if response.status_code == 201:
response_201 = VerificationToken.from_dict(response.json())
response_201 = VerificationToken(**response.json())
return response_201
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -50,12 +50,12 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Error]:
return None
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(*, response: httpx.Response) -> Response[Optional[Error]]:

View File

@ -29,12 +29,12 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Error]:
return None
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(*, response: httpx.Response) -> Response[Optional[Error]]:

View File

@ -31,15 +31,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[AiPluginManifest, Error]]:
if response.status_code == 200:
response_200 = AiPluginManifest.from_dict(response.json())
response_200 = AiPluginManifest(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -29,15 +29,15 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Union[Metadata, Error]]:
if response.status_code == 200:
response_200 = Metadata.from_dict(response.json())
response_200 = Metadata(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -31,12 +31,12 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[dict, Error]]
response_200 = response.json()
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -31,12 +31,12 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[dict, Error]]
response_200 = response.json()
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -0,0 +1,117 @@
from typing import Any, Dict, Optional, Union
import httpx
from ...client import Client
from ...models.api_token import ApiToken
from ...models.error import Error
from ...types import Response
def _get_kwargs(
discord_id: str,
*,
client: Client,
) -> Dict[str, Any]:
url = "{}/internal/discord/api-token/{discord_id}".format(
client.base_url,
discord_id=discord_id,
) # noqa: E501
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()
return {
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
}
def _parse_response(*, response: httpx.Response) -> Optional[Union[ApiToken, Error]]:
if response.status_code == 200:
response_200 = ApiToken(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error(**response.json())
return response_5XX
return Error(**response.json())
def _build_response(
*, response: httpx.Response
) -> Response[Optional[Union[ApiToken, Error]]]:
return Response(
status_code=response.status_code,
content=response.content,
headers=response.headers,
parsed=_parse_response(response=response),
)
def sync_detailed(
discord_id: str,
*,
client: Client,
) -> Response[Optional[Union[ApiToken, Error]]]:
kwargs = _get_kwargs(
discord_id=discord_id,
client=client,
)
response = httpx.get(
verify=client.verify_ssl,
**kwargs,
)
return _build_response(response=response)
def sync(
discord_id: str,
*,
client: Client,
) -> Optional[Union[ApiToken, Error]]:
"""This endpoint allows us to run API calls from our discord bot on behalf of a user. The user must have a discord account linked to their KittyCAD Account via oauth2 for this to work.
You must be a KittyCAD employee to use this endpoint.""" # noqa: E501
return sync_detailed(
discord_id=discord_id,
client=client,
).parsed
async def asyncio_detailed(
discord_id: str,
*,
client: Client,
) -> Response[Optional[Union[ApiToken, Error]]]:
kwargs = _get_kwargs(
discord_id=discord_id,
client=client,
)
async with httpx.AsyncClient(verify=client.verify_ssl) as _client:
response = await _client.get(**kwargs)
return _build_response(response=response)
async def asyncio(
discord_id: str,
*,
client: Client,
) -> Optional[Union[ApiToken, Error]]:
"""This endpoint allows us to run API calls from our discord bot on behalf of a user. The user must have a discord account linked to their KittyCAD Account via oauth2 for this to work.
You must be a KittyCAD employee to use this endpoint.""" # noqa: E501
return (
await asyncio_detailed(
discord_id=discord_id,
client=client,
)
).parsed

View File

@ -29,15 +29,15 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Union[Pong, Error]]:
if response.status_code == 200:
response_200 = Pong.from_dict(response.json())
response_200 = Pong(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -1,10 +1,13 @@
from typing import Any, Dict
import json
from typing import Any, Dict, Iterator
import bson
from websockets.client import WebSocketClientProtocol, connect as ws_connect_async
from websockets.sync.client import ClientConnection, connect as ws_connect
from ...client import Client
from ...models.error import Error
from ...models.web_socket_request import WebSocketRequest
from ...models.web_socket_response import WebSocketResponse
def _get_kwargs(
@ -12,6 +15,7 @@ def _get_kwargs(
unlocked_framerate: bool,
video_res_height: int,
video_res_width: int,
webrtc: bool,
*,
client: Client,
) -> Dict[str, Any]:
@ -25,9 +29,9 @@ def _get_kwargs(
if unlocked_framerate is not None:
if "?" in url:
url = url + "&unlocked_framerate=" + str(unlocked_framerate)
url = url + "&unlocked_framerate=" + str(unlocked_framerate).lower()
else:
url = url + "?unlocked_framerate=" + str(unlocked_framerate)
url = url + "?unlocked_framerate=" + str(unlocked_framerate).lower()
if video_res_height is not None:
if "?" in url:
@ -41,6 +45,12 @@ def _get_kwargs(
else:
url = url + "?video_res_width=" + str(video_res_width)
if webrtc is not None:
if "?" in url:
url = url + "&webrtc=" + str(webrtc).lower()
else:
url = url + "?webrtc=" + str(webrtc).lower()
headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()
@ -57,6 +67,7 @@ def sync(
unlocked_framerate: bool,
video_res_height: int,
video_res_width: int,
webrtc: bool,
*,
client: Client,
) -> ClientConnection:
@ -67,17 +78,11 @@ def sync(
unlocked_framerate=unlocked_framerate,
video_res_height=video_res_height,
video_res_width=video_res_width,
webrtc=webrtc,
client=client,
)
with ws_connect(
kwargs["url"].replace("https://", "wss://"),
additional_headers=kwargs["headers"],
) as websocket:
return websocket # type: ignore
# Return an error if we got here.
return Error(message="An error occurred while connecting to the websocket.")
return ws_connect(kwargs["url"].replace("http", "ws"), additional_headers=kwargs["headers"], close_timeout=120, max_size=None) # type: ignore
async def asyncio(
@ -85,6 +90,7 @@ async def asyncio(
unlocked_framerate: bool,
video_res_height: int,
video_res_width: int,
webrtc: bool,
*,
client: Client,
) -> WebSocketClientProtocol:
@ -95,13 +101,76 @@ async def asyncio(
unlocked_framerate=unlocked_framerate,
video_res_height=video_res_height,
video_res_width=video_res_width,
webrtc=webrtc,
client=client,
)
async with ws_connect_async(
kwargs["url"].replace("https://", "wss://"), extra_headers=kwargs["headers"]
) as websocket:
return websocket
return await ws_connect_async(
kwargs["url"].replace("http", "ws"),
extra_headers=kwargs["headers"],
close_timeout=120,
max_size=None,
)
# Return an error if we got here.
return Error(message="An error occurred while connecting to the websocket.")
class WebSocket:
"""A websocket connection to the API endpoint."""
ws: ClientConnection
def __init__(
self,
fps: int,
unlocked_framerate: bool,
video_res_height: int,
video_res_width: int,
webrtc: bool,
client: Client,
):
self.ws = sync(
fps,
unlocked_framerate,
video_res_height,
video_res_width,
webrtc,
client=client,
)
def __enter__(
self,
):
return self
def __exit__(self, exc_type, exc_value, traceback):
self.close()
def __iter__(self) -> Iterator[WebSocketResponse]:
"""
Iterate on incoming messages.
The iterator calls :meth:`recv` and yields messages in an infinite loop.
It exits when the connection is closed normally. It raises a
:exc:`~websockets.exceptions.ConnectionClosedError` exception after a
protocol error or a network failure.
"""
for message in self.ws:
yield WebSocketResponse(**json.loads(message))
def send(self, data: WebSocketRequest):
"""Send data to the websocket."""
self.ws.send(json.dumps(data.model_dump()))
def send_binary(self, data: WebSocketRequest):
"""Send data as bson to the websocket."""
self.ws.send(bson.encode(data.model_dump())) # type: ignore
def recv(self) -> WebSocketResponse:
"""Receive data from the websocket."""
message = self.ws.recv(timeout=60)
return WebSocketResponse(**json.loads(message))
def close(self):
"""Close the websocket."""
self.ws.close()

View File

@ -32,15 +32,15 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Union[Customer, Error]]:
if response.status_code == 201:
response_201 = Customer.from_dict(response.json())
response_201 = Customer(**response.json())
return response_201
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -31,15 +31,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[PaymentIntent, Error]]:
if response.status_code == 201:
response_201 = PaymentIntent.from_dict(response.json())
response_201 = PaymentIntent(**response.json())
return response_201
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -29,12 +29,12 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Error]:
return None
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(*, response: httpx.Response) -> Response[Optional[Error]]:

View File

@ -31,12 +31,12 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Error]:
return None
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(*, response: httpx.Response) -> Response[Optional[Error]]:

View File

@ -31,15 +31,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[CustomerBalance, Error]]:
if response.status_code == 200:
response_200 = CustomerBalance.from_dict(response.json())
response_200 = CustomerBalance(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -29,15 +29,15 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Union[Customer, Error]]:
if response.status_code == 200:
response_200 = Customer.from_dict(response.json())
response_200 = Customer(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -31,15 +31,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[List[Invoice], Error]]:
if response.status_code == 200:
response_200 = [Invoice.from_dict(item) for item in response.json()]
response_200 = [Invoice(**item) for item in response.json()]
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -31,15 +31,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[List[PaymentMethod], Error]]:
if response.status_code == 200:
response_200 = [PaymentMethod.from_dict(item) for item in response.json()]
response_200 = [PaymentMethod(**item) for item in response.json()]
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -32,15 +32,15 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Union[Customer, Error]]:
if response.status_code == 200:
response_200 = Customer.from_dict(response.json())
response_200 = Customer(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -29,12 +29,12 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Error]:
return None
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(*, response: httpx.Response) -> Response[Optional[Error]]:

View File

@ -43,15 +43,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[UnitAngleConversion, Error]]:
if response.status_code == 200:
response_200 = UnitAngleConversion.from_dict(response.json())
response_200 = UnitAngleConversion(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -43,15 +43,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[UnitAreaConversion, Error]]:
if response.status_code == 200:
response_200 = UnitAreaConversion.from_dict(response.json())
response_200 = UnitAreaConversion(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -43,15 +43,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[UnitCurrentConversion, Error]]:
if response.status_code == 200:
response_200 = UnitCurrentConversion.from_dict(response.json())
response_200 = UnitCurrentConversion(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -43,15 +43,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[UnitEnergyConversion, Error]]:
if response.status_code == 200:
response_200 = UnitEnergyConversion.from_dict(response.json())
response_200 = UnitEnergyConversion(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -43,15 +43,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[UnitForceConversion, Error]]:
if response.status_code == 200:
response_200 = UnitForceConversion.from_dict(response.json())
response_200 = UnitForceConversion(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -43,15 +43,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[UnitFrequencyConversion, Error]]:
if response.status_code == 200:
response_200 = UnitFrequencyConversion.from_dict(response.json())
response_200 = UnitFrequencyConversion(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -43,15 +43,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[UnitLengthConversion, Error]]:
if response.status_code == 200:
response_200 = UnitLengthConversion.from_dict(response.json())
response_200 = UnitLengthConversion(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -43,15 +43,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[UnitMassConversion, Error]]:
if response.status_code == 200:
response_200 = UnitMassConversion.from_dict(response.json())
response_200 = UnitMassConversion(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -43,15 +43,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[UnitPowerConversion, Error]]:
if response.status_code == 200:
response_200 = UnitPowerConversion.from_dict(response.json())
response_200 = UnitPowerConversion(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -43,15 +43,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[UnitPressureConversion, Error]]:
if response.status_code == 200:
response_200 = UnitPressureConversion.from_dict(response.json())
response_200 = UnitPressureConversion(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -43,15 +43,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[UnitTemperatureConversion, Error]]:
if response.status_code == 200:
response_200 = UnitTemperatureConversion.from_dict(response.json())
response_200 = UnitTemperatureConversion(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -43,15 +43,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[UnitTorqueConversion, Error]]:
if response.status_code == 200:
response_200 = UnitTorqueConversion.from_dict(response.json())
response_200 = UnitTorqueConversion(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -43,15 +43,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[UnitVolumeConversion, Error]]:
if response.status_code == 200:
response_200 = UnitVolumeConversion.from_dict(response.json())
response_200 = UnitVolumeConversion(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -29,12 +29,12 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Error]:
return None
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(*, response: httpx.Response) -> Response[Optional[Error]]:

View File

@ -31,15 +31,15 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Union[Session, Error]]:
if response.status_code == 200:
response_200 = Session.from_dict(response.json())
response_200 = Session(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -31,15 +31,15 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Union[User, Error]]:
if response.status_code == 200:
response_200 = User.from_dict(response.json())
response_200 = User(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -33,15 +33,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[ExtendedUser, Error]]:
if response.status_code == 200:
response_200 = ExtendedUser.from_dict(response.json())
response_200 = ExtendedUser(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -31,12 +31,12 @@ def _parse_response(*, response: httpx.Response) -> Optional[Union[str, Error]]:
response_200 = response.text
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -29,15 +29,15 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Union[Onboarding, Error]]:
if response.status_code == 200:
response_200 = Onboarding.from_dict(response.json())
response_200 = Onboarding(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -29,15 +29,15 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Union[User, Error]]:
if response.status_code == 200:
response_200 = User.from_dict(response.json())
response_200 = User(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -31,15 +31,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[ExtendedUser, Error]]:
if response.status_code == 200:
response_200 = ExtendedUser.from_dict(response.json())
response_200 = ExtendedUser(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -53,15 +53,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[UserResultsPage, Error]]:
if response.status_code == 200:
response_200 = UserResultsPage.from_dict(response.json())
response_200 = UserResultsPage(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -53,15 +53,15 @@ def _parse_response(
*, response: httpx.Response
) -> Optional[Union[ExtendedUserResultsPage, Error]]:
if response.status_code == 200:
response_200 = ExtendedUserResultsPage.from_dict(response.json())
response_200 = ExtendedUserResultsPage(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -32,15 +32,15 @@ def _get_kwargs(
def _parse_response(*, response: httpx.Response) -> Optional[Union[User, Error]]:
if response.status_code == 200:
response_200 = User.from_dict(response.json())
response_200 = User(**response.json())
return response_200
if response.status_code == 400:
response_4XX = Error.from_dict(response.json())
response_4XX = Error(**response.json())
return response_4XX
if response.status_code == 500:
response_5XX = Error.from_dict(response.json())
response_5XX = Error(**response.json())
return response_5XX
return Error.from_dict(response.json())
return Error(**response.json())
def _build_response(

View File

@ -38,6 +38,10 @@ class Client:
"""Get a new client matching this one with a new timeout (in seconds)"""
return attr.evolve(self, timeout=timeout)
def with_base_url(self, url: str) -> "Client":
"""Get a new client matching this one with a new base url"""
return attr.evolve(self, base_url=url)
@attr.s(auto_attribs=True)
class ClientFromEnv(Client):

View File

@ -1,21 +1,23 @@
import json
import os
from typing import Tuple, Union
import uuid
from typing import Optional, Union
import pytest
from .api.api_tokens import list_api_tokens_for_user
from .api.file import (
create_file_conversion_with_base64_helper,
create_file_mass,
create_file_volume,
)
from .api.file import create_file_conversion, create_file_mass, create_file_volume
from .api.meta import ping
from .api.modeling import modeling_commands_ws
from .api.users import get_user_self, list_users_extended
from .client import ClientFromEnv
from .models import (
ApiCallStatus,
ApiTokenResultsPage,
Axis,
AxisDirectionPair,
CreatedAtSortMode,
Direction,
Error,
ExtendedUserResultsPage,
FileConversion,
@ -23,12 +25,30 @@ from .models import (
FileImportFormat,
FileMass,
FileVolume,
ImageFormat,
ImportFile,
InputFormat,
ModelingCmd,
ModelingCmdId,
Pong,
System,
UnitDensity,
UnitLength,
UnitMass,
UnitVolume,
User,
WebSocketRequest,
WebSocketResponse,
)
from .models.input_format import obj
from .models.modeling_cmd import (
default_camera_focus_on,
import_files,
start_path,
take_snapshot,
)
from .models.web_socket_request import modeling_cmd_req
from .types import Unset
def test_get_session():
@ -106,19 +126,16 @@ def test_file_convert_stl():
file.close()
# Get the fc.
result: Union[
Tuple[FileConversion, bytes], Error, None
] = create_file_conversion_with_base64_helper.sync(
result: Optional[Union[FileConversion, Error]] = create_file_conversion.sync(
client=client,
body=content,
src_format=FileImportFormat.STL,
output_format=FileExportFormat.OBJ,
)
r: Tuple[FileConversion, bytes] = result # type: ignore
assert isinstance(result, FileConversion)
b: bytes = r[1]
fc: FileConversion = r[0]
fc: FileConversion = result
print(f"FileConversion: {fc}")
@ -127,8 +144,12 @@ def test_file_convert_stl():
print(f"FileConversion: {fc}")
assert not isinstance(fc.outputs, Unset)
assert fc.outputs is not None
# Make sure the bytes are not empty.
assert len(b) > 0
for key, value in fc.outputs.items():
assert len(value.get_decoded()) > 0
@pytest.mark.asyncio
@ -142,19 +163,18 @@ async def test_file_convert_stl_async():
file.close()
# Get the fc.
result: Union[
Tuple[FileConversion, bytes], Error, None
] = await create_file_conversion_with_base64_helper.asyncio(
result: Optional[
Union[FileConversion, Error]
] = await create_file_conversion.asyncio(
client=client,
body=content,
src_format=FileImportFormat.STL,
output_format=FileExportFormat.OBJ,
)
r: Tuple[FileConversion, bytes] = result # type: ignore
assert isinstance(result, FileConversion)
b: bytes = r[1]
fc: FileConversion = r[0]
fc: FileConversion = result
print(f"FileConversion: {fc}")
@ -163,8 +183,51 @@ async def test_file_convert_stl_async():
print(f"FileConversion: {fc}")
assert not isinstance(fc.outputs, Unset)
assert fc.outputs is not None
# Make sure the bytes are not empty.
assert len(b) > 0
for key, value in fc.outputs.items():
assert len(value.get_decoded()) > 0
@pytest.mark.asyncio
async def test_file_convert_obj_async():
# Create our client.
client = ClientFromEnv()
dir_path = os.path.dirname(os.path.realpath(__file__))
file = open(os.path.join(dir_path, "../assets/ORIGINALVOXEL-3.obj"), "rb")
content = file.read()
file.close()
# Get the fc.
result: Optional[
Union[FileConversion, Error]
] = await create_file_conversion.asyncio(
client=client,
body=content,
src_format=FileImportFormat.OBJ,
output_format=FileExportFormat.STL,
)
assert isinstance(result, FileConversion)
fc: FileConversion = result
print(f"FileConversion: {fc}")
assert fc.id is not None
assert fc.status == ApiCallStatus.COMPLETED
print(f"FileConversion: {fc}")
assert not isinstance(fc.outputs, Unset)
assert fc.outputs is not None
# Make sure the bytes are not empty.
for key, value in fc.outputs.items():
assert len(value.get_decoded()) > 0
def test_file_mass():
@ -195,7 +258,7 @@ def test_file_mass():
assert fm.id is not None
assert fm.mass is not None
assert fm.to_dict() is not None
assert fm.model_dump_json() is not None
assert fm.status == ApiCallStatus.COMPLETED
@ -226,7 +289,7 @@ def test_file_volume():
assert fv.id is not None
assert fv.volume is not None
assert fv.to_dict() is not None
assert fv.model_dump_json() is not None
assert fv.status == ApiCallStatus.COMPLETED
@ -242,3 +305,187 @@ def test_list_users():
assert isinstance(response, ExtendedUserResultsPage)
print(f"ExtendedUserResultsPage: {response}")
def test_ws_simple():
# Create our client.
client = ClientFromEnv()
# Connect to the websocket.
with modeling_commands_ws.WebSocket(
client=client,
fps=30,
unlocked_framerate=False,
video_res_height=360,
video_res_width=480,
webrtc=False,
) as websocket:
# Send a message.
id = uuid.uuid4()
req = WebSocketRequest(
modeling_cmd_req(cmd=ModelingCmd(start_path()), cmd_id=ModelingCmdId(id))
)
websocket.send(req)
# Get the messages.
while True:
message = websocket.recv()
print(json.dumps(message.model_dump_json()))
break
def test_ws_import():
# Create our client.
client = ClientFromEnv()
# Connect to the websocket.
with modeling_commands_ws.WebSocket(
client=client,
fps=30,
unlocked_framerate=False,
video_res_height=360,
video_res_width=480,
webrtc=False,
) as websocket:
# read the content of the file
dir_path = os.path.dirname(os.path.realpath(__file__))
file_name = "ORIGINALVOXEL-3.obj"
file = open(os.path.join(dir_path, "..", "assets", file_name), "rb")
content = file.read()
file.close()
cmd_id = uuid.uuid4()
ImportFile(data=content, path=file_name)
# form the request
req = WebSocketRequest(
modeling_cmd_req(
cmd=ModelingCmd(
import_files(
files=[ImportFile(data=content, path=file_name)],
format=InputFormat(
obj(
units=UnitLength.M,
coords=System(
forward=AxisDirectionPair(
axis=Axis.Y, direction=Direction.NEGATIVE
),
up=AxisDirectionPair(
axis=Axis.Z, direction=Direction.POSITIVE
),
),
)
),
)
),
cmd_id=ModelingCmdId(cmd_id),
)
)
# Import files request must be sent as binary, because the file contents might be binary.
websocket.send_binary(req)
# Get the success message.
object_id = ""
for message in websocket:
message_dict = message.model_dump()
if message_dict["success"] is not True:
raise Exception(message_dict)
elif message_dict["resp"]["type"] != "modeling":
continue
elif (
message_dict["resp"]["data"]["modeling_response"]["type"]
!= "import_files"
):
# We have a modeling command response.
# Make sure its the import files response.
raise Exception(message_dict)
else:
# Okay we have the import files response.
# Break since now we know it was a success.
object_id = str(
message_dict["resp"]["data"]["modeling_response"]["data"][
"object_id"
]
)
break
# Now we want to focus on the object.
cmd_id = uuid.uuid4()
# form the request
req = WebSocketRequest(
modeling_cmd_req(
cmd=ModelingCmd(default_camera_focus_on(uuid=object_id)),
cmd_id=ModelingCmdId(cmd_id),
)
)
websocket.send(req)
# Get the success message.
for message in websocket:
message_dict = message.model_dump()
if message_dict["success"] is not True:
raise Exception(message_dict)
elif message_dict["resp"]["type"] != "modeling":
continue
elif message_dict["request_id"] == str(cmd_id):
# We got a success response for our cmd.
break
else:
raise Exception(message_dict)
# Now we want to snapshot as a png.
cmd_id = uuid.uuid4()
# form the request
# form the request
req = WebSocketRequest(
modeling_cmd_req(
cmd=ModelingCmd(take_snapshot(format=ImageFormat.PNG)),
cmd_id=ModelingCmdId(cmd_id),
)
)
websocket.send(req)
# Get the success message.
png_contents = b""
for message in websocket:
message_dict = message.model_dump()
if message_dict["success"] is not True:
raise Exception(message_dict)
elif message_dict["resp"]["type"] != "modeling":
continue
elif (
message_dict["resp"]["data"]["modeling_response"]["type"]
!= "take_snapshot"
):
# Make sure its the correct response.
raise Exception(message_dict)
else:
# Okay we have the snapshot response.
# Break since now we know it was a success.
png_contents = message_dict["resp"]["data"]["modeling_response"][
"data"
]["contents"].get_decoded()
break
# Save the contents to a file.
png_path = os.path.join(dir_path, "..", "assets", "snapshot.png")
with open(png_path, "wb") as f:
f.write(png_contents)
# Ensure the file is not empty.
assert len(png_contents) > 0
# Ensure the file exists.
assert os.path.exists(png_path)
def test_serialize_deserialize():
json_str = """{"success":true,"request_id":"16a06065-6ca3-4a96-a042-d0bec6b161a6","resp":{"type":"modeling","data":{"modeling_response":{"type":"import_files","data":{"object_id":"f61ac02e-77bd-468f-858f-fd4141a26acd"}}}}}"""
d = json.loads(json_str)
print(d)
message = WebSocketResponse(**d)
model_dump = message.model_dump()
print(model_dump)
assert model_dump["success"] is True # type: ignore
assert model_dump["request_id"] == "16a06065-6ca3-4a96-a042-d0bec6b161a6" # type: ignore
assert model_dump["resp"]["type"] == "modeling" # type: ignore
assert model_dump["resp"]["data"]["modeling_response"]["type"] == "import_files" # type: ignore
assert model_dump["resp"]["data"]["modeling_response"]["data"]["object_id"] == "f61ac02e-77bd-468f-858f-fd4141a26acd" # type: ignore

File diff suppressed because it is too large Load Diff

Some files were not shown because too many files have changed in this diff Show More