Skip to main content

Python parser from TransXChange.

Project description

pytxc

Quick start

Installation

Use pip to install pytxc.

python -m pip install pytxc

Usage

The Timetable class is used to parse and interact with TransXChange files.

from pathlib import Path
from pytxc import Timetable


>> filepath = "path/to/transxchange/file.xml"
>> timetable = Timetable.from_file_path(Path(filepath))
>> timetable.header
Header(
    creation_date_time=datetime.datetime(2020, 11, 22, 11, 0),
    modification_date_time=datetime.datetime(2021, 12, 17, 11, 8, 35),
    file_name="file.xml",
    modification="revise",
    schema_version="2.4",
    revision_number=159,
)

The StopPoints in a TransXChange can be accessed through the stop_points attribute.

>> timetable.stop_points[0]

AnnotatedStopPointRef(
    stop_point_ref=StopPointRef(text="077072002S"),
    common_name="High Street Stand S",
)

Similarly, RouteSections can be accessed using the route_sections attribute.

>> timetable.route_sections[0]

RouteSection(id='RS1')

The naming conventions used for the Python objects will more or less match those of TransXChange for example, the first JourneyPattern of a StandardService is usually found in a Service of the Services block. Using pytxc it can be accessed as follows,

>> timetable.services[0].standard_services[0].journey_patterns[0]

JourneyPattern(
    id="JP1",
    CreationDateTime="2020-11-22T11:00:00",
    ModificationDateTime="2021-12-17T11:08:35",
    Modification="revise",
    RevisionNumber="159",
)

When interacting with references, pytxc provides a resolve method to find the original element in the TransXChange file. For example if a JourneyPattern contains a RouteRef then calling resolve on the route_ref object will return the original Route object.

>> jp = timetable.services[0].standard_services[0].journey_patterns[0]
>> jp.route_ref.resolve()

Route(private_code='35st-40', description='Stockton - Wolviston Court')

Project details


Download files

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

Source Distribution

pytxc-0.1.3.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

pytxc-0.1.3-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file pytxc-0.1.3.tar.gz.

File metadata

  • Download URL: pytxc-0.1.3.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.13.0-1021-azure

File hashes

Hashes for pytxc-0.1.3.tar.gz
Algorithm Hash digest
SHA256 5aac7df3b7c84052c51035c5a378aa58401d97928c104976a43073579d8884f9
MD5 cad9b7d7c92bd06495db410afb3a59a3
BLAKE2b-256 bce90b2e640c60c9940c91bea5265128be1f0539eed1820f2c01bbf474d5c839

See more details on using hashes here.

File details

Details for the file pytxc-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pytxc-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 10.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.4 Linux/5.13.0-1021-azure

File hashes

Hashes for pytxc-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0a8a010deb1aec3d60c2d6bba80ce2c9c0316e91c1640f3b9138564cd7622a83
MD5 de7240d9c998548c4dca7506202041b3
BLAKE2b-256 3c30dfe8906688ed9466f24b2c75a53aa2f727c08dc5c244282e96ea4d0db2dd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page