Skip to main content

PY NS API

What is this repository for?

  • This python3 module is for easy usage of the the NS Train API

How do I get set up?

  • Go To NS API SIte

  • Subscribe for the NS API (It’s free for 50.000 calls a day)

  • Install this script with:

    • pip3 py_nsapi –upgrade (or pip py_nsapi –upgrade )

    • or

    • sudo -H pip3 py_nsapi –upgrade

  • ready to use it!

Repository & Pypi

You can find the Repro at Bitbucket

and the install information on Pypi

API’s

The API’s return the data in a Dictionary. You can loop through the Dict as any Dict.

See examples about how to get information.

All api’s can write warnings, errors and debug information to log files

Just use

import logging
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', level=logging.DEBUG)

More information about logging

Storingen

De webservice voor de storingen en werkzaamheden maakt het mogelijk informatie op te vragen over storingen en/of werkzaamheden.

Fields

  • id

  • Traject

  • Reden

  • Periode

  • Bericht

  • Advies

Example code

from py_nsapi import storingen
user = "yourusername"
pwd  = "yournotsoeasytoguesspassword"
station = [a station, can be empty]
actual = [true or false]
unplanned = [true or false] #false = the oposite of what you think! :-) you get unplanned
ns = reisadviezen(user,pwd)
ns = storingen(user,pwd)
nsStoringen = ns.getData(station,  actual, unplanned)

nsStoringen is a Dict

Reisadviezen

De webservice voor de reisadviezen maakt het mogelijk de NS Reisplanner aan te roepen voor een treinreis van een station naar een station. Een reisadvies bestaat uit meerdere reismogelijkheden, zodat de treinreiziger hier een keuze uit kan maken. Een reismogelijkheid bevat zowel geplande als actuele informatie.

Fields

  • AantalOverstappen

  • ActueleVertrekTijd

  • GeplandeAankomstTijd

  • ActueleReisTijd

  • GeplandeVertrekTijd

  • GeplandeReisTijd

  • Status

  • ActueleAankomstTijd

  • Optimaal

  • ReisDeel

    • @reisSoort

    • Status

    • Vervoerder

    • VervoerType

    • RitNummer

    • ReisStop

      • Naam

      • Tijd

      • Spoor

        • #text

        • @wijziging

Example code

from py_nsapi import reisadviezen
user = "yourusername"
pwd  = "yournotsoeasytoguesspassword"
ns = reisadviezen(user,pwd)
fromST  = "GS"
toST    = "RTB"
triplist = ns.getData(fromST, toST)

Stationslijst

De webservice voor de stationslijst maakt het mogelijk om alle stationsnamen op te vragen.

Fields

  • Code

  • UICCode

  • Synoniemen

  • Type

  • Land

  • Lon

  • Lat

  • Namen

    • Lang

    • Middel

    • Kort

Example code

from py_nsapi import stations


user = "yourusername"
pwd  = "yournotsoeasytoguesspassword"

ns = stations(user, pwd)
nsStations = ns.getData()

Vertrektijden

De webservice voor de actuele vertrektijden maakt het mogelijk om voor een station een actueel overzicht op te vragen van alle vertrekkende treinen voor het komende uur.

Fields

  • RitNummer

  • EindBestemming

  • Vervoerder

  • VertrekSpoor

    • #text

    • @wijziging

  • RouteTekst

  • VertrekTijd

  • TreinSoort

Example code

from py_nsapi import vertrektijden
user = "yourusername"
pwd  = "yournotsoeasytoguesspassword"
ns = vertrektijden(user,pwd)

fromST = "GS"
triplist = ns.getData(fromST)

Prijzen API

De webservice voor de prijzen maakt het mogelijk voor een treinreis de bijbehorende prijsinformatie op te vragen.

Voor gebruik van de webservice is aparte autorisatie vereist. Deze autorisatie wordt verleend na ontvangst van een getekend contract. Dit contract is op te vragen via nsr.api@ns.nl.

Fields

  • @naam

  • Tariefeenheden

  • ReisType

  • @naam

  • ReisKlasse

    • @klasse

    • Korting

      • Kortingsprijs

        • @name

        • @prijs

      • Totaal

      • Prijsdeel

        • @naar

        • @vervoerder

        • van

        • @prijs

Example code

from py_nsapi import prijzen
user = "yourusername"
pwd  = "yournotsoeasytoguesspassword"
ns = prijzen(user,pwd)

fromST = "GS"
toST = "RTB"
viaST = ""
dateTime= ""
data = ns.getData(fromST, toST, viaST, dateTime)

elements = data['VervoerderKeuzes']
print(elements) #dict

Who do I talk to?

License

Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0)

You are free to:

  • Share — copy and redistribute the material in any medium or format

  • Adapt — remix, transform, and build upon the material

-The licensor cannot revoke these freedoms as long as you follow the license terms.-

Under the following terms:

  • Attribution — You must give appropriate credit, provide a link to the license, and indicate if changes were made. You may do so in any reasonable manner, but not in any way that suggests the licensor endorses you or your use.

  • NonCommercial — You may not use the material for commercial purposes.

  • ShareAlike — If you remix, transform, or build upon the material, you must distribute your contributions under the same license as the original.

NS Disclaimer

De getoonde prijsinformatie is niet afkomstig van NS reizigers B.V. of een hieraan gelieerde partij. Jegens NS Reizigers B.V. of daaraan gelieerde partijen, kunnne dan ook geen rechten worden ontleend met betrekking tot deze prijsinformatie

Special thanks to

Stefan de Konink who gave me a complete new insight with his python api

Metadata

Release files for py-nsapi 0.9.3

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

Source distribution (sdist)

Source distribution for py-nsapi 0.9.3
File Size Uploaded Provenance
py_nsapi-0.9.3.tar.gz 6.0 kB Without provenance Details

Release files / py_nsapi-0.9.3.tar.gz

Download URL py_nsapi-0.9.3.tar.gz
Size 6.0 kB
Tags Source
SHA-256 checksum
How to use checksums
076b21b13cfe2d247cbce597f472fdb7b7e0747e1c9937b57bb49b60722d9612
BLAKE2b-256 checksum
How to use checksums
404c4686903c8b618af825c953685c09a1440ef0a51978a4d888ef068d9d00f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for py-nsapi 0.9.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

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