IMPORTANT NOTICE: I am still working on this project. Slowly, but I hope that it should be releasable by mid-2019.
PyDiggy
Dgraph to Python object mapper
Free software: MIT license
EXAMPLE
# ./examples/__init__
from .basic import * # noqa
# ./examples/basic.py
from __future__ import annotations
from pydiggy import Node
from typing import List
class Region(Node):
area: int
population: int
name: str
borders: List[Region]
CLI
Point the CLI utility at an existing module to generate a Dgraph schema.
$ python3 -m pydiggy generate examples
Generating schema for: examples
Nodes found: (1)
- Region
Your schema:
~~~~~~~~
Region: bool @index(bool) .
_type: string .
area: int .
borders: uid .
name: string .
population: int .
~~~~~~~~
GENERATE MUTATIONS
from pydiggy import generate_mutation, Facets
por = Region(uid=0x11, name="Portugal")
spa = Region(uid=0x12, name="Spain")
gas = Region(uid=0x13, name="Gascony")
mar = Region(uid=0x14, name="Marseilles")
por.borders = [spa]
spa.borders = [por, gas, mar]
gas.borders = [Facets(spa, foo='bar', hello='world'), mar]
mar.borders = [spa, gas]
por.stage()
spa.stage()
gas.stage()
mar.stage()
print(generate_mutation())
The result:
{
set {
<0x11> <Region> "true" .
<0x11> <_type> "Region" .
<0x11> <name> "Portugal" .
<0x11> <borders> <0x12> .
<0x12> <Region> "true" .
<0x12> <_type> "Region" .
<0x12> <name> "Spain" .
<0x12> <borders> <0x11> .
<0x12> <borders> <0x13> .
<0x12> <borders> <0x14> .
<0x13> <Region> "true" .
<0x13> <_type> "Region" .
<0x13> <name> "Gascony" .
<0x13> <borders> <0x12> (foo="bar", hello="world") .
<0x13> <borders> <0x14> .
<0x14> <Region> "true" .
<0x14> <_type> "Region" .
<0x14> <name> "Marseilles" .
<0x14> <borders> <0x12> .
<0x14> <borders> <0x13> .
}
}
HYDATE FROM JSON TO PYTHON OBJECTS
Given some response from Dgraph:
{
"data": {
"allRegions": [
{
"uid": "0x11",
"_type": "Region",
"name": "Portugal",
"borders": [
{
"uid": "0x12",
"_type": "Region",
"name": "Spain"
}
]
},
{
"uid": "0x12",
"_type": "Region",
"name": "Spain",
"borders": [
{
"uid": "0x11",
"_type": "Region",
"name": "Portugal"
},
{
"uid": "0x13",
"_type": "Region",
"name": "Gascony"
},
{
"uid": "0x14",
"_type": "Region",
"name": "Marseilles"
}
]
},
{
"uid": "0x13",
"_type": "Region",
"name": "Gascony",
"borders": [
{
"uid": "0x12",
"_type": "Region",
"name": "Spain",
"borders|foo": "bar",
"borders|hello": "world"
},
{
"uid": "0x14",
"_type": "Region",
"name": "Marseilles"
}
]
},
{
"uid": "0x14",
"_type": "Region",
"name": "Marseilles",
"borders": [
{
"uid": "0x12",
"_type": "Region",
"name": "Spain"
},
{
"uid": "0x13",
"_type": "Region",
"name": "Gascony"
}
]
}
]
},
"extensions": {
"server_latency": {
"parsing_ns": 23727,
"processing_ns": 2000535,
"encoding_ns": 7803450
},
"txn": {
"start_ts": 117,
"lin_read": {
"ids": {
"1": 49
}
}
}
}
}
We can turn it into some Python objects:
>>> data = hydrate(retrieved_data)
{'allRegions': [<Region:17>, <Region:18>, <Region:19>, <Region:20>]}
History
0.1.0 (2018-07-31)
First release on PyPI.
Metadata
Release files for pydiggy 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pydiggy-0.1.0.tar.gz | 22.8 kB | Without provenance | Details for pydiggy-0.1.0.tar.gz |
Release files / pydiggy-0.1.0.tar.gz
| Download URL | pydiggy-0.1.0.tar.gz |
|---|---|
| Size | 22.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9ec07da656933aefbee33f89c0198ba923bfd049f252ba7f2dd6c0d77a607f65
|
|
BLAKE2b-256 checksum How to use checksums |
2d4214f37fd4ddd5f05e21e03e5f468ca4767fe86e705d89daca05d2f02f879a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3
|
Security for pydiggy 0.1.0
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.