XML backed models queried from external REST apis
Project description
[![Build Status](https://travis-ci.org/alephnullplex/xml_models2.svg?branch=master)](https://travis-ci.org/alephnullplex/xml_models2)
[![Coverage Status](https://coveralls.io/repos/alephnullplex/xml_models2/badge.svg?branch=master)](https://coveralls.io/r/alephnullplex/xml_models2?branch=master)
[Read The Docs](http://xml-models2.readthedocs.org/en/latest/)
# XmlModels2
XmlModels allows you to define Models similar in nature to Django models that are backed by XML endpoints rather than a
database. Using a familiar declarative definition, the fields map to values in the XML document by means of XPath
expressions. With support for querying external REST APIs using a django-esque approach, we have strived to make
writing and using xml backed models as close to django database models as we can, within the limitations of the
available API calls.
# Installation
The simplest approach is to to use `pip install xml_models2`
# A simple example
Just to get started, this is an example of taking an XML representation of an Address that might be returned from a
GET request to an external REST api.
<Address id="2">
<number>22</number>
<street>Acacia Avenue</street>
<city>Maiden</city>
<country>England</country>
<postcode>IM6 66B</postcode>
</Address>
class Address(xml_models.Model):
id=xml_models.IntField(xpath="/Address/@id")
number = xml_models.IntField(xpath="/Address/number")
street = xml_models.CharField(xpath="/Address/street")
city = xml_models.CharField(xpath="/Address/city")
country = xml_models.CharField(xpath="/Address/country")
postcode = xml_models.CharField(xpath="/Address/postcode")
finders = {(id,): 'http://adresses/%s'}
This example would be used as follows:-
>>> address = Address.objects.get(id=2)
>>> print "address is %s, %s" % (address.number, address.street)
"22, Acacia Avenue"
# Heritage
This project is a fork of [Django REST Models](http://djangorestmodel.sourceforge.net/)
[![Coverage Status](https://coveralls.io/repos/alephnullplex/xml_models2/badge.svg?branch=master)](https://coveralls.io/r/alephnullplex/xml_models2?branch=master)
[Read The Docs](http://xml-models2.readthedocs.org/en/latest/)
# XmlModels2
XmlModels allows you to define Models similar in nature to Django models that are backed by XML endpoints rather than a
database. Using a familiar declarative definition, the fields map to values in the XML document by means of XPath
expressions. With support for querying external REST APIs using a django-esque approach, we have strived to make
writing and using xml backed models as close to django database models as we can, within the limitations of the
available API calls.
# Installation
The simplest approach is to to use `pip install xml_models2`
# A simple example
Just to get started, this is an example of taking an XML representation of an Address that might be returned from a
GET request to an external REST api.
<Address id="2">
<number>22</number>
<street>Acacia Avenue</street>
<city>Maiden</city>
<country>England</country>
<postcode>IM6 66B</postcode>
</Address>
class Address(xml_models.Model):
id=xml_models.IntField(xpath="/Address/@id")
number = xml_models.IntField(xpath="/Address/number")
street = xml_models.CharField(xpath="/Address/street")
city = xml_models.CharField(xpath="/Address/city")
country = xml_models.CharField(xpath="/Address/country")
postcode = xml_models.CharField(xpath="/Address/postcode")
finders = {(id,): 'http://adresses/%s'}
This example would be used as follows:-
>>> address = Address.objects.get(id=2)
>>> print "address is %s, %s" % (address.number, address.street)
"22, Acacia Avenue"
# Heritage
This project is a fork of [Django REST Models](http://djangorestmodel.sourceforge.net/)
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
xml_models2-0.10.0.zip
(13.5 kB
view hashes)
Built Distribution
Close
Hashes for xml_models2-0.10.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 89493bc65c849755a029db201b10b8086f8dd5f7ecaac31d7f11d34eb6b2dec5 |
|
MD5 | 570a047b3d4f2ec99dacb986f846ddd4 |
|
BLAKE2b-256 | 1052feb9f6a14438e1650ce9c6c766e076202e77b55e763e5b89e0a1c316bfe5 |