mo-dots


Namemo-dots JSON
Version 3.149.20327 PyPI version JSON
download
home_pagehttps://github.com/klahnakoski/mo-dots
SummaryMore Dots! Dot-access to Python dicts like Javascript
upload_time2020-11-22 04:19:40
maintainer
docs_urlNone
authorKyle Lahnakoski
requires_python
licenseMPL 2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # More Dots!


|Branch      |Status   |
|------------|---------|
|master      | [![Build Status](https://travis-ci.org/klahnakoski/mo-dots.svg?branch=master)](https://travis-ci.org/klahnakoski/mo-dots) |
|dev         | [![Build Status](https://travis-ci.org/klahnakoski/mo-dots.svg?branch=dev)](https://travis-ci.org/klahnakoski/mo-dots)  [![Coverage Status](https://coveralls.io/repos/github/klahnakoski/mo-dots/badge.svg?branch=dev)](https://coveralls.io/github/klahnakoski/mo-dots?branch=dev)  |



## Overview

This library defines a `Data` class that can serve as a replacement for `dict`, with additional features. 

    >>> from mo_dots import to_data, Data

*See the [full documentation](https://github.com/klahnakoski/mo-dots/tree/dev/docs) for all the features of `mo-dots`*

### Easy Definition

Define `Data` using named parameters, just like you would a `dict`

    >>> Data(b=42, c="hello world")
    Data({'b': 42, 'c': 'hello world'})

You can also wrap existing `dict`s so they can be used like `Data`

    >>> to_data({'b': 42, 'c': 'hello world'})
    Data({'b': 42, 'c': 'hello world'})

### Dot Access

Access properties with attribute dots: `a.b == a["b"]`. You have probably seen this before.

### Path Access

Access properties by dot-delimited path.

	>>> a = to_data({"b": {"c": 42}})
	>>> a["b.c"] == 42
	True

### Safe Access

If a property does not exist then return `Null` rather than raising an error.

	>>> a = Data()
	a == {}
	>>> a.b == None
	True
	>>> a.b.c == None
	True
	>>> a[None] == None
	True

### Path assignment

No need to make intermediate `dicts`

    >>> a = Data()
    a == {}
    >>> a["b.c"] = 42   # same as a.b.c = 42
    a == {"b": {"c": 42}}

### Path accumulation

Use `+=` to add to a property; default zero (`0`)

    >>> a = Data()
    a == {}
    >>> a.b.c += 1
    a == {"b": {"c": 1}}
    >>> a.b.c += 42
    a == {"b": {"c": 43}}

Use `+=` with a list ([]) to append to a list; default empty list (`[]`)

    >>> a = Data()
    a == {}
    >>> a.b.c += [1]
    a == {"b": {"c": [1]}}
    >>> a.b.c += [42]
    a == {"b": {"c": [1, 42]}}

## Serializing to JSON

The standard Python JSON library does not recognize `Data` as serializable.  You may overcome this by providing `default=from_data`; which converts the data structures in this module into Python primitives of the same. 

    from mo_dots import from_data, to_data
    
    s = to_data({"a": ["b", 1]})
    result = json.dumps(s, default=from_data)  

Alternatively, you may consider [mo-json](https://pypi.org/project/mo-json/) which has a function `value2json` that converts a larger number of data structures into JSON.


## Summary

This library is the basis for a data transformation algebra: We want a succinct way of transforming data in Python. We want operations on data to result in yet more data. We do not want data operations to raise exceptions. This library is solves Python's lack of consistency (lack of closure) under the dot (`.`) and slice `[::]` operators when operating on data objects. 

[Full documentation](https://github.com/klahnakoski/mo-dots/tree/dev/docs)
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/klahnakoski/mo-dots",
    "name": "mo-dots",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "Kyle Lahnakoski",
    "author_email": "kyle@lahnakoski.com",
    "download_url": "https://files.pythonhosted.org/packages/4d/fb/c1e58c1fde673f813c89ef43344ac62ecac37d2e5c1d575109d6d7abb670/mo-dots-3.149.20327.tar.gz",
    "platform": "",
    "description": "# More Dots!\n\n\n|Branch      |Status   |\n|------------|---------|\n|master      | [![Build Status](https://travis-ci.org/klahnakoski/mo-dots.svg?branch=master)](https://travis-ci.org/klahnakoski/mo-dots) |\n|dev         | [![Build Status](https://travis-ci.org/klahnakoski/mo-dots.svg?branch=dev)](https://travis-ci.org/klahnakoski/mo-dots)  [![Coverage Status](https://coveralls.io/repos/github/klahnakoski/mo-dots/badge.svg?branch=dev)](https://coveralls.io/github/klahnakoski/mo-dots?branch=dev)  |\n\n\n\n## Overview\n\nThis library defines a `Data` class that can serve as a replacement for `dict`, with additional features. \n\n    >>> from mo_dots import to_data, Data\n\n*See the [full documentation](https://github.com/klahnakoski/mo-dots/tree/dev/docs) for all the features of `mo-dots`*\n\n### Easy Definition\n\nDefine `Data` using named parameters, just like you would a `dict`\n\n    >>> Data(b=42, c=\"hello world\")\n    Data({'b': 42, 'c': 'hello world'})\n\nYou can also wrap existing `dict`s so they can be used like `Data`\n\n    >>> to_data({'b': 42, 'c': 'hello world'})\n    Data({'b': 42, 'c': 'hello world'})\n\n### Dot Access\n\nAccess properties with attribute dots: `a.b == a[\"b\"]`. You have probably seen this before.\n\n### Path Access\n\nAccess properties by dot-delimited path.\n\n\t>>> a = to_data({\"b\": {\"c\": 42}})\n\t>>> a[\"b.c\"] == 42\n\tTrue\n\n### Safe Access\n\nIf a property does not exist then return `Null` rather than raising an error.\n\n\t>>> a = Data()\n\ta == {}\n\t>>> a.b == None\n\tTrue\n\t>>> a.b.c == None\n\tTrue\n\t>>> a[None] == None\n\tTrue\n\n### Path assignment\n\nNo need to make intermediate `dicts`\n\n    >>> a = Data()\n    a == {}\n    >>> a[\"b.c\"] = 42   # same as a.b.c = 42\n    a == {\"b\": {\"c\": 42}}\n\n### Path accumulation\n\nUse `+=` to add to a property; default zero (`0`)\n\n    >>> a = Data()\n    a == {}\n    >>> a.b.c += 1\n    a == {\"b\": {\"c\": 1}}\n    >>> a.b.c += 42\n    a == {\"b\": {\"c\": 43}}\n\nUse `+=` with a list ([]) to append to a list; default empty list (`[]`)\n\n    >>> a = Data()\n    a == {}\n    >>> a.b.c += [1]\n    a == {\"b\": {\"c\": [1]}}\n    >>> a.b.c += [42]\n    a == {\"b\": {\"c\": [1, 42]}}\n\n## Serializing to JSON\n\nThe standard Python JSON library does not recognize `Data` as serializable.  You may overcome this by providing `default=from_data`; which converts the data structures in this module into Python primitives of the same. \n\n    from mo_dots import from_data, to_data\n    \n    s = to_data({\"a\": [\"b\", 1]})\n    result = json.dumps(s, default=from_data)  \n\nAlternatively, you may consider [mo-json](https://pypi.org/project/mo-json/) which has a function `value2json` that converts a larger number of data structures into JSON.\n\n\n## Summary\n\nThis library is the basis for a data transformation algebra: We want a succinct way of transforming data in Python. We want operations on data to result in yet more data. We do not want data operations to raise exceptions. This library is solves Python's lack of consistency (lack of closure) under the dot (`.`) and slice `[::]` operators when operating on data objects. \n\n[Full documentation](https://github.com/klahnakoski/mo-dots/tree/dev/docs)",
    "bugtrack_url": null,
    "license": "MPL 2.0",
    "summary": "More Dots! Dot-access to Python dicts like Javascript",
    "version": "3.149.20327",
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "3bce2ff2bfaaf6ffe26056c75a58d59c",
                "sha256": "12e284fe085d0b54af86b00e5ae23fcff76d08909c980bd6b74d9ad919c28707"
            },
            "downloads": -1,
            "filename": "mo-dots-3.149.20327.tar.gz",
            "has_sig": false,
            "md5_digest": "3bce2ff2bfaaf6ffe26056c75a58d59c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 17464,
            "upload_time": "2020-11-22T04:19:40",
            "upload_time_iso_8601": "2020-11-22T04:19:40.631491Z",
            "url": "https://files.pythonhosted.org/packages/4d/fb/c1e58c1fde673f813c89ef43344ac62ecac37d2e5c1d575109d6d7abb670/mo-dots-3.149.20327.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-11-22 04:19:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "klahnakoski",
    "error": "Could not fetch GitHub repository",
    "lcname": "mo-dots"
}
        
Elapsed time: 0.19101s