/jiyou-sample-sdk

Example SDK for jiyou

Primary LanguagePythonMIT LicenseMIT

Template SDK

How to use this repository

👀 This template repository is designed to bootstrap a Speakeasy managed SDK repository using Github's repository clone feature. Once this repository is setup it will automatically keep your SDK up to date and published to a package manager.

Creating an SDK

  1. To get started, simply clone the repository by clicking on the "Use template" button and give it a name.

Screenshot 2023-09-06 at 09 20 52

  1. Configure the Speakeasy workflow to generate the SDK. Go to the generation workflow file and configure the language, mode and location of your openapi document. For complete documentation on all the available generation configurations, see here. You will also need to add a SPEAKEASY_API_KEY as a repository secret. If you don't already have a key you can get one by making a workspace on Speakeasy here.

  2. Configure the Speakeasy workflow to publish the SDK. Go to the publishing workflow file and configure any relevant package manager credentials as repository secrets. For complete documentation on all the available publishing configurations, see here.

  3. Configure the generation by editing the gen.yaml file in the root of the repo. This file controls the generator and determines various attributes of the SDK like packageName, sdkClassName, inlining of parameters, and other ergonomics.

  4. Finally go to the Actions tab, choose the generation workflow and click "Force Generate". This will trigger a new generation of your SDK using the configuration you provided above. Depending on whether you configured pr or direct mode above your updated SDK will appear in PR or in the main branch.

Screenshot 2023-09-06 at 10 01 46

🚀 You should have a working SDK for your API 🙂 . To check out all the features of the SDK please see our docs site.

Local development

Once you have the SDK setup you may want to iterate on the SDK. Speakeasy supports OpenAPI vendor extensions that can be added to your spec to customize the SDK ergonomics (method names, namespacing resources etc.) and functionality (adding retries, pagination, multiple server support etc)

To get started install the Speakeasy CLI.

In your terminal, run:

brew install speakeasy-api/homebrew-tap/speakeasy

Once you annonate your spec with an extension you will want to run speakeasy validate to check the spec for correctness and speakeasy generate to recreate the SDK locally. More documentation on OpenAPI extensions here. Here's an example of adding a multiple server support to the spec so that your SDK supports production and sandbox versions of your API.

info:
  title: Example
  version: 0.0.1
servers:
  - url: https://prod.example.com # Used as the default URL by the SDK
    description: Our production environment
    x-speakeasy-server-id: prod
  - url: https://sandbox.example.com
    description: Our sandbox environment
    x-speakeasy-server-id: sandbox

Once you're finished iterating and happy with the output push only the latest version of spec into the repo and regenerate the SDK using step 6 above.

SDK Installation

pip install git+https://github.com/speakeasy-sdks/template-sdk.git

SDK Example Usage

import speakeasybar
from speakeasybar.models import operations, shared

s = speakeasybar.Speakeasybar(
    security=shared.Security(
        api_key="",
    ),
)

res = s.drinks.list_drinks(drink_type=shared.DrinkType.WINE)

if res.drinks is not None:
    # handle response

Available Resources and Operations

  • authenticate - Authenticate with the API by providing a username and password.

Maturity

This SDK is in beta, and there may be breaking changes between versions without a major version update. Therefore, we recommend pinning usage to a specific package version. This way, you can install the same version each time without breaking changes unless you are intentionally looking for the latest version.

Contributions

While we value open-source contributions to this SDK, this library is generated programmatically. Feel free to open a PR or a Github issue as a proof of concept and we'll do our best to include it in a future release !

SDK Created by Speakeasy