Skip to content

storyblok/storyblok-python-client

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
 
 
 
 
 
 
 
 
 
 

storyblok-python-sdk

Warning: It's currently not working with US endpoints.

Storyblok API library client for python.

This library is generated by alpaca

Installation

Make sure you have pip installed

$ pip install storyblok

Versions

Works with [ 2.6 / 2.7 / 3.2 / 3.3 ]

Usage

import storyblok

# Then we instantiate a client (as shown below)

Build a client

Without any authentication
client = storyblok.Client()

# If you need to send options
client = storyblok.Client({}, client_options)

Client Options

The following options are available while instantiating a client:

  • base: Base url for the api
  • api_version: Default version of the api (to be used in url)
  • user_agent: Default user-agent for all requests
  • headers: Default headers for all requests
  • request_type: Default format of the request body

Response information

All the callbacks provided to an api call will recieve the response as shown below

response = client.klass('args').method('args', method_options)

response.code
# >>> 200

response.headers
# >>> {'content-type': 'application/json; charset=utf-8'}
JSON response

When the response sent by server is json, it is decoded into a dict

response.body
# >>> {"story": {"name":"story_name"}}

Method Options

The following options are available while calling a method of an api:

  • api_version: Version of the api (to be used in url)
  • headers: Headers for the request
  • query: Query parameters for the url
  • body: Body of the request
  • request_type: Format of the request body

Request body information

Set request_type in options to modify the body accordingly

JSON request

When the value is set to json, JSON encode the body.

body = {'story': {'name':"story_name"}}
# >>> '{"story": {"name":"story_name"}}'

Spaces api

Returns your current space name, published version and domain

spaces = client.spaces()
Get current space (GET /cdn/spaces/me)

This endpoint is mostly useful for client side apps. The response contains space.version which you can use to call the story api and get the most recent published version. (https://www.storyblok.com/docs/Delivery-Api/spaces)

The following arguments are required:

  • token: Public token for published or private token for draft version
response = spaces.me("your_access_token", options)

Stories api

Returns stories api instance

stories = client.stories()
Get a list of stories (GET /cdn/stories/)

Returns a list of Stories (https://www.storyblok.com/docs/Delivery-Api/get-a-story#get-a-list-of-stories)

The following arguments are required:

  • token: Public token for published or private token for draft version
response = stories.list("your_access_token", "draft", "1", "25", "posts", "1527067945", options)
Get a story by id (GET /cdn/stories/:story_id)

Returns a single story by id (https://www.storyblok.com/docs/Delivery-Api/get-a-story#get-a-story-by-id)

The following arguments are required:

  • token: Public token for published or private token for draft version
response = stories.single("your_access_token", "draft", "41252", options)

Tags api

Returns tags api instance

tags = client.tags()
Get a list of tags (GET /cdn/tags/)

Returns a list of tags (https://www.storyblok.com/docs/Delivery-Api/Tags)

The following arguments are required:

  • token: Public token for published or private token for draft version
response = tags.list("your_access_token", "de", options)

Links api

Returns links api instance

links = client.links()
Get a list of links (GET /cdn/links/)

Returns a list of links (https://www.storyblok.com/docs/Delivery-Api/Links)

The following arguments are required:

  • token: Public token for published or private token for draft version
response = links.list("your_access_token", "draft", "de", options)
Get a link by id (GET /cdn/links/:id)

Returns a single link by id (https://www.storyblok.com/docs/Delivery-Api/Links#get-a-single-link)

The following arguments are required:

  • token: Public token for published or private token for draft version
  • id: Uuid of the link
response = links.single("your_access_token", "148ee49a-ad81-4aff-b3d5-a2b4b6739e65", options)

Tags api

Returns tags api instance

datasource_entries = client.datasource_entries()
Get a list of tags (GET /cdn/datasource_entries/)

Returns a list of tags (https://www.storyblok.com/docs/Delivery-Api/Tags)

The following arguments are required:

  • token: Public token for published or private token for draft version
response = datasource_entries.list("your_access_token", "labels", "de-at", options)

Contributors

Here is a list of Contributors

License

MIT

Bug Reports

Report here.