simple python client for the spacelift.io GraphQL API
Project description
Spacelift Client
Simple client library for working with the spacelift.io API.
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.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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for spacelift-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b217e34803339d6bb8a7bf9a1043475620ea04ac2af33758fdfbdf90a0253115 |
|
MD5 | 92bc1726c5d4fbc8a0e1f475736bc918 |
|
BLAKE2b-256 | 9c92fa35815675c87a1c01b5626cb98e1cd771fe5e7417e0ca09ba8506deb470 |