@ -42,7 +42,10 @@ client = Client(token="$TOKEN")
|
|||||||
# - OR -
|
# - OR -
|
||||||
|
|
||||||
# Create a new client with your token parsed from the environment variable:
|
# Create a new client with your token parsed from the environment variable:
|
||||||
# `KITTYCAD_API_TOKEN`.
|
# `KITTYCAD_API_TOKEN` or `ZOO_API_TOKEN`.
|
||||||
|
# Optionally, you can pass in `ZOO_HOST` to specify the host. But this only
|
||||||
|
# needs to be done if you are using a different host than the default,
|
||||||
|
# which implies you are running your own instance of the API.
|
||||||
from kittycad.client import ClientFromEnv
|
from kittycad.client import ClientFromEnv
|
||||||
|
|
||||||
client = ClientFromEnv()
|
client = ClientFromEnv()
|
||||||
@ -50,7 +53,7 @@ client = ClientFromEnv()
|
|||||||
# NOTE: The python library additionally implements asyncio, however all the code samples we
|
# NOTE: The python library additionally implements asyncio, however all the code samples we
|
||||||
# show below use the sync functions for ease of use and understanding.
|
# show below use the sync functions for ease of use and understanding.
|
||||||
# Check out the library docs at:
|
# Check out the library docs at:
|
||||||
# https://python.api.docs.kittycad.io/_autosummary/kittycad.api.html#module-kittycad.api
|
# https://python.api.docs.zoo.dev/_autosummary/kittycad.api.html#module-kittycad.api
|
||||||
# for more details.""",
|
# for more details.""",
|
||||||
"install": "pip install kittycad",
|
"install": "pip install kittycad",
|
||||||
}
|
}
|
||||||
@ -757,7 +760,7 @@ async def test_"""
|
|||||||
# Add our example to our json output.
|
# Add our example to our json output.
|
||||||
data["paths"][name][method]["x-python"] = {
|
data["paths"][name][method]["x-python"] = {
|
||||||
"example": cleaned_example.replace("def test_", "def example_"),
|
"example": cleaned_example.replace("def test_", "def example_"),
|
||||||
"libDocsLink": "https://python.api.docs.kittycad.io/_autosummary/kittycad.api."
|
"libDocsLink": "https://python.api.docs.zoo.dev/_autosummary/kittycad.api."
|
||||||
+ tag_name
|
+ tag_name
|
||||||
+ "."
|
+ "."
|
||||||
+ fn_name
|
+ fn_name
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -4,13 +4,15 @@ from typing import Dict, Optional, Union
|
|||||||
|
|
||||||
import attr
|
import attr
|
||||||
|
|
||||||
|
DEFAULT_BASE_URL = "https://api.zoo.dev"
|
||||||
|
|
||||||
|
|
||||||
@attr.s(auto_attribs=True)
|
@attr.s(auto_attribs=True)
|
||||||
class Client:
|
class Client:
|
||||||
"""A Client which has been authenticated for use on secured endpoints of the KittyCAD API.""" # noqa: E501
|
"""A Client which has been authenticated for use on secured endpoints of the KittyCAD API.""" # noqa: E501
|
||||||
|
|
||||||
token: str = attr.ib(kw_only=True)
|
token: str = attr.ib(kw_only=True)
|
||||||
base_url: str = attr.ib(default="https://api.kittycad.io")
|
base_url: str = attr.ib(default=DEFAULT_BASE_URL)
|
||||||
cookies: Dict[str, str] = attr.ib(factory=dict, kw_only=True)
|
cookies: Dict[str, str] = attr.ib(factory=dict, kw_only=True)
|
||||||
headers: Dict[str, str] = attr.ib(factory=dict, kw_only=True)
|
headers: Dict[str, str] = attr.ib(factory=dict, kw_only=True)
|
||||||
timeout: float = attr.ib(120.0, kw_only=True)
|
timeout: float = attr.ib(120.0, kw_only=True)
|
||||||
@ -45,18 +47,27 @@ class Client:
|
|||||||
|
|
||||||
@attr.s(auto_attribs=True)
|
@attr.s(auto_attribs=True)
|
||||||
class ClientFromEnv(Client):
|
class ClientFromEnv(Client):
|
||||||
"""A Client which has been authenticated for use on secured endpoints that uses the KITTYCAD_API_TOKEN environment variable for the authentication token.""" # noqa: E501
|
"""A Client which has been authenticated for use on secured endpoints that uses the KITTYCAD_API_TOKEN or ZOO_API_TOKEN environment variable for the authentication token.
|
||||||
|
|
||||||
|
Optionally, you can use `ZOO_HOST` to set the base url.
|
||||||
|
This implies you are hosting your own instance of the KittyCAD API.
|
||||||
|
""" # noqa: E501
|
||||||
|
|
||||||
token: str = attr.field()
|
token: str = attr.field()
|
||||||
|
base_url: str = attr.ib(default=os.getenv("ZOO_HOST", DEFAULT_BASE_URL))
|
||||||
|
|
||||||
@token.default
|
@token.default
|
||||||
def set_token(self):
|
def set_token(self):
|
||||||
maybe_token: Optional[str] = os.getenv("KITTYCAD_API_TOKEN")
|
maybe_token: Optional[str] = os.getenv("KITTYCAD_API_TOKEN")
|
||||||
if maybe_token is None:
|
if maybe_token is None:
|
||||||
raise ValueError(
|
# Try the ZOO_API_TOKEN environment variable
|
||||||
"KITTYCAD_API_TOKEN environment variable must be set to use ClientFromEnv"
|
maybe_token = os.getenv("ZOO_API_TOKEN")
|
||||||
)
|
if maybe_token is None:
|
||||||
|
raise ValueError(
|
||||||
|
"KITTYCAD_API_TOKEN or ZOO_API_TOKEN environment variable must be set to use ClientFromEnv"
|
||||||
|
)
|
||||||
token: str = maybe_token
|
token: str = maybe_token
|
||||||
|
|
||||||
return token
|
return token
|
||||||
|
|
||||||
def get_headers(self) -> Dict[str, str]:
|
def get_headers(self) -> Dict[str, str]:
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "kittycad"
|
name = "kittycad"
|
||||||
version = "0.7.1"
|
version = "0.7.2"
|
||||||
description = "A client library for accessing KittyCAD"
|
description = "A client library for accessing KittyCAD"
|
||||||
|
|
||||||
authors = []
|
authors = []
|
||||||
|
Reference in New Issue
Block a user