Skip to main content
# nf-grapher-python

This is a Python3 library for building Native Format Scores.

> **Note**: Currently this library supports _building_ Native Format Scores for the Native Format Smart Player, however reading or deserializing scores from JSON is currently unsupported.

## Requirements

- Python3
- virtualenv

## Installing

```bash
pip install nf_grapher
```

## Getting Started

Setup a virtual environment with the following:

```bash
virtualenv -p python3 e
source ./e/bin/activate
```

You can use whatever environment name you'd like, `e` is used here because it's short.

## Structure

This python library is divided into 3 modules. `nf_grapher.score` contains all the Score level objects
defined by the Native Format Score schema. `nf_grapher.typed` contains useful "typed" nodes defined
by the [smart player contract](../smart-player-contract.json). Because Python is not
statically typed, these types are not yet enforced. `nf_grapher.encoder` contains a function `encode`
for serializing grapher objects into JSON.

## Tests

Run tests with the following command:

```bash
python -m unittest discover -v
```

## Example Usage

```python
from nf_grapher.score import *
from nf_grapher.typed import *
from nf_grapher.encoder import encode

# Build a source node for a Spotify track
# Start from 5.6 seconds into the track and play for 5.6 seconds
source = FileNode('spotify:track:4RDKrwyA9YouzL1LxvMaxH', offset=5.6e+9, duration=5.6e+9)

# Create a 5.6 second loop from the beginning of the track
loop = LoopNode(when=0, duration=5.6e+9)

# Create the full score
score = Score(Graph(
nodes=[source, loop],
edges=[source.connect(loop)]
))

print(encode(score))
```

You can see a list of all supported typed nodes by using the Python `help` feature in a REPL.
For instance,

```bash
python
>>> from nf_grapher import typed
>>> help(typed)
```


Release files for nf-grapher 1.2.24

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nf-grapher 1.2.24
File Size Uploaded
nf_grapher-1.2.24.tar.gz 8.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for nf-grapher 1.2.24
File Interpreter ABI Platform
nf_grapher-1.2.24-py3-none-any.whl Python 3 none any Details

Total release size: 22.7 kB

Release files / nf_grapher-1.2.24.tar.gz

Download URL nf_grapher-1.2.24.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
63f25e4f6cc51d38ef653d3bd53dda1aff9a23800efea0d1fcbf78df0c335e9d
BLAKE2b-256 checksum
How to use checksums
0193596bbe2969052848c47a6dca7fa99e831bd6ec5bac9f1b180ca43b506ace
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.4

Release files / nf_grapher-1.2.24-py3-none-any.whl

Download URL nf_grapher-1.2.24-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
8c3649881f463b1f0489b2eb31f3d76f0d8f58749fdf26576c17525f0215e17e
BLAKE2b-256 checksum
How to use checksums
c0e5938f9a7f258fa9c7597d758be56a84f6d794b7fb611f6374896f60ce2af4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.4

Release history Release notifications | RSS feed

This release

1.2.24 This release

2 release files

1.2.23

2 release files

1.2.22

2 release files

1.2.21

2 release files

1.2.20

2 release files

1.2.19

2 release files

1.2.18

2 release files

1.2.17

2 release files

1.2.16

2 release files

1.2.15

2 release files

1.2.14

2 release files

1.2.13

2 release files

1.2.12

2 release files

1.2.11

2 release files

1.2.10

2 release files

1.2.9

2 release files

1.2.8

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page