Skip to main content

Spacelift Client

Simple client library for working with the spacelift.io API.

Essential features:

  • Read operations for Spaces, Contexts, Stacks, and Blueprints
  • Create operations for Spaces, Contexts, and Stacks (from Blueprints)
  • Trigger a run for a Stack

Install

pip install spacelift

Usage

from spacelift import Spacelift


def main():
    sl = Spacelift(
        base_url="https://ORGNAME.app.spacelift.io/graphql",
        key_id="01HCJMP<API_KEY_ID ~26CHAR LONG>",
        key_secret="e355ae6fd5<API_KEY_SECRET ~64 CHAR LONG>"
    )
    result = sl.get_stacks()
    print(result)

    result = sl.get_stacks(query_fields=["id", "name", "branch", "namespace", "repository", "state"])
    print(result)


if __name__ == "__main__":
    main()
$ python main.py
[{'id': 'demo-stack', 'space': 'legacy'}]
[{'id': 'demo-stack', 'name': 'Demo stack', 'branch': 'showcase', 'namespace': 'spacelift-io', 'repository': 'onboarding', 'state': 'FINISHED'}]
$ 

Relevant Methods

from spacelift import Spacelift
sl = Spacelift()
sl.get_stacks()
sl.get_stack_by_id(stack_id)
sl.get_spaces()
sl.get_space_by_id(space_id)
sl.get_contexts()
sl.get_context_by_id(context_id)
sl.get_blueprints()
sl.get_blueprint_by_id(blueprint_id)

sl.create_stack_from_blueprint(blueprint_id, inputs=[{'id': 'bp_var1', 'value': 'bp_var1_value'}])

sl.trigger_run(stack_id)

Environment Variables

the Spacelift object can also infer its parameters from the following environment variables:

SPACELIFT_BASE_URL="https://ORGNAME.app.spacelift.io/graphql"
SPACELIFT_KEY_ID="01HCJMP<API_KEY_ID ~26CHAR LONG>"
SPACELIFT_KEY_SECRET="e355ae6fd5<API_KEY_SECRET ~64 CHAR LONG>"

API Keys

Currently, this depends on the API Key workflow here. The Current Spacelift.io documentation doesn't clearly specify this, but the API Key ID is the 26 character code that appears after the name in the web UI. It does not appear at all in the downloaded .config file.

The required Secret value is the first code (64 characters long) that appears in the downloaded .config file.

Raw GraphQL

The Spacelift object also has a _execute method that accepts a raw GraphQL query object. This can be created by sending a valid GraphQL query string to gql.gql() from the gql package. This is necessary for more advanced queries.

Mocked Version

There's also a mocked version MockedSpacelift that can be used for testing. It offers mocked versions of all the CRUD methods without any real API calls.

Development

Publishing

poetry build
poetry publish

Release files for spacelift 1.1.2

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

Source distribution (sdist)

Source distribution for spacelift 1.1.2
File Size Uploaded
spacelift-1.1.2.tar.gz 11.2 kB Details

Built distribution (wheel)

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

Total release size: 22.6 kB

Release files / spacelift-1.1.2.tar.gz

Download URL spacelift-1.1.2.tar.gz
Size 11.2 kB
Tags Source
SHA-256 checksum
How to use checksums
39b2675f2d75e82209a754b60205c4f1091f6103c16b2b56e61ed8ca41d5b5bd
BLAKE2b-256 checksum
How to use checksums
0c6b3bbe826e12daa4a41342db885077157e8c150a2a69def35877bc32ec57fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.10.5 Windows/10

Release files / spacelift-1.1.2-py3-none-any.whl

Download URL spacelift-1.1.2-py3-none-any.whl
Size 11.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2bd1b49e2f1d101990ac0fddb788a6dd147612a33206c16ca84310f2730a8e4e
BLAKE2b-256 checksum
How to use checksums
eaaefe5ceb248b769eb61d572fa9ebb646f131363728efd16124f7d116e72c27
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.10.5 Windows/10

Release history Release notifications | RSS feed

This release

1.1.2 This release

2 release files

1.1.1

2 release files

1.1.0

2 release files

1.0.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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