Skip to main content

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>

Metadata

Release files for spacetraders 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spacetraders 0.10.0
File Size Uploaded Provenance
spacetraders-0.10.0.tar.gz 59.1 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for spacetraders 0.10.0
File Interpreter ABI Platform
spacetraders-0.10.0-py3-none-any.whl Python 3 none any Details

Total release size: 288.2 kB

Release files / spacetraders-0.10.0.tar.gz

Download URL spacetraders-0.10.0.tar.gz
Size 59.1 kB
Tags Source
SHA-256 checksum
How to use checksums
202d281e33a6fef51af3bd028053a85048d36062be5e7b8cc82c8c771b3ac389
BLAKE2b-256 checksum
How to use checksums
2cbdfa3fe7ac5410950ba63b19f70b121e4f03752f78b69e674bea5ea2e57f5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.6 Darwin/23.1.0

Release files / spacetraders-0.10.0-py3-none-any.whl

Download URL spacetraders-0.10.0-py3-none-any.whl
Size 229.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6211e2c89e6873a2987f93d9564388b1d62115114e77817507f87b899809b309
BLAKE2b-256 checksum
How to use checksums
55268da8aa77e097db6b0e45317bcc585774552f8770884c6dfd3ce1e44a69d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.6 Darwin/23.1.0

Security for spacetraders 0.10.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page