relations-rest


Namerelations-rest JSON
Version 0.5.0 PyPI version JSON
download
home_pagehttps://github.com/relations-dil/python-relations-rest
SummaryAPI Modeling through REST
upload_time2022-12-10 22:21:22
maintainer
docs_urlNone
authorGaffer Fitch
requires_python
license
keywords
VCS
bugtrack_url
requirements relations-restx requests ptvsd coverage pylint
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # relations-rest

API Modeling through REST

Relations overall is designed to be a simple, straight forward, flexible DIL (data interface layer).

Quite different from other DIL's, it has the singular, microservice based purpose to:
- Create models with very little code, independent of backends
- Create CRUD API with a database backend from those models with very little code
- Create microservices to use those same models but with that CRUD API as the backend

Ya, that last one is kinda new I guess and the purpose of this package.

Say we create a service, composed of microservices, which in turn is to be consumed by other services made of microservices.

You should only need to define the model once. Your conceptual structure is the same, to the DB, the API, and anything using that API. You shouldn't have say that structure over and over. You shouldn't have to define CRUD endpoints over and over. That's so boring, tedious, and unnecessary.

Furthermore, the conceptual structure is based not the backend of what you've going to use at that moment of time (scaling matters) but on the relations, how the pieces interact. If you know the structure of the data, that's all you need to interact with the data.

So with Relations, Models and Fields are defined independent of any backend, which instead is set at runtime. So the API will use a DB, everything else will use that API.

This is what allows those same models to use a CRUD API as a backend.

Don't have great docs yet so I've included some of the unittests to show what's possible.

# Example

## define

```python

import relations
import relations_pymysql

# The source is a string, the backend of which is defined at runtime

class SourceModel(relations.Model):
    SOURCE = "RestSource"

class Simple(SourceModel):
    id = int
    name = str

class Plain(SourceModel):
    ID = None # This table has no primary id field
    simple_id = int
    name = str

# This makes Simple a parent of Plain

relations.OneToMany(Simple, Plain)

class Meta(SourceModel):
    id = int
    name = str
    flag = bool
    spend = float
    people = set # JSON storage
    stuff = list # JSON stroage
    things = dict, {"extract": "for__0____1"} # Extracts things["for"][0][-1] as a virtual column
    push = str, {"inject": "stuff___1__relations.io____1"} # Injects this value into stuff[-1]["relations.io"]["1"]

def subnet_attr(values, value):

    values["address"] = str(value)
    min_ip = value[0]
    max_ip = value[-1]
    values["min_address"] = str(min_ip)
    values["min_value"] = int(min_ip)
    values["max_address"] = str(max_ip)
    values["max_value"] = int(max_ip)

class Net(SourceModel):

    id = int
    ip = ipaddress.IPv4Address, { # The field type is that of a class, with the storage being JSON
        "attr": {
            "compressed": "address", # Storge compressed attr as address key in JSON
            "__int__": "value"       # Storge int() as value key in JSON
        },
        "init": "address",           # Initilize with address from JSON
        "titles": "address",         # Use address from JSON as the how to list this field
        "extract": {
            "address": str,          # Extract address as virtual column
            "value": int             # Extra value as virtual column
        }
    }
    subnet = ipaddress.IPv4Network, {
        "attr": subnet_attr,
        "init": "address",
        "titles": "address"
    }

    TITLES = "ip__address" # When listing, use ip["address"] as display value
    INDEX = "ip__value"    # Create an index on the virtual column ip __value

class Unit(SourceModel):
    id = int
    name = str, {"format": "fancy"}

class Test(SourceModel):
    id = int
    unit_id = int
    name = str, {"format": "shmancy"}

class Case(SourceModel):
    id = int
    test_id = int
    name = str

relations.OneToMany(Unit, Test)
relations.OneToOne(Test, Case)

# With this statement, all the above models now how this API endpoint as the backend

self.source = relations_pymysql.Source("RestSource", "http://localhost")
```

## create

```python
simple = Simple("sure")
simple.plain.add("fine")

simple.create()

self.assertEqual(simple.id, 1)
self.assertEqual(simple._action, "update")
self.assertEqual(simple._record._action, "update")
self.assertEqual(simple.plain[0].simple_id, 1)
self.assertEqual(simple.plain._action, "update")
self.assertEqual(simple.plain[0]._record._action, "update")

simples = Simple.bulk().add("ya").create()

self.assertEqual(simples._models, [])

yep = Meta("yep", True, 3.50, {"tom", "mary"}, [1, None], {"a": 1, "for": [{"1": "yep"}]}, "sure").create()
self.assertTrue(Meta.one(yep.id).flag)

nope = Meta("nope", False).create()
self.assertFalse(Meta.one(nope.id).flag)

# This checks teh mock source of the API the models are accessing

self.assertEqual(self.resource.ids, {
    "simple": 2,
    "plain": 1,
    "meta": 2
})

self.assertEqual(self.resource.data, {
    "simple": {
        1: {
            "id": 1,
            "name": "sure"
        },
        2: {
            "id": 2,
            "name": "ya"
        }
    },
    "plain": {
        1: {
            "simple_id": 1,
            "name": "fine"
        }
    },
    "meta": {
        1: {
            "id": 1,
            "name": "yep",
            "flag": True,
            "spend": 3.50,
            "people": ["mary", "tom"],
            "stuff": [1, {"relations.io": {"1": "sure"}}],
            "things": {"a": 1, "for": [{"1": "yep"}]},
            "things__for__0____1": "yep"
        },
        2: {
            "id": 2,
            "name": "nope",
            "flag": False,
            "spend": None,
            "people": [],
            "stuff": [{"relations.io": {"1": None}}],
            "things": {},
            "things__for__0____1": None
        }
    }
})
```

## retrieve

```python
Unit([["people"], ["stuff"]]).create()

models = Unit.one(name__in=["people", "stuff"])
self.assertRaisesRegex(relations.ModelError, "unit: more than one retrieved", models.retrieve)

model = Unit.one(name="things")
self.assertRaisesRegex(relations.ModelError, "unit: none retrieved", model.retrieve)

self.assertIsNone(model.retrieve(False))

unit = Unit.one(name="people")

self.assertEqual(unit.id, 1)
self.assertEqual(unit._action, "update")
self.assertEqual(unit._record._action, "update")

unit = Unit.one(like="p")

self.assertEqual(unit.id, 1)
self.assertEqual(unit._action, "update")
self.assertEqual(unit._record._action, "update")

unit.test.add("things")[0].case.add("persons")
unit.update()

Meta("yep", True, 1.1, {"tom"}, [1, None], {"a": 1}).create()
model = Meta.one(name="yep")

self.assertEqual(model.flag, True)
self.assertEqual(model.spend, 1.1)
self.assertEqual(model.people, {"tom"})
self.assertEqual(model.stuff, [1, {"relations.io": {"1": None}}])
self.assertEqual(model.things, {"a": 1})

self.assertEqual(Unit.many().name, ["people", "stuff"])
self.assertEqual(Unit.many().sort("-name").name, ["stuff", "people"])
self.assertEqual(Unit.many().sort("-name").limit(1, 1).name, ["people"])
self.assertEqual(Unit.many().sort("-name").limit(0).name, [])
self.assertEqual(Unit.many(name="people").limit(1).name, ["people"])

Meta("dive", people={"tom", "mary"}, stuff=[1, 2, 3, None], things={"a": {"b": [1, 2], "c": "sure"}, "4": 5, "for": [{"1": "yep"}]}).create()

model = Meta.many(people={"tom", "mary"})
self.assertEqual(model[0].name, "dive")

model = Meta.many(stuff=[1, 2, 3, {"relations.io": {"1": None}}])
self.assertEqual(model[0].name, "dive")

model = Meta.many(things={"a": {"b": [1, 2], "c": "sure"}, "4": 5, "for": [{"1": "yep"}]})
self.assertEqual(model[0].name, "dive")

model = Meta.many(stuff__1=2)
self.assertEqual(model[0].name, "dive")

model = Meta.many(things__a__b__0=1)
self.assertEqual(model[0].name, "dive")

model = Meta.many(things__a__c__like="su")
self.assertEqual(model[0].name, "dive")

model = Meta.many(things__a__d__null=True)
self.assertEqual(model[0].name, "dive")

model = Meta.many(things____4=5)
self.assertEqual(model[0].name, "dive")

model = Meta.many(things__a__b__0__gt=1)
self.assertEqual(len(model), 0)

model = Meta.many(things__a__c__notlike="su")
self.assertEqual(len(model), 0)

model = Meta.many(things__a__d__null=False)
self.assertEqual(len(model), 0)

model = Meta.many(things___4=6)
self.assertEqual(len(model), 0)

model = Meta.many(things__a__b__has=1)
self.assertEqual(len(model), 1)

model = Meta.many(things__a__b__has=3)
self.assertEqual(len(model), 0)

model = Meta.many(things__a__b__any=[1, 3])
self.assertEqual(len(model), 1)

model = Meta.many(things__a__b__any=[4, 3])
self.assertEqual(len(model), 0)

model = Meta.many(things__a__b__all=[2, 1])
self.assertEqual(len(model), 1)

model = Meta.many(things__a__b__all=[3, 2, 1])
self.assertEqual(len(model), 0)

model = Meta.many(people__has="mary")
self.assertEqual(len(model), 1)

model = Meta.many(people__has="dick")
self.assertEqual(len(model), 0)

model = Meta.many(people__any=["mary", "dick"])
self.assertEqual(len(model), 1)

model = Meta.many(people__any=["harry", "dick"])
self.assertEqual(len(model), 0)

model = Meta.many(people__all=["mary", "tom"])
self.assertEqual(len(model), 1)

model = Meta.many(people__all=["tom", "dick", "mary"])
self.assertEqual(len(model), 0)

Net(ip="1.2.3.4", subnet="1.2.3.0/24").create()
Net().create()

model = Net.many(like='1.2.3.')
self.assertEqual(model[0].ip.compressed, "1.2.3.4")

model = Net.many(ip__address__like='1.2.3.')
self.assertEqual(model[0].ip.compressed, "1.2.3.4")

model = Net.many(ip__value__gt=int(ipaddress.IPv4Address('1.2.3.0')))
self.assertEqual(model[0].ip.compressed, "1.2.3.4")

model = Net.many(subnet__address__like='1.2.3.')
self.assertEqual(model[0].ip.compressed, "1.2.3.4")

model = Net.many(subnet__min_value=int(ipaddress.IPv4Address('1.2.3.0')))
self.assertEqual(model[0].ip.compressed, "1.2.3.4")

model = Net.many(ip__address__notlike='1.2.3.')
self.assertEqual(len(model), 0)

model = Net.many(ip__value__lt=int(ipaddress.IPv4Address('1.2.3.0')))
self.assertEqual(len(model), 0)

model = Net.many(subnet__address__notlike='1.2.3.')
self.assertEqual(len(model), 0)

model = Net.many(subnet__max_value=int(ipaddress.IPv4Address('1.2.3.0')))
self.assertEqual(len(model), 0)
```

## update

```python
Unit([["people"], ["stuff"]]).create()

unit = Unit.many(id=2).set(name="things")

self.assertEqual(unit.update(), 1)

unit = Unit.one(2)

unit.name = "thing"
unit.test.add("moar")

self.assertEqual(unit.update(), 1)
self.assertEqual(unit.name, "thing")
self.assertEqual(unit.test[0].id, 1)
self.assertEqual(unit.test[0].name, "moar")

plain = Plain.one()
self.assertRaisesRegex(relations.ModelError, "plain: nothing to update from", plain.update)

net = Net(ip="1.2.3.4", subnet="1.2.3.0/24").create()

Net.one(net.id).set(ip="5.6.7.8").update()
self.assertEqual(Net.one(net.id).ip.compressed, "5.6.7.8")

meta = Meta("dive", people={"tom", "mary"}, stuff=[1, 2, 3, None], things={"a": {"b": [1, 2], "c": "sure"}, "4": 5, "for": [{"1": "yep"}]}).create()

meta.things["a"]["b"][0] = 3
self.assertEqual(meta.things__a__b__0, 3)

meta.update()

meta = Meta.one(meta.id)

self.assertEqual(meta.things__a__b__0, 3)
```

## delete

```python
unit = Unit("people")
unit.test.add("stuff").add("things")
unit.create()

self.assertEqual(Test.one(id=2).delete(), 1)
self.assertEqual(len(Test.many()), 1)

self.assertEqual(Unit.one(1).test.delete(), 1)
self.assertEqual(Unit.one(1).retrieve().delete(), 1)
self.assertEqual(len(Unit.many()), 0)
self.assertEqual(len(Test.many()), 0)

plain = Plain(0, "nope").create()
self.assertRaisesRegex(relations.ModelError, "plain: nothing to delete from", plain.delete)
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/relations-dil/python-relations-rest",
    "name": "relations-rest",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Gaffer Fitch",
    "author_email": "relations@gaf3.com",
    "download_url": "https://files.pythonhosted.org/packages/34/c1/c58ef2b1dc5f81c6131046421100a039ce65b4ddaf82661c242e5ff52c70/relations-rest-0.5.0.tar.gz",
    "platform": null,
    "description": "# relations-rest\n\nAPI Modeling through REST\n\nRelations overall is designed to be a simple, straight forward, flexible DIL (data interface layer).\n\nQuite different from other DIL's, it has the singular, microservice based purpose to:\n- Create models with very little code, independent of backends\n- Create CRUD API with a database backend from those models with very little code\n- Create microservices to use those same models but with that CRUD API as the backend\n\nYa, that last one is kinda new I guess and the purpose of this package.\n\nSay we create a service, composed of microservices, which in turn is to be consumed by other services made of microservices.\n\nYou should only need to define the model once. Your conceptual structure is the same, to the DB, the API, and anything using that API. You shouldn't have say that structure over and over. You shouldn't have to define CRUD endpoints over and over. That's so boring, tedious, and unnecessary.\n\nFurthermore, the conceptual structure is based not the backend of what you've going to use at that moment of time (scaling matters) but on the relations, how the pieces interact. If you know the structure of the data, that's all you need to interact with the data.\n\nSo with Relations, Models and Fields are defined independent of any backend, which instead is set at runtime. So the API will use a DB, everything else will use that API.\n\nThis is what allows those same models to use a CRUD API as a backend.\n\nDon't have great docs yet so I've included some of the unittests to show what's possible.\n\n# Example\n\n## define\n\n```python\n\nimport relations\nimport relations_pymysql\n\n# The source is a string, the backend of which is defined at runtime\n\nclass SourceModel(relations.Model):\n    SOURCE = \"RestSource\"\n\nclass Simple(SourceModel):\n    id = int\n    name = str\n\nclass Plain(SourceModel):\n    ID = None # This table has no primary id field\n    simple_id = int\n    name = str\n\n# This makes Simple a parent of Plain\n\nrelations.OneToMany(Simple, Plain)\n\nclass Meta(SourceModel):\n    id = int\n    name = str\n    flag = bool\n    spend = float\n    people = set # JSON storage\n    stuff = list # JSON stroage\n    things = dict, {\"extract\": \"for__0____1\"} # Extracts things[\"for\"][0][-1] as a virtual column\n    push = str, {\"inject\": \"stuff___1__relations.io____1\"} # Injects this value into stuff[-1][\"relations.io\"][\"1\"]\n\ndef subnet_attr(values, value):\n\n    values[\"address\"] = str(value)\n    min_ip = value[0]\n    max_ip = value[-1]\n    values[\"min_address\"] = str(min_ip)\n    values[\"min_value\"] = int(min_ip)\n    values[\"max_address\"] = str(max_ip)\n    values[\"max_value\"] = int(max_ip)\n\nclass Net(SourceModel):\n\n    id = int\n    ip = ipaddress.IPv4Address, { # The field type is that of a class, with the storage being JSON\n        \"attr\": {\n            \"compressed\": \"address\", # Storge compressed attr as address key in JSON\n            \"__int__\": \"value\"       # Storge int() as value key in JSON\n        },\n        \"init\": \"address\",           # Initilize with address from JSON\n        \"titles\": \"address\",         # Use address from JSON as the how to list this field\n        \"extract\": {\n            \"address\": str,          # Extract address as virtual column\n            \"value\": int             # Extra value as virtual column\n        }\n    }\n    subnet = ipaddress.IPv4Network, {\n        \"attr\": subnet_attr,\n        \"init\": \"address\",\n        \"titles\": \"address\"\n    }\n\n    TITLES = \"ip__address\" # When listing, use ip[\"address\"] as display value\n    INDEX = \"ip__value\"    # Create an index on the virtual column ip __value\n\nclass Unit(SourceModel):\n    id = int\n    name = str, {\"format\": \"fancy\"}\n\nclass Test(SourceModel):\n    id = int\n    unit_id = int\n    name = str, {\"format\": \"shmancy\"}\n\nclass Case(SourceModel):\n    id = int\n    test_id = int\n    name = str\n\nrelations.OneToMany(Unit, Test)\nrelations.OneToOne(Test, Case)\n\n# With this statement, all the above models now how this API endpoint as the backend\n\nself.source = relations_pymysql.Source(\"RestSource\", \"http://localhost\")\n```\n\n## create\n\n```python\nsimple = Simple(\"sure\")\nsimple.plain.add(\"fine\")\n\nsimple.create()\n\nself.assertEqual(simple.id, 1)\nself.assertEqual(simple._action, \"update\")\nself.assertEqual(simple._record._action, \"update\")\nself.assertEqual(simple.plain[0].simple_id, 1)\nself.assertEqual(simple.plain._action, \"update\")\nself.assertEqual(simple.plain[0]._record._action, \"update\")\n\nsimples = Simple.bulk().add(\"ya\").create()\n\nself.assertEqual(simples._models, [])\n\nyep = Meta(\"yep\", True, 3.50, {\"tom\", \"mary\"}, [1, None], {\"a\": 1, \"for\": [{\"1\": \"yep\"}]}, \"sure\").create()\nself.assertTrue(Meta.one(yep.id).flag)\n\nnope = Meta(\"nope\", False).create()\nself.assertFalse(Meta.one(nope.id).flag)\n\n# This checks teh mock source of the API the models are accessing\n\nself.assertEqual(self.resource.ids, {\n    \"simple\": 2,\n    \"plain\": 1,\n    \"meta\": 2\n})\n\nself.assertEqual(self.resource.data, {\n    \"simple\": {\n        1: {\n            \"id\": 1,\n            \"name\": \"sure\"\n        },\n        2: {\n            \"id\": 2,\n            \"name\": \"ya\"\n        }\n    },\n    \"plain\": {\n        1: {\n            \"simple_id\": 1,\n            \"name\": \"fine\"\n        }\n    },\n    \"meta\": {\n        1: {\n            \"id\": 1,\n            \"name\": \"yep\",\n            \"flag\": True,\n            \"spend\": 3.50,\n            \"people\": [\"mary\", \"tom\"],\n            \"stuff\": [1, {\"relations.io\": {\"1\": \"sure\"}}],\n            \"things\": {\"a\": 1, \"for\": [{\"1\": \"yep\"}]},\n            \"things__for__0____1\": \"yep\"\n        },\n        2: {\n            \"id\": 2,\n            \"name\": \"nope\",\n            \"flag\": False,\n            \"spend\": None,\n            \"people\": [],\n            \"stuff\": [{\"relations.io\": {\"1\": None}}],\n            \"things\": {},\n            \"things__for__0____1\": None\n        }\n    }\n})\n```\n\n## retrieve\n\n```python\nUnit([[\"people\"], [\"stuff\"]]).create()\n\nmodels = Unit.one(name__in=[\"people\", \"stuff\"])\nself.assertRaisesRegex(relations.ModelError, \"unit: more than one retrieved\", models.retrieve)\n\nmodel = Unit.one(name=\"things\")\nself.assertRaisesRegex(relations.ModelError, \"unit: none retrieved\", model.retrieve)\n\nself.assertIsNone(model.retrieve(False))\n\nunit = Unit.one(name=\"people\")\n\nself.assertEqual(unit.id, 1)\nself.assertEqual(unit._action, \"update\")\nself.assertEqual(unit._record._action, \"update\")\n\nunit = Unit.one(like=\"p\")\n\nself.assertEqual(unit.id, 1)\nself.assertEqual(unit._action, \"update\")\nself.assertEqual(unit._record._action, \"update\")\n\nunit.test.add(\"things\")[0].case.add(\"persons\")\nunit.update()\n\nMeta(\"yep\", True, 1.1, {\"tom\"}, [1, None], {\"a\": 1}).create()\nmodel = Meta.one(name=\"yep\")\n\nself.assertEqual(model.flag, True)\nself.assertEqual(model.spend, 1.1)\nself.assertEqual(model.people, {\"tom\"})\nself.assertEqual(model.stuff, [1, {\"relations.io\": {\"1\": None}}])\nself.assertEqual(model.things, {\"a\": 1})\n\nself.assertEqual(Unit.many().name, [\"people\", \"stuff\"])\nself.assertEqual(Unit.many().sort(\"-name\").name, [\"stuff\", \"people\"])\nself.assertEqual(Unit.many().sort(\"-name\").limit(1, 1).name, [\"people\"])\nself.assertEqual(Unit.many().sort(\"-name\").limit(0).name, [])\nself.assertEqual(Unit.many(name=\"people\").limit(1).name, [\"people\"])\n\nMeta(\"dive\", people={\"tom\", \"mary\"}, stuff=[1, 2, 3, None], things={\"a\": {\"b\": [1, 2], \"c\": \"sure\"}, \"4\": 5, \"for\": [{\"1\": \"yep\"}]}).create()\n\nmodel = Meta.many(people={\"tom\", \"mary\"})\nself.assertEqual(model[0].name, \"dive\")\n\nmodel = Meta.many(stuff=[1, 2, 3, {\"relations.io\": {\"1\": None}}])\nself.assertEqual(model[0].name, \"dive\")\n\nmodel = Meta.many(things={\"a\": {\"b\": [1, 2], \"c\": \"sure\"}, \"4\": 5, \"for\": [{\"1\": \"yep\"}]})\nself.assertEqual(model[0].name, \"dive\")\n\nmodel = Meta.many(stuff__1=2)\nself.assertEqual(model[0].name, \"dive\")\n\nmodel = Meta.many(things__a__b__0=1)\nself.assertEqual(model[0].name, \"dive\")\n\nmodel = Meta.many(things__a__c__like=\"su\")\nself.assertEqual(model[0].name, \"dive\")\n\nmodel = Meta.many(things__a__d__null=True)\nself.assertEqual(model[0].name, \"dive\")\n\nmodel = Meta.many(things____4=5)\nself.assertEqual(model[0].name, \"dive\")\n\nmodel = Meta.many(things__a__b__0__gt=1)\nself.assertEqual(len(model), 0)\n\nmodel = Meta.many(things__a__c__notlike=\"su\")\nself.assertEqual(len(model), 0)\n\nmodel = Meta.many(things__a__d__null=False)\nself.assertEqual(len(model), 0)\n\nmodel = Meta.many(things___4=6)\nself.assertEqual(len(model), 0)\n\nmodel = Meta.many(things__a__b__has=1)\nself.assertEqual(len(model), 1)\n\nmodel = Meta.many(things__a__b__has=3)\nself.assertEqual(len(model), 0)\n\nmodel = Meta.many(things__a__b__any=[1, 3])\nself.assertEqual(len(model), 1)\n\nmodel = Meta.many(things__a__b__any=[4, 3])\nself.assertEqual(len(model), 0)\n\nmodel = Meta.many(things__a__b__all=[2, 1])\nself.assertEqual(len(model), 1)\n\nmodel = Meta.many(things__a__b__all=[3, 2, 1])\nself.assertEqual(len(model), 0)\n\nmodel = Meta.many(people__has=\"mary\")\nself.assertEqual(len(model), 1)\n\nmodel = Meta.many(people__has=\"dick\")\nself.assertEqual(len(model), 0)\n\nmodel = Meta.many(people__any=[\"mary\", \"dick\"])\nself.assertEqual(len(model), 1)\n\nmodel = Meta.many(people__any=[\"harry\", \"dick\"])\nself.assertEqual(len(model), 0)\n\nmodel = Meta.many(people__all=[\"mary\", \"tom\"])\nself.assertEqual(len(model), 1)\n\nmodel = Meta.many(people__all=[\"tom\", \"dick\", \"mary\"])\nself.assertEqual(len(model), 0)\n\nNet(ip=\"1.2.3.4\", subnet=\"1.2.3.0/24\").create()\nNet().create()\n\nmodel = Net.many(like='1.2.3.')\nself.assertEqual(model[0].ip.compressed, \"1.2.3.4\")\n\nmodel = Net.many(ip__address__like='1.2.3.')\nself.assertEqual(model[0].ip.compressed, \"1.2.3.4\")\n\nmodel = Net.many(ip__value__gt=int(ipaddress.IPv4Address('1.2.3.0')))\nself.assertEqual(model[0].ip.compressed, \"1.2.3.4\")\n\nmodel = Net.many(subnet__address__like='1.2.3.')\nself.assertEqual(model[0].ip.compressed, \"1.2.3.4\")\n\nmodel = Net.many(subnet__min_value=int(ipaddress.IPv4Address('1.2.3.0')))\nself.assertEqual(model[0].ip.compressed, \"1.2.3.4\")\n\nmodel = Net.many(ip__address__notlike='1.2.3.')\nself.assertEqual(len(model), 0)\n\nmodel = Net.many(ip__value__lt=int(ipaddress.IPv4Address('1.2.3.0')))\nself.assertEqual(len(model), 0)\n\nmodel = Net.many(subnet__address__notlike='1.2.3.')\nself.assertEqual(len(model), 0)\n\nmodel = Net.many(subnet__max_value=int(ipaddress.IPv4Address('1.2.3.0')))\nself.assertEqual(len(model), 0)\n```\n\n## update\n\n```python\nUnit([[\"people\"], [\"stuff\"]]).create()\n\nunit = Unit.many(id=2).set(name=\"things\")\n\nself.assertEqual(unit.update(), 1)\n\nunit = Unit.one(2)\n\nunit.name = \"thing\"\nunit.test.add(\"moar\")\n\nself.assertEqual(unit.update(), 1)\nself.assertEqual(unit.name, \"thing\")\nself.assertEqual(unit.test[0].id, 1)\nself.assertEqual(unit.test[0].name, \"moar\")\n\nplain = Plain.one()\nself.assertRaisesRegex(relations.ModelError, \"plain: nothing to update from\", plain.update)\n\nnet = Net(ip=\"1.2.3.4\", subnet=\"1.2.3.0/24\").create()\n\nNet.one(net.id).set(ip=\"5.6.7.8\").update()\nself.assertEqual(Net.one(net.id).ip.compressed, \"5.6.7.8\")\n\nmeta = Meta(\"dive\", people={\"tom\", \"mary\"}, stuff=[1, 2, 3, None], things={\"a\": {\"b\": [1, 2], \"c\": \"sure\"}, \"4\": 5, \"for\": [{\"1\": \"yep\"}]}).create()\n\nmeta.things[\"a\"][\"b\"][0] = 3\nself.assertEqual(meta.things__a__b__0, 3)\n\nmeta.update()\n\nmeta = Meta.one(meta.id)\n\nself.assertEqual(meta.things__a__b__0, 3)\n```\n\n## delete\n\n```python\nunit = Unit(\"people\")\nunit.test.add(\"stuff\").add(\"things\")\nunit.create()\n\nself.assertEqual(Test.one(id=2).delete(), 1)\nself.assertEqual(len(Test.many()), 1)\n\nself.assertEqual(Unit.one(1).test.delete(), 1)\nself.assertEqual(Unit.one(1).retrieve().delete(), 1)\nself.assertEqual(len(Unit.many()), 0)\nself.assertEqual(len(Test.many()), 0)\n\nplain = Plain(0, \"nope\").create()\nself.assertRaisesRegex(relations.ModelError, \"plain: nothing to delete from\", plain.delete)\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "API Modeling through REST",
    "version": "0.5.0",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "25859fb4d48c5f6f6e857594766dbf81",
                "sha256": "8e6844efdafbb7157e6969ef1b57ef8a72af460c943cd207d0bb24e78a8b69aa"
            },
            "downloads": -1,
            "filename": "relations_rest-0.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "25859fb4d48c5f6f6e857594766dbf81",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 7080,
            "upload_time": "2022-12-10T22:21:20",
            "upload_time_iso_8601": "2022-12-10T22:21:20.257222Z",
            "url": "https://files.pythonhosted.org/packages/7d/6f/108a730628cf868a513004b377caafacff5bc635f88f93ff6620ff62b0b7/relations_rest-0.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "fd781ea52da72853406e4676d90223b8",
                "sha256": "ab6e39d3dde2e1a1cb8066590a9aa8f937145d84b14e519ec370c290c7eebaaf"
            },
            "downloads": -1,
            "filename": "relations-rest-0.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "fd781ea52da72853406e4676d90223b8",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 10461,
            "upload_time": "2022-12-10T22:21:22",
            "upload_time_iso_8601": "2022-12-10T22:21:22.123231Z",
            "url": "https://files.pythonhosted.org/packages/34/c1/c58ef2b1dc5f81c6131046421100a039ce65b4ddaf82661c242e5ff52c70/relations-rest-0.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-12-10 22:21:22",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "relations-dil",
    "github_project": "python-relations-rest",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "requirements": [
        {
            "name": "relations-restx",
            "specs": [
                [
                    "==",
                    "0.6.2"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    "==",
                    "2.25.1"
                ]
            ]
        },
        {
            "name": "ptvsd",
            "specs": [
                [
                    "==",
                    "4.3.2"
                ]
            ]
        },
        {
            "name": "coverage",
            "specs": [
                [
                    "==",
                    "5.2.1"
                ]
            ]
        },
        {
            "name": "pylint",
            "specs": [
                [
                    "==",
                    "2.5.3"
                ]
            ]
        }
    ],
    "lcname": "relations-rest"
}
        
Elapsed time: 0.02214s