Skip to main content

Entity Data Format (EDF) parser and serializer

Project description

EDF Parser

Entity Data Format (EDF) parser and serializer.

Installation

pip install entity_data_format

Usage

Loading

Load from file

import entity_data_format as edf

with open('path/to/file.edf', 'r', encoding='utf-8') as fp:
    data = edf.load(fp)

Load from string

import entity_data_format as edf

data_str = '''
[entity = player]
speed = 10.0
inventory = sword shield
'''
data = edf.loads(data_str)

# Incremental loading into existing dictionary
extra_str = '[entity = enemy]\nspeed = 5'
edf.loads(extra_str, data=data)

Load all entities (merging)

import entity_data_format as edf

# Recursively load all .edf files and merge them
# Files are processed in alphabetical order
data = edf.load_all_entities('assets/**/*.edf')

Serialization

Dump to file

import entity_data_format as edf

data = {
    'car': {
        'car1': {'speed': 100, 'acceleration': 1.0}
    }
}

with open('output.edf', 'w', encoding='utf-8') as fp:
    edf.dump(data, fp)

Dump to string

import entity_data_format as edf

data = {
    'weapon': {
        'sword': {'damage': 15, 'weight': 2.5}
    }
}
s = edf.dumps(data)

Data Types

EDF is primarily string-based, but serialize_value handles several Python types:

  • bool: True -> 1, False -> 0
  • float: Formatted using %f
  • list / tuple: Space-separated values. Spaces within elements are replaced by _.
  • other: Converted to str()

Note: All values are returned as strings when loading.

Modding support (merging entities)

cars.edf:

[car = car1]
speed = 100
acceleration = 1.0

[car = car2]
speed = 80
acceleration = 1.2

cars_mod.edf:

[car = car1]
speed = 120
import entity_data_format as edf

# Files are loaded in alphabetical order, so cars_mod.edf will overwrite values from cars.edf
data = edf.load_all_entities('*.edf')

# data['car']['car1']['speed'] == '120'
# data['car']['car1']['acceleration'] == '1.0'

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

entity_data_format-1.0.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

entity_data_format-1.0.0-py3-none-any.whl (4.3 kB view details)

Uploaded Python 3

File details

Details for the file entity_data_format-1.0.0.tar.gz.

File metadata

  • Download URL: entity_data_format-1.0.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.4

File hashes

Hashes for entity_data_format-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ae3e20a18aebba527f8d4a391803b1e3f951a0b7c36752798c52aba2c8d42469
MD5 efaddbb6f8669f7953f008a080b88732
BLAKE2b-256 981ce874ec003309419f28bf0e6970c4f418f366cdb24ccd3e8c739f87121c2d

See more details on using hashes here.

File details

Details for the file entity_data_format-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for entity_data_format-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 42dc09e93276ed0a839363f567cf3a3917842a96444335acbe4a80aa165f95ec
MD5 737b049cf8d872e3bb4473a94eb82299
BLAKE2b-256 c6b596587dcf43b4f2dcf3f8f76cef218213c2ab2bf8bf1ff1a9864e18baea01

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page