Skip to main content

Firefox Kinto client

Project description

Kinto is a service allowing you to store and synchronize arbitrary data, attached to a user account. Its primary interface is HTTP.

kinto-client is a Python library aiming at easing interacting with a Kinto server instance. A project with related goals is also available for JavaScript.

Usage

  • The first version of this API doesn’t cache any access nor provide any refresh mechanism. If you want to be sure you have the latest data available, issue another call.

Here is an overview of what the API looks like:

from kintoclient import Bucket

bucket = Bucket('default', server_url='http://localhost:8888/v1',
                auth=('alexis', 'p4ssw0rd'))
todo = bucket.get_collection('todo')

records = todo.get_records()
for i, record in enumerate(records):
    record.data.title = 'Todo #%d' %i

todo.save_records(records)

Handling buckets

All operations are rooted in a bucket. It makes little sense for one application to handle multiple buckets at once.

The passed auth parameter is a requests authentication policy, allowing authenticating using whatever fits you best.

By default, Kinto supports Firefox Accounts and Basic authentication policies.

credentials = ('alexis', 'p4ssw0rd')

bucket = Bucket('payments', server_url='http://localhost:8888/v1',
                auth=credentials)

# Passing `create=True` to the bucket will make an HTTP request to
# create it.
bucket = Bucket('payments', server_url='http://localhost:8888/v1',
                auth=credentials, create=True)

Collections

A collection is where records are stored.

# Once the bucket handy, use it to handle collections or groups.
collection = bucket.create_collection('receipts')

# Or get an existing one.
collection = bucket.get_collection('receipts')

# To delete an existing collection.
bucket.delete_collection('receipts')

Records

Records can be retrieved from and saved to collections.

# You can pass a python dictionary to create the record
record = collection.create_record(dict(id='XXX', status='done',
                                       title='Todo #1'))

# Get all records
record = collection.get_records()
record = collection.get_record(id='89881454-e4e9-4ef0-99a9-404d95900352')
collection.save_record(record)
collection.save_records([record1, record2])
collection.delete_record(id='89881454-e4e9-4ef0-99a9-404d95900352')
collection.delete_records([record1, record2])

# Alternative use
record.save()

Permissions

By default, authenticated users will get read and write access to the manipulated objects. It is possible to change this behavior by passing a dict to the permissions parameter.

record = collection.create_record(
    data={},
    permissions={'read': ['group:groupid']})

The Bucket, Collection, Group and Record classes have a special permissions object that can be mutated in order to update the permissions model attached to the object.

bucket = Bucket('default', auth=('alexis', 'p4ssw0rd'))

friends = ['natim', 'niko', 'mat', 'tarek']
bucket.permissions.write += friends
bucket.permissions.create_collection += friends

# You *need* to call save in order to have these changes reflected in the
# remote.
bucket.save()

Installation

To install the kinto client, use pip:

$ pip install kintoclient

Project details


Download files

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

Source Distribution

kinto-client-0.1.1.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

kinto_client-0.1.1-py2-none-any.whl (15.9 kB view details)

Uploaded Python 2

File details

Details for the file kinto-client-0.1.1.tar.gz.

File metadata

File hashes

Hashes for kinto-client-0.1.1.tar.gz
Algorithm Hash digest
SHA256 29519c56c0db03246691628b9f120d7e654183931582bfc5e2941d6ae53a2382
MD5 dc6444239a65f1b7f7c1649e1cb22682
BLAKE2b-256 fa5ecdc3d011da3473ce91c37ab800b4333b3e150dcd5decefae9ece14aec58e

See more details on using hashes here.

File details

Details for the file kinto_client-0.1.1-py2-none-any.whl.

File metadata

File hashes

Hashes for kinto_client-0.1.1-py2-none-any.whl
Algorithm Hash digest
SHA256 8470f00bbfa60b0c10a0fa82e310cc219874fe7dfc5256bb409a60b39b6be1f3
MD5 4f072d14b4e54aa0e180508bd1031e64
BLAKE2b-256 1edf3aca3990fda88be2a2eb2c8d63d0ef749be1be3af0e28e34bb300db3347f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page