Model Reference¶
Note
Every attribute can be None when no data is available, unless noted otherwise.
Base Models¶
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.
-
Locations¶
-
class
GeoLocation¶ Submodel of :py:class:`Serializable`.
Abstract base class for everything that has a fixed position.
-
lat¶ latitude as float
-
lon¶ longitude as float
-
-
class
Coordinates(lat, lon)¶ Submodel of :py:class:`GeoLocation`.
A Model just geographic coordinate.
You can cast
Coordinatesto tuple if needed:>>> tuple(Coordinates(51.445555, 7.017253)) (51.445555, 7.017253)
-
class
Platform(stop, name=None, full_name=None)¶ Submodel of :py:class:`Collectable` and :py:class:`GeoLocation`.
An place where rides stop (e.g. Gleis 7). It belongs to one
Stop.-
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
Searchable.Request.
-
class
Platform.Results¶ Submodel of
Searchable.Results.
-
-
class
Location(country=None, city=None, name=None)¶ Submodel of :py:class:`Collectable` and :py:class:`GeoLocation`.
Abstract base class place that 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 aGeoLocationdirectly usingStop.Request.
-
class
Request¶ Submodel of
Searchable.Request.-
name¶ A search string for the name of the Location.
-
city¶ City of the Location.
-
-
class
Location.Results¶ Submodel of
Searchable.Results.
-
-
class
Stop(country=None, city=None, name=None)¶ Submodel of :py:class:`Location`.
A train station, bus stop, etc. 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)¶ Submodel of :py:class:`Location`.
An address. The
nameattribute 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)¶ Submodel of :py:class:`Location`.
A Point of Interest.
-
class
Request¶ Submodel of
Location.Request.
-
class
POI.Results¶ Submodel of
Location.Results.
-
class
Rides¶
-
class
Ride(line=None, number=None)¶ Submodel of :py:class:`Collectable`.
A ride is implemented as a list of
RidePointobjects and suppors nearly all methods of Python’s nativelisttype.If you iterate over a
Rideeach item you get isNoneor aRidePointobject. Each item that isNonestands for n missing stations. It can also mean that theRidePointbefore and after the item are in fact the same. To get rid of allNoneitems, pass an incomplete ride to a network API.You can slice a
Ridewhich will get you aRideSegmentthat refers to the original ride but always will have the correct boundaries, even if elements between are removed or inserted between them. 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 aRideSegmentdescribing the journey between element 2 and element 5, containing 4 elements in total!-
time¶ -
The time at which the ride data was retrieved as ``datetime``.
-
canceled¶ A boolean indicating whether this ride has been canceled.
-
bike_friendly¶ A boolean indicating whether this is a bike-friendly vehicle.
-
pop([i])¶ Remove the item at the given position (default: last position) from the list.
-
index([i])¶ Remove the item at the given position (default: last position) from the list.
You can also use
inanddel.Attention
The following attributes are dynamic and can not be set.
-
path¶ -
Get the geographic path of the ride as a list of :py:class:`Coordinates`. If you only want to get the path between to stops, just use the :py:class:`RideSegment` property with the same name. Falls back to just directly connecting the platform or stop coordinates if no other information is available.
Note
For serialization, the property
stopsis created containing a list of the serialized elements. EachRidePointelement can have the additional propertypath_to_nextcontaining a list of tupled py:class:Coordinates.-
class
Request¶ Submodel of
Searchable.Request.
-
class
Ride.Results¶ Submodel of
Searchable.Results.
-
-
class
RideSegment¶ -
*Submodel of :py:class:`TripPart`.* This class created by slicing
Rideobjects.This model is usable in the same way as a
Ride. Slicing it will return anotherRideSegmentfor the sameRide.Caution
Slicing a
Rideis inclusive! For example, slicing from element 2 to element 5 results in aRideSegmentdescribing the journey between element 2 and element 5, containing 4 elements in total!-
index([i])¶ Remove the item at the given position (default: last position) from the list.
You can also use
in.Attention
The following attributes are dynamic and can not be set.
-
path¶ -
Get the geographic path of the ride segment as a list of :py:class:`Coordinates`. Falls back to just directly connecting the platform or stop coordinates if no other information is available.
-
departure¶ The departure at the first
Stopof this segment asLiveTime. Shortcut forsegment[0].departure.
-
arrival¶ The arrival at the last
Stopof this segment asLiveTime. 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:])Don’t forget that Ride slicing is inclusive (see above)!
-
-
class
RidePoint(platform, arrival=None, departure=None)¶ Submodel of :py:class:`Serializable`.
LiveTime¶
-
class
LiveTime(time, delay=None)¶ Submodel of :py:class:`Serializable`.
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
-
expected_time¶ The (expected) actual time as a datetime.datetime object if real time data is available, otherwise the originally planned time.
Lines¶
-
class
Line(linetype=None)¶ Submodel of :py:class:`Collectable`.
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.
Note
For serialization, the string representation is used for
linetype.-
-
class
LineType(name)¶ Submodel of :py:class:`Serializable`.
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'
-
class
LineTypes(include=('', ), exclude=())¶ Submodel of :py:class:`Serializable`.
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 string representation of line types.-
Trips¶
-
class
Trip¶ Submodel of :py:class:`Searchable`.
A connection from a
GeoLocationto anotherGeoLocation.It consists of a list of
TripPartobjects. 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
GeoLocationof this trip.
-
destination¶ The end
GeoLocationof this trip.
-
departure¶ The departure at the first
GeoLocationof this trip asLiveTime. (If there are leadingWayobjects they need to have thedurationattribute set in order for this to work)
-
arrival¶ The arrival at the last
GeoLocationof this trip asLiveTime. (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
GeoLocationof the trip.
-
destination¶ Not None. The end
GeoLocationof the trip.
-
departure¶ The minimum departure time as
LiveTimeordatetime.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)
-
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
GeoLocationof the trip.
-
destination¶ Not None. The end
GeoLocationof the trip.
-
-
-
class
TripPart¶ Submodel of :py:class:`Serializable`.
Abstract base Class for Trip parts
Ways¶
-
class
Way(origin: Location, destination: Location, distance: int=None)¶ Submodel of :py:class:`TripPart`.
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.
Note
For serialization, the string representation is used for
linetypeand theWayEventobjects inevents.The property
pathis a list of tuple representations ofCoordinates.-
-
class
WayType(name)¶ Submodel of :py:class:`Serializable`.
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'
-
class
WayEvent(name, direction)¶ Submodel of :py:class:`Serializable`.
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
You can cast a
WayEventto string or tuple if needed:>>> str(WayEvent('escalator, 'down')) 'escalator.down' >>> tuple(WayEvent('escalator, 'down')) ('escalator', 'down')
Attention
The following attributes are dynamic and can not be set.
-
name¶ Not None.
stairs,escalatororelevator
-
direction¶ Not None.
upordown
-
Tickets¶
-
class
TicketList(all_types: bool=True)¶ Submodel of :py:class:`Serializable`.
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.
-
Submodels of Serializable.
-
class
TicketData(authority=None, level=None, price=None, price_child=None)¶ Submodel of :py:class:`Serializable`.
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.