Skip to main content

Python reader, writer and validator for Meta yAML (MAML).

Project description

MAML

MAML is a YAML based metadata format for tabular data. This is the official python package interface to help read, write, and parse MAML files and implementes the standards and schemas defined here: https://github.com/asgr/MAML-Format

pymaml

This is the official python package for reading, writing, and parsing the Meta yAML format. The MAML format is defined by json schemas which are used to construct pydantic classes which enforce validation.

Installation

pymaml can be installed easily with pip

pip install pymaml

Reading in a .maml file.

Reading a maml file is done using the MAML object in pymaml.

from pymaml import MAML
new_maml = MAML.from_file("example.maml", "v1.1")

This object will only be created if "example.maml" is valid maml for the given version. If it isn't, then a pydantic ValidationError will be raised explaining what is causing the validation error.

Validating a .maml file.

The pymaml package has a valid_for function that will audit a .maml file and return a list of valid maml versions for which that file is valid.

from pymaml import valid_for
valid_versions = valid_for("example.maml")

In this way users can determine if their own maml files are actually valid for the version they expect.

Creating a new maml file

MAML files can be constructed from scratch using the MAMLBuilder which implements a builder pattern and includes some helper methods.

from pymaml.maml import MAMLBuilder
builder = MAMLBuilder("v1.1")

This is the most basic constructions and will create a new builder object which will enforce the version 1.1 schema.

Additional properties can be added or set, and the final validation occurs during the build step.

builder.set("author", "Me")
builder.set("table", "Table Name")
builder.set("version", "1")
builder.add("fields", {"name": "RA", "data_type": "float"})
builder.add("fields", {"name": "Dec", "data_type": "float"})
builder.add("fields", {"name": "redshift", "data_type": "float"})
builder.set("date", "1995-09-12")
maml = builder.build()

The .build() method performs validation in the exact same way as reading from a file.

Defaults

The builder can also generate maml based off of some basic default categories which will create valid MAML.

from pymaml.maml import MAMLBuilder

builder = MAMLBuilder("v1.0", defauts=True)
maml = builder.build()

This will always work since the defaults are always set to be valid maml. But are marked obviously to show that they are default values. The User will need to change these values.

Fields from pandas

Since each column requires a field entry, there can be numerous columns. We include a method in the builder that will autogenerate the field names and datatypes from a pandas dataframe.

from pymaml.maml import MAMLBuilder
import pandas as pd

df = pd.read_csv("example.csv")

builder = MAMLBuilder("v1.0")
builder.fields_from_pandas(df)
builder.set("author", "Me")
builder.set("table", "Table Name")
builder.set("version", "1")

maml = builder.build()

Writing to file

Once the maml data has been read in and edited, or built from scratch the MAML object can be written to a maml file using the to_file method.

maml.to_file("my_maml.maml")

If the maml object exists, then you can take solace in the knowledge that it is valid MAML by design.

In addition the maml data can be converted into a dictionry for more fine tune editing.

dictionary = maml.to_dict()

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

pymaml-0.6.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

pymaml-0.6.1-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file pymaml-0.6.1.tar.gz.

File metadata

  • Download URL: pymaml-0.6.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pymaml-0.6.1.tar.gz
Algorithm Hash digest
SHA256 8edd0c2378b1dd60daa4c447f7321eabc892c1301ca419c7ae24dacf3aada292
MD5 bb61448471fe50828445c7bc6b287c14
BLAKE2b-256 1eb64588a31f5c8aa73739ab7a278ddf0cae5985e1a2285d3188b7657811caf9

See more details on using hashes here.

File details

Details for the file pymaml-0.6.1-py3-none-any.whl.

File metadata

  • Download URL: pymaml-0.6.1-py3-none-any.whl
  • Upload date:
  • Size: 12.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pymaml-0.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 164c7f60e57921302178270de7b5e3044aeaca5c80b644e9f3fcb22d444d0af4
MD5 5f6d8128343a60cce8b301440c9bdc95
BLAKE2b-256 977017a28b1ca470dc4c86e8a5ef9cb28629da3d7fbc280b68d78146d96b66dd

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