Skip to main content

Traktor NML utils

Python package

This module contains utilities to parse and modify Native Instruments Traktor NML files.
Traktor 2.x, 3.x and 4.x NML files are supported.

It can parse collection NML files ($TRAKTOR_DIR/collection.nml) and history NML files ($TRAKTOR_DIR/History/history_$DATE.nml).

All NML attributes are readable and writable using auto-generated dataclasses (see traktor_nml_utils/models).
This allows a typesafe way to work with NML files, fully supporting IDE autocompletion:

alt text

While reading should work in 99% cases, writing NML files hasn't been tested thoroughly enough yet, so always keep a copy of your NML files.

Requirements

traktor-nml-utils requires Python 3.10 or newer.

traktor-nml-utils is tested with Traktor 4.x (NML VERSION="20") and Traktor 3.3.0, though it should be able to parse Traktor 2.x NML files as well. Feel free to provide files that cause problems on parsing.

Installation

pip install traktor-nml-utils

Usage

Get artist, title and rating of all collection entries

from traktor_nml_utils import TraktorCollection
from pathlib import Path

collection = TraktorCollection(path=Path('collection.nml'))

for entry in collection.nml.collection.entry:
    print(entry.artist, entry.title, entry.info.ranking)

Get cuepoint start

entry = collection.nml.collection.entry[0]

for cue_v2 in entry.cue_v2:
    print(cue_v2.start)

Find entry

artist = "Yotto"
title = "Another Riff For The Good Times (Extended Mix)"

entry = [
    entry for entry in collection.nml.collection.entry
    if entry.artist == artist
    and entry.title == title
][0]

Add cuepoint

from traktor_nml_utils.models.collection import CueV2Type
from traktor_nml_utils.utils import duration_str_to_milliseconds

my_cue = CueV2Type(
    value=None, 
    name='n.n.', 
    displ_order=0, 
    type=0, 
    start=duration_str_to_milliseconds("00:01:00"), 
    len=0.0, 
    repeats=-1, 
    hotcue=1
)
entry.cue_v2.append(my_cue)

# Write XML file
collection.save()

Run tests

Run tests within Docker container:

argc docker-build
argc docker-test

Create virtualenv and run tests:

argc virtualenv-create
argc virtualenv-test

To test if parsing your own collection/history files with traktor-nml-utils works, pass your Traktor directory to the CLI:

traktor-nml-utils traktor-import ~/traktor3/

How does it work?

NML files to Python dataclasses

Since there is no official schema for Traktor NML files, the dataclasses in traktor_nml_utils/models/ were generated from sample NML files with xsdata, which infers the schema directly from XML documents. They have since been hand-tuned to match Traktor's exact output format, so they are maintained in the repository rather than regenerated blindly.

To generate fresh models from your own files, overwrite collection.nml and history.nml in ./xml_to_xsd/ and run:

argc generate-models

This writes new models to build/generated/. Compare them against the hand-tuned modules in traktor_nml_utils/models/ and merge any differences manually (class names differ: xsdata names classes after elements, e.g. Entry instead of the committed Entrytype).

Contribution

Help wanted!

Since the XSD-schema was created from my own Traktor files, the schema might not fit for all collection and history files. In case you have any problems parsing NML files, please report an issue and attach the problematic NML file so I can update the schema.

Download files

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

Source Distribution

traktor_nml_utils-4.1.0.tar.gz (27.1 kB view details)

Uploaded Source

Built Distribution

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

traktor_nml_utils-4.1.0-py3-none-any.whl (25.4 kB view details)

Uploaded Python 3

File details

Details for the file traktor_nml_utils-4.1.0.tar.gz.

File metadata

  • Download URL: traktor_nml_utils-4.1.0.tar.gz
  • Upload date:
  • Size: 27.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for traktor_nml_utils-4.1.0.tar.gz
Algorithm Hash digest
SHA256 6f9c4e586651afe96c5bb9a042ed87e678d501b580e5552bfb53bc40aab78d03
MD5 587f41f16c2c64f7a945a7b0007839f4
BLAKE2b-256 15643ff077ba741990fe26576f7dd809878ea6adbca606a3b2fbc7b918a2ac78

See more details on using hashes here.

Provenance

The following attestation bundles were made for traktor_nml_utils-4.1.0.tar.gz:

Publisher: release.yml on wolkenarchitekt/traktor-nml-utils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file traktor_nml_utils-4.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for traktor_nml_utils-4.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e0a6bb8a419f0ec4a75ef84f9af04ae8b952b2f57044dce7c16188acbbb9f504
MD5 2f59f3dd99f7a383393951dd9430e322
BLAKE2b-256 d95a7728c6e6ba2fb37bcd9b1d040ba6c77d15241cddc06b3c12472fa18c9042

See more details on using hashes here.

Provenance

The following attestation bundles were made for traktor_nml_utils-4.1.0-py3-none-any.whl:

Publisher: release.yml on wolkenarchitekt/traktor-nml-utils

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

4.1.0 This release

2 files

4.0.0

2 files

3.1.0

1 file

3.0.2

1 file

3.0.1

1 file

3.0.0

1 file

2.0.6

1 file

2.0.5

1 file

2.0.4

1 file

1.0.2

1 file

1.0.1

1 file

Supported by

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