This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!
Project Description

Python SDK for Contentful’s Content Delivery API.

Setup

Installation via pip:

pip install contentful.py

Usage

Creating a Client

The Client class manages all your interaction with the Contentful Delivery API, creating one is as simple as:

client = Client('space-id', 'access-token')

Fetching Resources

The simplest form of fetching resources follows:

client.fetch(Asset).all()         # Returns an array of Assets
client.fetch(Asset).first()       # Returns the first Asset available

client.fetch(Entry).all()         # Returns an array of Entries
client.fetch(Entry).first()       # Returns the first Entry available

client.fetch(ContentType).all()   # Returns an array of Content Types
client.fetch(ContentType).first() # Returns the first Content Type available

When used with the all() method, expect an Array object to be returned, which is iterable:

for resource in array:
    dosomething(resource)

and sliceable:

for resource in array[2:4]:
    dosomething(resource)

Custom Queries

Custom queries can be provided by invoking the where() method of a Request object, for example:

client.fetch(Entry).where({'sys.id': 'MyEntry'}).first()

Defining Models

Custom Entry classes can be declared by providing a Content Type ID value and by defining a set of fields. Consider the Cat Content Type from the official demo space, which looks like this (sans some properties for brevity):

{
  "fields": [
    {"id": "name", "name": "Name", "type": "Text"},
    {"id": "likes", "name": "Likes", "type": "Array", "items": { "type": "Symbol" }},
    {"id": "color", "name": "Color", "type": "Symbol"},
    {"id": "bestFriend", "name": "Best Friend", "type": "Link", "linkType": "Entry"},
    {"id": "birthday", "name": "Birthday", "type": "Date"},
    {"id": "lives", "name": "Lives left", "type": "Integer"},
    {"id": "image", "name": "Image", "type": "Link", "linkType": "Asset"}
  ],
  "name": "Cat",
  "displayField": "name",
  "description": "Meow."
}

A custom Entry class for this Content Type can be defined as follows:

class Cat(Entry):
    __content_type__ = 'cat'

    name = Field(Text)
    likes = Field(List)
    color = Field(Text)
    best_friend = Field(Link, field_id='bestFriend')
    birthday = Field(Date)
    lives = Field(Number)
    image = Field(Link)

The class also has to be registered when creating a Client:

client = Client('cfexampleapi', 'b4c0n73n7fu1', custom_entries=[Cat])

Whenever this Client will attempt to create an Entry with a Content Type that matches the one defined in the class, an instance of the Cat class will be created, and it’s fields will be set accordingly, and can later be easily accessed as instance attributes:

print('Name of the Cat: {0}'.format(cat.name))

If at any point it is desired to fetch only resources of that type, it can be passed to the fetch() method and inferred by the client:

client.fetch(Cat).all() # Fetches all the Cats!

License

Copyright (c) 2015 Contentful GmbH. See LICENSE.txt for further details.

Release History

Release History

0.9.3

This version

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.9.2

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.9.1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

0.9.0a1

History Node

TODO: Figure out how to actually get changelog content.

Changelog content for this version goes here.

Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit.

Show More

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
contentful.py-0.9.3.tar.gz (13.7 kB) Copy SHA256 Checksum SHA256 Source Jan 18, 2016

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting