diff --git a/.fernignore b/.fernignore index 94457f9..b6293ae 100644 --- a/.fernignore +++ b/.fernignore @@ -3,5 +3,4 @@ README.md assets/ -src/webflow/client.py src/webflow/oauth.py diff --git a/README.md b/README.md index dbf6b74..34a0c6c 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Webflow Python Library [![fern shield](https://img.shields.io/badge/%F0%9F%8C%BF-SDK%20generated%20by%20Fern-brightgreen)](https://github.com/fern-api/fern) +[![pypi](https://img.shields.io/pypi/v/webflow.svg)](https://pypi.python.org/pypi/webflow) The Webflow Python Library provides convenient access to the Webflow API from applications written in Python. The library includes type definitions for all @@ -27,9 +28,7 @@ Simply import `Webflow` and start making calls to our API. from webflow.client import Webflow client = Webflow( - client_id="YOUR_CLIENT_ID", - client_secret="YOUR_CLIENT_SECRET", - code="YOUR_AUTHORIZATION_CODE" + access_token="YOUR_ACCESS_TOKEN" ) site = client.sites.get("site-id") ``` @@ -42,9 +41,7 @@ calls to our API. from webflow.client import AsyncWebflow client = AsyncWebflow( - client_id="YOUR_CLIENT_ID", - client_secret="YOUR_CLIENT_SECRET", - code="YOUR_AUTHORIZATION_CODE" + access_token="YOUR_ACCESS_TOKEN" ) async def main() -> None: @@ -68,33 +65,19 @@ for more details. from webflow.oauth import authorize_url from webflow import OauthScope -url = webflow.authorize_url({ - client_id = "[CLIENT ID]", - scope = OauthScope.ReadUsers, # or [OauthScope.ReadUsers, OauthScope.WriteUsers] - state = "1234567890", # optional - redirect_uri = "https://my.server.com/oauth/callback", # optional -}); - -print(url) -``` - -### Step 2: Instantiate the client -Pass in your `client_id`, `client_secret`, `authorization_code` when instantiating -the client. Our SDK handles generating an access token and passing that to every endpoint. - -```python -from webflow.client import Webflow - -client = Webflow( +url = authorize_url( client_id="YOUR_CLIENT_ID", - client_secret="YOUR_CLIENT_SECRET", - code="YOUR_AUTHORIZATION_CODE", - redirect_uri = "https://my.server.com/oauth/callback", # optional + scope=OauthScope.USERS_READ, # or [OauthScope.USERS_READ, OauthScope.USERS_WRITE] + state="1234567890", # optional + redirect_uri="https://my.server.com/oauth/callback", # optional ) + +print(url) ``` -If you want to generate an access token yourself, simply import the -`get_access_token` function. +### Step 2: Retrieve your acccess token +Use the `get_access_token` function and pass in your `client_id`, +`client_secret`, and `authorization_code`. ```python from webflow.oauth import get_access_token @@ -106,6 +89,17 @@ access_token = get_access_token( ) ``` +### Step 3: Instantiate the client +Instantiate the client using your access_token. + +```python +from webflow.client import Webflow + +client = Webflow( + access_token=access_token +) +``` + ## Webflow Module All of the models are nested within the Webflow module. Let Intellisense guide you! @@ -131,7 +125,7 @@ except webflow.BadRequestError as e: # Handle specific error ## Advanced ### Timeouts -By default requests time out after 60 seconds. You can configure this with a +By default, requests time out after 60 seconds. You can configure this with a timeout option, which accepts a float. ```python @@ -144,7 +138,7 @@ client = Webflow( ``` ### Custom HTTP client -You can override the httpx client to customize it for your use case. Some common usecases +You can override the httpx client to customize it for your use case. Some common use-cases include support for proxies and transports. ```python diff --git a/pyproject.toml b/pyproject.toml index 10a6dcf..9750e6b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "webflow" -version = "0.1.0b1" +version = "0.1.0b2" description = "" readme = "README.md" authors = [] diff --git a/src/webflow/client.py b/src/webflow/client.py index 63d4dbf..08638bc 100644 --- a/src/webflow/client.py +++ b/src/webflow/client.py @@ -6,7 +6,6 @@ from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from .environment import WebflowEnvironment -from .oauth import get_access_token from .resources.access_groups.client import AccessGroupsClient, AsyncAccessGroupsClient from .resources.assets.client import AssetsClient, AsyncAssetsClient from .resources.collections.client import AsyncCollectionsClient, CollectionsClient @@ -27,22 +26,15 @@ class Webflow: def __init__( self, *, - client_id: str, - client_secret: str, - code: str, - redirect_uri: typing.Optional[str] = None, + base_url: typing.Optional[str] = None, environment: WebflowEnvironment = WebflowEnvironment.DEFAULT, + access_token: typing.Union[str, typing.Callable[[], str]], timeout: typing.Optional[float] = 60, httpx_client: typing.Optional[httpx.Client] = None ): - self._token = get_access_token( - client_id=client_id, - client_secret=client_secret, - code=code, - redirect_uri=redirect_uri) self._client_wrapper = SyncClientWrapper( - base_url=_get_base_url(base_url=None, environment=environment), - access_token=self._token, + base_url=_get_base_url(base_url=base_url, environment=environment), + access_token=access_token, httpx_client=httpx.Client(timeout=timeout) if httpx_client is None else httpx_client, ) self.token = TokenClient(client_wrapper=self._client_wrapper) @@ -65,22 +57,15 @@ class AsyncWebflow: def __init__( self, *, - client_id: str, - client_secret: str, - code: str, - redirect_uri: typing.Optional[str] = None, + base_url: typing.Optional[str] = None, environment: WebflowEnvironment = WebflowEnvironment.DEFAULT, + access_token: typing.Union[str, typing.Callable[[], str]], timeout: typing.Optional[float] = 60, httpx_client: typing.Optional[httpx.AsyncClient] = None ): - self._token = get_access_token( - client_id=client_id, - client_secret=client_secret, - code=code, - redirect_uri=redirect_uri) self._client_wrapper = AsyncClientWrapper( - base_url=_get_base_url(base_url=None, environment=environment), - access_token=self._token, + base_url=_get_base_url(base_url=base_url, environment=environment), + access_token=access_token, httpx_client=httpx.AsyncClient(timeout=timeout) if httpx_client is None else httpx_client, ) self.token = AsyncTokenClient(client_wrapper=self._client_wrapper) diff --git a/src/webflow/core/client_wrapper.py b/src/webflow/core/client_wrapper.py index 5e431c1..2e7a724 100644 --- a/src/webflow/core/client_wrapper.py +++ b/src/webflow/core/client_wrapper.py @@ -14,7 +14,7 @@ def get_headers(self) -> typing.Dict[str, str]: headers: typing.Dict[str, str] = { "X-Fern-Language": "Python", "X-Fern-SDK-Name": "webflow", - "X-Fern-SDK-Version": "0.1.0b1", + "X-Fern-SDK-Version": "0.1.0b2", } headers["Authorization"] = f"Bearer {self._get_access_token()}" return headers diff --git a/src/webflow/oauth.py b/src/webflow/oauth.py index 4de369b..ce06031 100644 --- a/src/webflow/oauth.py +++ b/src/webflow/oauth.py @@ -58,7 +58,7 @@ def authorize_url( if scope is not OMIT and isinstance(scope, str): params["scope"] = scope.value elif scope is not OMIT: - params["scope"] = ", ".join([s.value for s in scope]) # type: ignore + params["scope"] = " ".join([s.value for s in scope]) # type: ignore return f"https://webflow.com/oauth/authorize?{urllib.parse.urlencode(params)}"