SDKgen is a powerful code generator to automatically build client SDKs for your REST API.

Sign in   Sign up

Code

At the following page you can take a look at the generated code, the code is based on this TypeAPI specification. This is only a demo to give you a first insight, for live examples feel free to login at the backend and use the live generator.


client.py

"""
Client automatically generated by SDKgen please do not edit this file manually
https://sdkgen.app
"""

import sdkgen

from test_tag import TestTag

class Client(sdkgen.ClientAbstract):
    def __init__(self, base_url: str, credentials: sdkgen.CredentialsInterface):
        super().__init__(base_url, credentials)
    pass

    def test(self) -> TestTag:
        return TestTag(
            self.http_client,
            self.parser
        )
    pass



    @staticmethod
    def build(credentials: sdkgen.CredentialsInterface):
        return Client("https://api.sdkgen.app/", credentials)
    pass

error.py

"""
error automatically generated by SDKgen please do not edit this file manually
https://sdkgen.app
"""

from dataclasses import dataclass
from dataclasses_json import dataclass_json
@dataclass_json
@dataclass
class Error:
    success: bool
    message: str

error_exception.py

"""
ErrorException automatically generated by SDKgen please do not edit this file manually
https://sdkgen.app
"""

import sdkgen

class ErrorException(sdkgen.KnownStatusCodeException) {

    def __init__(self, payload: Error):
        self.payload = payload
    pass

}

hello_world.py

"""
hello_world automatically generated by SDKgen please do not edit this file manually
https://sdkgen.app
"""

from dataclasses import dataclass
from dataclasses_json import dataclass_json
@dataclass_json
@dataclass
class HelloWorld:
    message: str

response.py

"""
response automatically generated by SDKgen please do not edit this file manually
https://sdkgen.app
"""

from dataclasses import dataclass
from dataclasses_json import dataclass_json
@dataclass_json
@dataclass
class Response:
    success: bool
    message: str

test_tag.py

"""
TestTag automatically generated by SDKgen please do not edit this file manually
https://sdkgen.app
"""

import requests
import sdkgen

from error_exception import ErrorException
from hello_world import HelloWorld
from response import Response
from todo import Todo
from todos import Todos

class TestTag(sdkgen.TagAbstract):
    def __init__(self, http_client: requests.Session, parser: sdkgen.Parser):
        super().__init__(http_client, parser)
    pass


    """
    Returns a hello world message
    """
    def get_hello(self, ) -> HelloWorld:
        try:
            pathParams = {}

            queryParams = {}

            queryStructNames = [];

            url = self.parser.url("/hello/world", pathParams)

            headers = {}

            response = self.http_client.get(url, headers=headers, params=this.parser.query(queryParams, queryStructNames))

            if response.status_code >= 200 and response.status_code < 300:
                return HelloWorld.from_json(response.content)


            raise sdkgen.UnknownStatusCodeException("The server returned an unknown status code")
        except Exception as e:
            raise sdkgen.ClientException("An unknown error occurred: " + str(e))
    pass

    """
    Returns available todo entries
    """
    def get_entries(self, start_index: int, count: int) -> Todos:
        try:
            pathParams = {}

            queryParams = {}
            queryParams["startIndex"] = start_index
            queryParams["count"] = count

            queryStructNames = [];

            url = self.parser.url("/todo", pathParams)

            headers = {}

            response = self.http_client.get(url, headers=headers, params=this.parser.query(queryParams, queryStructNames))

            if response.status_code >= 200 and response.status_code < 300:
                return Todos.from_json(response.content)


            raise sdkgen.UnknownStatusCodeException("The server returned an unknown status code")
        except Exception as e:
            raise sdkgen.ClientException("An unknown error occurred: " + str(e))
    pass

    """
    Inserts a new todo entry
    """
    def insert(self, payload: Todo) -> Response:
        try:
            pathParams = {}

            queryParams = {}

            queryStructNames = [];

            url = self.parser.url("/todo", pathParams)

            headers = {}
            headers["Content-Type"] = "application/json"

            response = self.http_client.post(url, headers=headers, params=this.parser.query(queryParams, queryStructNames), data=payload.to_json())

            if response.status_code >= 200 and response.status_code < 300:
                return Response.from_json(response.content)


            raise sdkgen.UnknownStatusCodeException("The server returned an unknown status code")
        except Exception as e:
            raise sdkgen.ClientException("An unknown error occurred: " + str(e))
    pass

    """
    Returns a hello world message
    """
    def throw_exception(self, ) -> HelloWorld:
        try:
            pathParams = {}

            queryParams = {}

            queryStructNames = [];

            url = self.parser.url("/exception", pathParams)

            headers = {}

            response = self.http_client.get(url, headers=headers, params=this.parser.query(queryParams, queryStructNames))

            if response.status_code >= 200 and response.status_code < 300:
                return HelloWorld.from_json(response.content)

            if response.status_code == 500:
                raise ErrorException(Error.from_json(response.content))

            raise sdkgen.UnknownStatusCodeException("The server returned an unknown status code")
        except Exception as e:
            raise sdkgen.ClientException("An unknown error occurred: " + str(e))
    pass


todo.py

"""
todo automatically generated by SDKgen please do not edit this file manually
https://sdkgen.app
"""

from dataclasses import dataclass
from dataclasses_json import dataclass_json
@dataclass_json
@dataclass
class Todo:
    title: str

todos.py

"""
todos automatically generated by SDKgen please do not edit this file manually
https://sdkgen.app
"""

from dataclasses import dataclass
from dataclasses_json import dataclass_json
from typing import List
from todo import Todo
@dataclass_json
@dataclass
class Todos:
    total_results: int
    start_index: int
    items_per_page: int
    entry: List[Todo]