Skip to main content

Python API for Space Traders

Project description

spacetraders python client

A client library for accessing SpaceTraders API

Usage

First, create a client:

from spacetraders import Client

client = Client(base_url="https://api.spacetraders.io/v2")

If the endpoints you're going to hit require authentication, use AuthenticatedClient instead:

from spacetraders import AuthenticatedClient

client = AuthenticatedClient(base_url="https://api.spacetraders.io/v2", token="SuperSecretToken")

Now call your endpoint and use your models:

from spacetraders.models import GetMyAgentResponse200
from spacetraders.types import Response

response: Response[GetMyAgentResponse200] = client.agents.get_my_agent()

Or do the same thing with an async version:

from spacetraders.models import GetMyAgentResponse200
from spacetraders.types import Response

response: Response[GetMyAgentResponse200] = await client.agents.get_my_agent()

By default, when you're calling an HTTPS API it will attempt to verify that SSL is working correctly. Using certificate verification is highly recommended most of the time, but sometimes you may need to authenticate to a server (especially an internal server) using a custom certificate bundle.

client = AuthenticatedClient(
    base_url="https://internal_api.example.com", 
    token="SuperSecretToken",
    verify_ssl="/path/to/certificate_bundle.pem",
)

You can also disable certificate validation altogether, but beware that this is a security risk.

client = AuthenticatedClient(
    base_url="https://internal_api.example.com", 
    token="SuperSecretToken", 
    verify_ssl=False
)

There are more settings on the generated Client class which let you control more runtime behavior, check out the docstring on that class for more info.

Things to know:

  1. All path/query params and bodies become method arguments.
  2. Tagged endpoints will use the first tag as a module name for the function
  3. Any endpoint which did not have a tag will be in client.default

Refreshing the API definition

This project is generated from SpaceTradersAPI/api-docs. The following steps outline how to refresh from a new schema:

  1. Clone the version of the api-docs to be generated in another directory git clone https://github.com/SpaceTradersAPI/api-docs /tmp/api-docs
  2. Navigate to /tmp/api-docs and generate a single OpenAPI bundle npx @redocly/openapi-cli@latest bundle -o bundle.json
  3. In this projects directory, refresh the generated class with poetry run openapi-python-client update --path /tmp/api-docs/bundle.json --meta none --config openapi-client.yml --custom-template-path=openapi-client-template

Building / publishing this Client

This project uses Poetry to manage dependencies and packaging. Here are the basics:

  1. Update the metadata in pyproject.toml (e.g. authors, version)
  2. Publish the client with poetry publish --build -r <your-repository-name> or, if for public PyPI, just poetry publish --build

If you want to install this client into another project without publishing it (e.g. for development) then:

  1. If that project is using Poetry, you can simply do poetry add <path-to-this-client> from that project
  2. If that project is not using Poetry:
    1. Build a wheel with poetry build -f wheel
    2. Install that wheel from the other project pip install <path-to-wheel>

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spacetraders-0.2.2.tar.gz (42.9 kB view details)

Uploaded Source

Built Distribution

spacetraders-0.2.2-py3-none-any.whl (169.9 kB view details)

Uploaded Python 3

File details

Details for the file spacetraders-0.2.2.tar.gz.

File metadata

  • Download URL: spacetraders-0.2.2.tar.gz
  • Upload date:
  • Size: 42.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.8.10 Linux/5.10.102.1-microsoft-standard-WSL2

File hashes

Hashes for spacetraders-0.2.2.tar.gz
Algorithm Hash digest
SHA256 568246d87571ce3e12bd28210a6dbe1d39d49e9e2504da1f26267ed8c8e81176
MD5 35290a811080f8f77d4cd1563e529519
BLAKE2b-256 1aadc0dabe61431e96508360069fe4c9bc0871113c7eea93327916ad5f417de0

See more details on using hashes here.

Provenance

File details

Details for the file spacetraders-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: spacetraders-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 169.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.2 CPython/3.8.10 Linux/5.10.102.1-microsoft-standard-WSL2

File hashes

Hashes for spacetraders-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 77765138cfafa50992c8fc5b07c864aaf9f33cb6080e2438a029a791a8334a22
MD5 774e389fb706f096f2b356446e62734a
BLAKE2b-256 b5170e42c52f5859b753766f924086beddd0f68d69f794a357b96ceb80852ab5

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page