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)
```


Download files

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

Source Distribution

nf_grapher-1.2.10.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

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

nf_grapher-1.2.10-py3-none-any.whl (14.1 kB view details)

Uploaded Python 3

File details

Details for the file nf_grapher-1.2.10.tar.gz.

File metadata

  • Download URL: nf_grapher-1.2.10.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for nf_grapher-1.2.10.tar.gz
Algorithm Hash digest
SHA256 d972b952b1bb259c93bd336cf186864ae580b25d551f17058cc33deb8d9f638a
MD5 d1760f01cd0180abe03436e3e2bf8e33
BLAKE2b-256 0b55be467fb1ab360c0c7a280983473ee7b2b8eb78501dc99fd21de3dcd3bd5a

See more details on using hashes here.

File details

Details for the file nf_grapher-1.2.10-py3-none-any.whl.

File metadata

  • Download URL: nf_grapher-1.2.10-py3-none-any.whl
  • Upload date:
  • Size: 14.1 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for nf_grapher-1.2.10-py3-none-any.whl
Algorithm Hash digest
SHA256 cce3b2b8a07dd2898a9484e58c0706b292ab2f6c599d3647a3d0a96c3cfb21df
MD5 6f4338d5a837d785fd119139504c4af1
BLAKE2b-256 4933b2931aac4dd62fbe0a5f6f00ec478a44f9b858e76573ec7b41775c50833d

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 Sentry Error logging StatusPage Status page