Skip to main content
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Description: ===
wac
===

To write a friendly client for a RESTful API you typically end up doing the
following:

- Write HTTP client commands for communicating with the server. These commands
do things like marshal payloads, convert errors, invoke request hooks, etc.

- Turn responses deserialized by your client into resource objects (i.e.
objectify the response).

- Build up queries (e.g. filter, sort) to access resources matching some
criteria in perhaps a particular order.

In the ideal case the client gives your users something approximating an ORM
for your resources. This library is intended to assist you in writing such a
client provided the API you are consuming complies with some basic
conventions:

- Uses HTTP properly.

- Annotates resource representations with type and URI information.

Installation
------------

Simply::

$ pip install finix-wac

or if you prefer::

$ easy_install finix-wac

Requirements
------------

- `Python <http://python.org/>`_ >= 2.6, < 3.0
- `Requests <https://github.com/kennethreitz/requests/>`_ >= 1.2.3

Usage
-----

Lets work through an example. The code for this example is in ``example.py``.

- First you import wac:

.. code-block:: python

import wac

- Next define the version of your client:

.. code-block:: python

__version__ = '1.0'

- Also define the configuration which all ``Client``\s will use by default:

.. code-block:: python

default_config = wac.Config(None)

- Now be nice and define a function for updating the configuration(s):

.. code-block:: python

def configure(root_url, **kwargs):
default = kwargs.pop('default', True)
kwargs['client_agent'] = 'example-client/' + __version__
if 'headers' not in kwargs:
kwargs['headers'] = {}
kwargs['headers']['Accept-Type'] = 'application/json'
if default:
default_config.reset(root_url, **kwargs)
else:
Client.config = wac.Config(root_url, **kwargs

- Now the big one, define your ``Client`` which is what will be used to talk to
a server:

.. code-block:: python

class Client(wac.Client):

config = default_config

def _serialize(self, data):
data = json.dumps(data, default=self._default_serialize)
return 'application/json', data

def _deserialize(self, response):
if response.headers['Content-Type'] != 'application/json':
raise Exception(
"Unsupported content-type '{}'"
.format(response.headers['Content-Type'])
)
data = json.loads(response.content)
return data

- Then define your base ``Resource``:

.. code-block:: python

class Resource(wac.Resource):

client = Client()
registry = wac.ResourceRegistry()

- And finally your actual resources:

.. code-block:: python

class Playlist(Resource):

type = 'playlist'

uri_gen = wac.URIGen('/v1/playlists', '{playlist}')


class Song(Resource):

type = 'song'

uri_gen = wac.URIGen('/v1/songs', '{song}')


- Done! Now you can do crazy stuff like this:

.. code-block:: python

import example

example.configure('https://api.example.com', auth=('user', 'passwd'))

q = (example.Playlist.query()
.filter(Playlist.f.tags.contains('nuti'))
.filter(~Playlist.f.tags.contains('sober'))
.sort(Playlist.f.created_at.desc()))
for playlist in q:
song = playlist.songs.create(
name='Flutes',
length=1234,
tags=['nuti', 'fluti'])
song.length += 101
song.save()

Contributing
------------

1. Fork it
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Write your code **and tests**
4. Ensure all tests still pass (`python setup.py test`)
5. Commit your changes (`git commit -am 'Add some feature'`)
6. Push to the branch (`git push origin my-new-feature`)
7. Create new pull request


.. :changelog:

History
-------

0.29 (2016-11)
++++++++++++++++++

* Update package name


0.28 (2016-10)
++++++++++++++++++

* Fix total property not found in page resource
* Require requests >= 1.2.3.

Platform: UNKNOWN
Classifier: Intended Audience :: Developers
Classifier: Development Status :: 4 - Beta
Classifier: Natural Language :: English
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: License :: OSI Approved :: ISC License (ISCL)
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 2.7

Metadata

Release files for finix-wac 0.31

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

Source distribution (sdist)

Source distribution for finix-wac 0.31
File Size Uploaded Provenance Actions
finix-wac-0.31.tar.gz 14.5 kB Without provenance Details for finix-wac-0.31.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for finix-wac 0.31
File Interpreter ABI Platform Actions
finix_wac-0.31-py2-none-any.whl Python 2 none any Details for finix_wac-0.31-py2-none-any.whl

Total release size: 32.2 kB

Release files / finix-wac-0.31.tar.gz

Download URL finix-wac-0.31.tar.gz
Size 14.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f89fe6b3f167185aec25781c3694e641678383cdeeb92907bf1ce2e81302e1bc
BLAKE2b-256 checksum
How to use checksums
0720616724d0d7561e1ebd83ebed4a20d0a6caf19a0d93a09d9759b7f256da25
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / finix_wac-0.31-py2-none-any.whl

Download URL finix_wac-0.31-py2-none-any.whl
Size 17.7 kB
Tags Python 2
SHA-256 checksum
How to use checksums
06b42849caa668cebf74b2b2100f878ca6310c88e08b75659a083442a399864e
BLAKE2b-256 checksum
How to use checksums
ed2e754d532ccd62cdce9006f42a58d4a2d60bd8b001df38d5c656add1bfc288
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for finix-wac 0.31

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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