Model Reference¶
Note
Every attribute can be None when no data is available, unless noted otherwise.
Base Classes¶
All choo models are based upon one of the following three base classes that build on top of each other.
-
class
Serializable¶ All models are Serializables. See Model Serialization for more information.
-
validate()¶ Checks if all attributes have valid values. Raises an exception if the object is not valid. This method is also called by
serialize().
-
serialize()¶ Serializes this object in a JSON-encodable format. This is a shortcut for Serializable.serialize(serializable).
Return type: the serialized object
-
classmethod
serialize(obj) Serializes the given instance of this model in a JSON-encodable format, using typed serialization if the given object is an instance of a submodel.
>>> stop.serialize() {…} >>> Stop.serialize(stop) == stop.serialize() True >>> Location.serialize(stop) ['Stop', {…}] >>> Location.serialize(stop)[1] == stop.serialize() True
Parameters: obj – A serialized representation of a choo object Return type: the serialized object
-
classmethod
unserialize(data)¶ Unserializes an object of this model or one of its child classes from a JSON-encodable format. Always use the same model for unserialization as you used for serialization.
Parameters: data – A serialized representation of an object of this model or one of its submodels. Return type: the unserialized object
-
-
class
Searchable¶ An
Serializablethat can be searched for. You can pass it to the API and to get its complete information.All subclasses have a
Requestand aResultssubclass. You can pass the and instance of the Request subclass to the API to get search results in a Results subclass.-
class
Request(Serializable)¶ A request template for this Model with lots of possible search criteria that can be set.
-
class
Searchable.Results(Serializable)¶ A list (of Request-Results) of instances of this object. Those lists can have match scores.
You can just iterate over this object to get its contents.
-
scored(obj)¶ Returns an iterator over tuples of (results, score).
-
filter(request)¶ Remove all objects that do not match the given Request.
-
filtered(request)¶ Returns a new
Resultsinstance with all objects that do not match the given Request removed.
Note
For serialization, the list of results is stored in the property
resultsas a list. Each element of this list is a two-element list containing the serialized result and the match score.Please note that the serialized result is typed serialized if the Model has submodels (e.g.
Location, which hasStopetc…)-
-
class
-
class
Collectable¶ A
Searchablethat can be collected. It has an ID and it really exists and is not some kind of data construct.-
source¶ Source Network of this object. All APIs set this attribute, but it is not mandatory for input.
-
id¶ ID of this object (as
str) in the source network.
-
Main Models¶
Submodels of Collectable.
-
class
AbstractLocation¶ Base class for everything that has a fixed position.
-
coords¶ The
Coordinatesof this location.
-
class
Request¶ Submodel of
Searchable.Request.
-
class
AbstractLocation.Results¶ Submodel of
Searchable.Results.
-
-
class
Ride(line=None, number=None)¶ A ride is implemented as a list of
TimeAndPlaceobjects.Although a
Rideis iterable, most of the time not all stops of the rides are known and the list of known stations can change. This makes the use of integer indices impossible. To avoid this problem, dynamic indices are used for aRide.If you iterate over a
Rideeach item you get isNoneor aTimeAndPlaceobject. Each item that isNonestands for n missing stations. It can also mean that theTimeAndPlacebefore and after the item are in fact the same. To get rid of allNoneitems, pass an incomplete ride to a network API.You can use integer indices to get, set or delete single
TimeAndPlaceobjects which is usefull if you want the first (0) or last (-1). But, as explained above, these integer indices may point to another item when theRidechanges or becomes more complete.If you iterate over
ride.items()you get(RideStopPointer, TimeAndPlace)tuples. When used as an indice, aRide.StopPointerused as an indice will always point to the sameTimeAndPlaceobject.You can slice a
Ride(using integer indices or :py:class RideStopPointer`) which will get you aRideSegmentthat will always have the correct boundaries. Slicing with no start or no end point is also supported.Caution
Slicing a
Rideis inclusive! For example, slicing from element 2 to element 5 results in aRideSegmentcontaining 4 elements in total!-
canceled¶ A boolean indicating whether this ride has been canceled.
-
bike_friendly¶ A boolean indicating whether this is a bike-friendly vehicle.
-
items()¶ A
(RideStopPointer, TimeAndPlace)iterator as explained above.
-
append(item)¶ Append a
TimeAndPlaceobject.
-
prepend(item)¶ Prepend a
TimeAndPlaceobject.
-
insert(position, item)¶ Insert a
TimeAndPlaceas the new positionposition.
Attention
The following attributes are dynamic and can not be set.
-
path¶ Get the geographic path of the ride as a list of
Coordinates.Falls back to just directly connecting the platform or stop coordinates if no other information is available. If some information is still missing, its value is
None.
-
is_complete¶ Trueif theTimeAndPlacelist is complete and there are no Nones in the list, otherwiseFalse.
-
class
StopPointer¶ See above. Immutable. Do not use this class directly. You can cast it to int.
Note
For serialization, pointers are not used. The property
stopsis created containing with each item being either a serializedTimeAndPlaceobject orNone.The property
pathis created containing a dictionary containing paths between consecutive ride stops with the index of the origin stop as keys.-
class
Ride.Request¶ Submodel of
Searchable.Request.
-
class
Ride.Results¶ Submodel of
Searchable.Results.
-
-
class
Line(linetype=None)¶ A group of Rides (e.g. Bus Line 495). Every
Ridebelongs to one Line.-
product¶ The product name, for example InterCity, Hamburg-Köln-Express or Niederflurbus.
-
route¶ The route description.
-
operator¶ The name of the company that operates this line.
-
class
Request¶ Submodel of
Searchable.Request.
-
class
Line.Results¶ Submodel of
Searchable.Results.
-
Locations¶
Submodels of AbstractLocation.
-
class
Platform(stop, name=None, full_name=None)¶ An
AbstractLocationwhere rides stop (e.g. Gleis 7). It belongs to oneStop.-
ifopt¶ The globally unique ID of this Platform according to Identification of Fixed Objects in Public Transport supported by some APIs.
-
name¶ The name of this Platform (e.g. 7 or 2b).
-
full_name¶ The full name of this Platform (e.g. Bussteig 7 or Gleis 2b)
-
class
Request¶ Submodel of
AbstractLocation.Request.
-
class
Platform.Results¶ Submodel of
AbstractLocation.Results.
-
-
class
Location(country=None, city=None, name=None)¶ An
AbstractLocationthat is named and not a sublocation like a Platform.-
country¶ The country of this location as a two-letter country code.
-
city¶ The name of the city this location is located in.
-
name¶ The name of this location. If the
cityattribute isNonethis it may also included in the name.
-
near_stops¶ Other stops near this one as a
Stop.Results, if available. You can always search for Stops near anAbstractLocationdirectly usingAbstractLocation.Request.
-
class
Request¶ Submodel of
AbstractLocation.Request.-
name¶ A search string for the name of the Location.
-
city¶ City of the Location.
-
-
class
Location.Results¶ Submodel of
AbstractLocation.Results.
-
-
class
Stop(country=None, city=None, name=None)¶ A
Locationdescribing a stop, for example: Düsseldorf Hbf.-
ifopt¶ The globally unique ID of this Stop according to Identification of Fixed Objects in Public Transport supported by some APIs.
-
uic¶ The is the international train station id by the International Union of Railways.
-
full_name¶ The full name of this Stop. Can be just the city and the name, but does’nt have to.
-
lines¶ The Lines that are available at this stop as a
Line.Resultsobject, if available. You can always search for Lines at aStopusingLine.Request.
-
rides¶ The next rides at this stop as a
Ride.Resultsobject, if available. You can always search for Rides at aStopusingRide.Request.
-
class
Request¶ Submodel of
Location.Request.
-
class
Stop.Results¶ Submodel of
Location.Results.
-
-
class
Address(country=None, city=None, name=None)¶ A
Locationdescribing an address. Thenameattribute contains the address in one string, but more detailed attributes may be available:-
street¶ The name of the street.
-
number¶ The house number as a string.
-
class
Request¶ Submodel of
Location.Request.
-
class
Address.Results¶ Submodel of
Location.Results.
-
-
class
POI(country=None, city=None, name=None)¶ A
Locationdescribing a Point of Interest.-
class
Request¶ Submodel of
Location.Request.
-
class
POI.Results¶ Submodel of
Location.Results.
-
class
Trips¶
Submodel of Searchable.
-
class
Trip¶ A connection from a
AbstractLocationto anotherAbstractLocation.It consists of a list of
RideSegmentandWayobjects. Just iterate over it to get its elements.-
time¶ The fetching time of this object as a
datetimeobject. This is relevant to know how up to date the contained real time data (delays, cancellation, platform changes, etc.) is. All APIs set this attribute, but it is not mandatory for input.
-
tickets¶ TicketListof available tickets for this trip.
Attention
The following attributes are dynamic and can not be set.
-
origin¶ The start
AbstractLocationof this trip.
-
destination¶ The end
AbstractLocationof this trip.
-
departure¶ The departure at the first
AbstractLocationof this trip asRealtimeTime. (If there are leadingWayobjects they need to have thedurationattribute set in order for this to work)
-
arrival¶ The arrival at the last
AbstractLocationof this trip asRealtimeTime. (If there are trailingWayobjects they need to have thedurationattribute set in order for this to work)
-
changes¶ The number of changes in this trip (number of
RideSegmentsminus one with a minimum of zero)
-
bike_friendly¶ Falseif at least oneRidethat is part of this trip is not bike friendly.Trueif all of them are.Noneif there is no bike friendly information for all rides but those that have the information are bike friendly.
Note
For serialization, the property
partsis created containing the list of typed serialized trip parts.-
class
Request¶ Submodel of
Searchable.Request.-
origin¶ Not None. The start
AbstractLocationof the trip.
-
destination¶ Not None. The end
AbstractLocationof the trip.
-
departure¶ The minimum departure time as
RealtimeTimeordatetime.datetime.If both times are
Nonethe behaviour is as if you would have set the departure time to the current time right before sending the request. (Default:None)
-
arrival¶ The latest allowed arrival as
RealtimeTimeordatetime.datetime. (Default:None)
-
max_changes¶ The maximum number of changes allowed or
Nonefor no limit. (Default:None)
-
with_bike¶ Whether a bike should be taken along. (Default:
False)
-
wheelchair¶ Whether to allow only vehicles that support wheelchairs. (Default:
False)
-
low_floor_only¶ Whether to allow only low floor vehicles. (Default:
False)
-
allow_solid_stairs¶ Whether to allow solid stairs. (Default:
True)
-
allow_escalators¶ Whether to allow escalators. (Default:
True)
-
allow_elevators¶ Whether to allow elevators. (Default:
True)
-
waytype_origin¶ Waytype at the beginning of the trip. (Default: walk)
-
waytype_via¶ Waytype at changes or ways during the trip. (Default: walk)
-
waytype_destination¶ Waytype at the end of the trip. (Default: walk)
-
wayduration_origin¶ Maximum duration of a way at the beginning of the trip as a
datetime.timedelta. (Default: 10 minutes)
-
wayduration_via¶ Maximum duration of changes of ways during the trip as a
datetime.timedelta. (Default: 10 minutes)
-
wayduration_destination¶ Maximum duration of a way at the end of the trip as a
datetime.timedelta. (Default: 10 minutes)
-
-
class
Trip.Results¶ Submodel of
Searchable.Results.-
origin¶ Not None. The start
AbstractLocationof the trip.
-
destination¶ Not None. The end
AbstractLocationof the trip.
-
-
Trip parts¶
Submodels of Serializable.
-
class
RideSegment¶ -
This class created by slicing :py:class:`Ride` objects. Integer indices are not too useful in this class, either, although you can for example still use 0 and -1 to get the first or last
RideStopPointerof this segment.This model is usable in the same way as a
Ride. Slicing it will return anotherRideSegmentfor the sameRide.Caution
Slicing a
RideSegmentis inclusive! For example, slicing from element 2 to element 5 results in aRideSegmentcontaining 4 elements in total!-
items()¶ A
(RideStopPointer, TimeAndPlace)iterator over this segment.
All attributes of the
Rideare also directly accessible through aRideSegment.Attention
The following attributes are dynamic and can not be set.
-
path¶ Get the geographic path of the ride segment as a list of
Coordinates.Falls back to just directly connecting the platform or stop coordinates if no other information is available. If some information is still missing, its value is
None.
-
is_complete¶ Trueif theTimeAndPlacelist of this Segment is complete.
-
departure¶ The departure at the first
Stopof this segment asRealtimeTime. Shortcut forsegment[0].departure.
-
arrival¶ The arrival at the last
Stopof this segment asRealtimeTime. Shortcut forsegment[-1].arrival.
Note
For serialization, the boundaries are given as integer indexes as properties
originanddestination. Each one can be missing if the boundary is not set. (e.g.ride[5:])Dont forget that Ride slicing is inclusive (see above)!
-
-
class
Way(origin: Location, destination: Location, distance: int=None)¶ Individual transport (walk, bike, taxi…) with no schedule. Used for example to get from a
Addressto aStopand for changes but also for trips that are faster by foot.-
distance¶ The distance in meters as
int.
-
duration¶ The expected duration as
datetime.timedelta.
-
path¶ The path as a list of
Coordinates.
-
Other Models¶
Submodels of Serializable.
-
class
TimeAndPlace(platform, arrival=None, departure=None)¶ Time and place of a
Ridestopping at aPlatform.-
arrival¶ The arrival time of the
RideasRealtimeTime.
-
departure¶ The departure time of the
RideasRealtimeTime.
-
-
class
RealtimeTime(time, delay=None)¶ A point in time with optional real time data.
Parameters: - time – The originally planned time as a datetime.datetime object.
- delay – The (expected) delay as a datetime.timedelta object if known.
-
time¶ Not None. The originally planned time as a datetime.datetime object.
-
delay¶ The (expected) delay as a datetime.timedelta object or None. Please note that a zero delay is not the same as None. None stands for absence of real time information.
Attention
The following attributes are dynamic and can not be set.
-
is_live¶ True if there is real time data available. Shortcut for
delay is not None
-
livetime¶ The (expected) actual time as a datetime.datetime object if real time data is available, otherwise the originally planned time.
-
class
TicketList(all_types: bool=True)¶ A list of tickets.
-
currency¶ Not None. The name or abbreviation of the currency.
-
level_name¶ How a level is named at this network.
-
single¶ Not None. The single ticket as
TicketData.
-
bike¶ The single ticket as
TicketData.
-
other¶ Not None. Other available tickets as a dictionary with the name of the tickets as keys and
TicketDataobjects as values.
-
Data types¶
Submodels of Serializable.
-
class
TicketData(authority=None, level=None, price=None, price_child=None)¶ Information about a ticket.
The name of the authority selling this ticket.
-
level¶ The level of this ticket, e.g. A or something similar, depending on the network
-
price¶ Not None. The price of this ticket as float.
-
price_child¶ The children’s price for this ticket if this ticket is not a ticket for children only but has a different price for children.
-
class
LineType(name)¶ Each
Linehas a line type. A line type has one of the values(empty string),train,train.local,train.longdistance,train.longdistance.highspeed,urban,metro,tram,bus,bus.regional,bus.city,bus.express,bus.longdistance,suspended,ship,dialable, orother.An empty string means that it can be anyone of the other linetypes, The linetype
busmeans that it could be any of the bus-subtypes. The reason for this is that not all networks differentiate between some subtyes (e.g. bus types). See the network reference for which linetypes it may output.All identical linetypes are the same instance:
>>> LineType('bus') is LineType('bus') True
To compare against a linetype, use the
inoperator. Be aware that this operator is not transitive!>>> linetype = LineType('bus.express') >>> linetype in LineType('bus') True >>> LineType('bus') in linetype False >>> LineType('bus') in LineType('') True >>> LineType('') in LineType('bus') False >>> LineType('bus') in LineType('bus') True
You can cast a
LineTypeto string if needed:>>> str(LineType('train.local')) 'train.local'
Note
The serialized representation of this model is its string representation.
-
class
LineTypes(include=('', ), exclude=())¶ A selector for
LineTypeobject. It is defined as a list of included line types and a list of excluded linetypes. By default, all line types are included.>>> LineType('bus') in LineTypes() True >>> LineType('bus') in LineTypes(exclude=('bus', )) False >>> LineType('bus.express') in LineTypes(exclude=('bus', )) False >>> LineType('bus') in LineTypes(exclude=('bus.express', )) True >>> LineType('bus.express') in LineTypes(exclude=('bus.express', )) False >>> LineType('train') in LineTypes(include=('bus', ), exclude=('bus.express', )) False >>> LineType('bus') in LineTypes(include=('bus', ), exclude=('bus.express', )) True >>> LineType('bus.express') in LineTypes(include=('bus', ), exclude=('bus.express', )) False
You can modify the selector using the following methods:
-
include(*linetypes)¶ Parameters: linetypes – one or more line types as string or LineTypeMake sure that the given line types and all of their subtypes are matched by the selector.
-
exclude(*linetypes)¶ Parameters: linetypes – one or more line types as string or LineTypeMake sure that the given line types and all of their subtypes are not matched by the selector.
Note
For serialization, the properties
includedandexcludedare created, each one containing a list of line types.-
-
class
WayType(name)¶ Each
Wayhas a line type. A Linetype has one of the valueswalk,bike,car,taxi.All identical way types are the same instance:
>>> WayType('walk') is WayType('walk') True
You can cast a
WayTypeto string if needed:>>> str(WayType('walk')) 'walk'
Note
The serialized representation of this model is its string representation.
-
class
WayEvent(name, direction)¶ A way
Wayevents one of the namesstairs,escalatororelevatorand one of the directionsupordown.All identical way types are the same instance:
>>> WayType('escalator', 'down') is WayType('escalator', 'down') True
Attention
The following attributes are dynamic and can not be set.
-
name¶ Not None.
stairs,escalatororelevator
-
direction¶ Not None.
upordown
Note
The serialized representation of this model is a
(name, direction)tuple.-