# 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)
```
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.20.tar.gz
(9.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nf_grapher-1.2.20.tar.gz.
File metadata
- Download URL: nf_grapher-1.2.20.tar.gz
- Upload date:
- Size: 9.4 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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1bb5f2628034156251f136adaca55dd1291c41cb8565500f96e4d00ef6537ee2
|
|
| MD5 |
142b3934277aaee36c5585a955f98055
|
|
| BLAKE2b-256 |
5fcc066ce0932af3ada6cae49de1bcaa98c165016c087452c36a40f78ecb411a
|
File details
Details for the file nf_grapher-1.2.20-py3-none-any.whl.
File metadata
- Download URL: nf_grapher-1.2.20-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9a9e4b2029c7c1a3801181e8e2ba1860ecb715d38596ec0008c7a8e35d951fa2
|
|
| MD5 |
031bdb9d995905d820e319c221662e50
|
|
| BLAKE2b-256 |
4a5bb6813411709773a473fc1ec01607bd0cefe5c827de7d6fa13e38a91c7d4b
|