All Projects → jacebrowning → Datafiles

jacebrowning / Datafiles

Licence: other
A file-based ORM for Python dataclasses.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to Datafiles

Cli
A simple, fast, and fun package for building command line apps in Go
Stars: ✭ 16,995 (+14939.82%)
Mutual labels:  json, yaml, toml
Remarshal
Convert between CBOR, JSON, MessagePack, TOML, and YAML
Stars: ✭ 421 (+272.57%)
Mutual labels:  json, yaml, toml
yorm
Automatic object-YAML mapping for Python.
Stars: ✭ 23 (-79.65%)
Mutual labels:  yaml, orm, filesystem
Config
📝 Go config manage(load,get,set). support JSON, YAML, TOML, INI, HCL, ENV and Flags. Multi file load, data override merge, parse ENV var. Go应用配置加载管理,支持多种格式,多文件加载,远程文件加载,支持数据合并,解析环境变量名
Stars: ✭ 225 (+99.12%)
Mutual labels:  json, yaml, toml
Configr
Implements the JSON, INI, YAML and TOML parser, for R setting and writing of configuration file.
Stars: ✭ 38 (-66.37%)
Mutual labels:  json, yaml, toml
Konf
A type-safe cascading configuration library for Kotlin/Java/Android, supporting most configuration formats
Stars: ✭ 225 (+99.12%)
Mutual labels:  json, yaml, toml
Night Config
Powerful java configuration library for toml, yaml, hocon, json and in-memory configurations
Stars: ✭ 93 (-17.7%)
Mutual labels:  json, yaml, toml
Rapidyaml
Rapid YAML - a library to parse and emit YAML, and do it fast.
Stars: ✭ 183 (+61.95%)
Mutual labels:  json, yaml, serialization
Mconfig
MCONFIG is a lightweight Golang library for integrating configs files like (json, yml, toml) and environment variables into one config struct.
Stars: ✭ 28 (-75.22%)
Mutual labels:  json, yaml, toml
Dasel
Query, update and convert data structures from the command line. Comparable to jq/yq but supports JSON, TOML, YAML, XML and CSV with zero runtime dependencies.
Stars: ✭ 759 (+571.68%)
Mutual labels:  json, yaml, toml
Mashumaro
Fast and well tested serialization framework on top of dataclasses
Stars: ✭ 208 (+84.07%)
Mutual labels:  json, yaml, serialization
Resticprofile
Configuration profiles for restic backup
Stars: ✭ 48 (-57.52%)
Mutual labels:  json, yaml, toml
Python Benedict
dict subclass with keylist/keypath support, I/O shortcuts (base64, csv, json, pickle, plist, query-string, toml, xml, yaml) and many utilities. 📘
Stars: ✭ 204 (+80.53%)
Mutual labels:  json, yaml, toml
Thorsserializer
C++ Serialization library for JSON
Stars: ✭ 241 (+113.27%)
Mutual labels:  json, yaml, serialization
Chronicle Wire
A Java Serialisation Library that supports multiple formats
Stars: ✭ 204 (+80.53%)
Mutual labels:  json, yaml, serialization
Korio
Korio: Kotlin cORoutines I/O : Virtual File System + Async/Sync Streams + Async TCP Client/Server + WebSockets for Multiplatform Kotlin 1.3
Stars: ✭ 282 (+149.56%)
Mutual labels:  json, yaml, filesystem
Qxorm
QxOrm library - C++ Qt ORM (Object Relational Mapping) and ODM (Object Document Mapper) library - Official repository
Stars: ✭ 176 (+55.75%)
Mutual labels:  json, orm, serialization
Srsly
🦉 Modern high-performance serialization utilities for Python (JSON, MessagePack, Pickle)
Stars: ✭ 189 (+67.26%)
Mutual labels:  json, yaml, serialization
Structured Text Tools
A list of command line tools for manipulating structured text data
Stars: ✭ 6,180 (+5369.03%)
Mutual labels:  json, yaml, toml
Ansible Config encoder filters
Ansible role used to deliver the Config Encoder Filters.
Stars: ✭ 48 (-57.52%)
Mutual labels:  json, yaml, toml

Datafiles: A file-based ORM for dataclasses

Datafiles is a bidirectional serialization library for Python dataclasses to synchronize objects to the filesystem using type annotations. It supports a variety of file formats with round-trip preservation of formatting and comments, where possible. Object changes are automatically saved to disk and only include the minimum data needed to restore each object.

Travis CI AppVeyor Coveralls PyPI License PyPI Version Gitter

Some common use cases include:

  • Coercing user-editable files into the proper Python types
  • Storing program configuration and data in version control
  • Loading data fixtures for demonstration or testing purposes
  • Synchronizing application state using file sharing services
  • Prototyping data models agnostic of persistence backends

Watch my lightning talk for a demo of this in action!

Overview

Take an existing dataclass such as this example from the documentation:

from dataclasses import dataclass

@dataclass
class InventoryItem:
    """Class for keeping track of an item in inventory."""

    name: str
    unit_price: float
    quantity_on_hand: int = 0

    def total_cost(self) -> float:
        return self.unit_price * self.quantity_on_hand

and decorate it with a directory pattern to synchronize instances:

from datafiles import datafile

@datafile("inventory/items/{self.name}.yml")
@dataclass
class InventoryItem:
    ...

Then, work with instances of the class as normal:

>>> item = InventoryItem("widget", 3)
# inventory/items/widget.yml

unit_price: 3.0

Changes to the object are automatically saved to the filesystem:

>>> item.quantity_on_hand += 100
# inventory/items/widget.yml

unit_price: 3.0
quantity_on_hand: 100

Changes to the filesystem are automatically reflected in the object:

# inventory/items/widget.yml

unit_price: 2.5 # <= manually changed from "3.0"
quantity_on_hand: 100
>>> item.unit_price
2.5

Objects can also be restored from the filesystem:

>>> from datafiles import Missing
>>> item = InventoryItem("widget", Missing)
>>> item.unit_price
2.5
>>> item.quantity_on_hand
100

Installation

Because datafiles relies on dataclasses and type annotations, Python 3.7+ is required. Install this library directly into an activated virtual environment:

$ pip install datafiles

or add it to your Poetry project:

$ poetry add datafiles

Documentation

To see additional synchronization and formatting options, please consult the full documentation.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].