luigi.server
Simple REST server that takes commands in a JSON payload
Interface to the Scheduler class.
See Using the Central Scheduler for more info.
Functions
|
|
|
convert UTC time string to time.struct_time: change datetime.datetime to time, return time.struct_time type |
|
Runs one instance of the API server. |
|
Classes
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Handle remote scheduling calls using rpc.RemoteSchedulerResponder. |
|
|
|
|
|
|
|
- class luigi.server.cors(*args, **kwargs)[source]
- enabled
A Parameter whose value is a
bool. This parameter has an implicit default value ofFalse. For the command line interface this means that the value isFalseunless you add"--the-bool-parameter"to your command without giving a parameter value. This is considered implicit parsing (the default). However, in some situations one might want to give the explicit bool value ("--the-bool-parameter true|false"), e.g. when you configure the default value to beTrue. This is called explicit parsing. When omitting the parameter value, it is still consideredTruebut to avoid ambiguities during argument parsing, make sure to always place bool parameters behind the task family on the command line when using explicit parsing.You can toggle between the two parsing modes on a per-parameter base via
class MyTask(luigi.Task): implicit_bool = luigi.BoolParameter(parsing=luigi.BoolParameter.IMPLICIT_PARSING) explicit_bool = luigi.BoolParameter(parsing=luigi.BoolParameter.EXPLICIT_PARSING)
or globally by
luigi.BoolParameter.parsing = luigi.BoolParameter.EXPLICIT_PARSING
for all bool parameters instantiated after this line.
- allow_any_origin
A Parameter whose value is a
bool. This parameter has an implicit default value ofFalse. For the command line interface this means that the value isFalseunless you add"--the-bool-parameter"to your command without giving a parameter value. This is considered implicit parsing (the default). However, in some situations one might want to give the explicit bool value ("--the-bool-parameter true|false"), e.g. when you configure the default value to beTrue. This is called explicit parsing. When omitting the parameter value, it is still consideredTruebut to avoid ambiguities during argument parsing, make sure to always place bool parameters behind the task family on the command line when using explicit parsing.You can toggle between the two parsing modes on a per-parameter base via
class MyTask(luigi.Task): implicit_bool = luigi.BoolParameter(parsing=luigi.BoolParameter.IMPLICIT_PARSING) explicit_bool = luigi.BoolParameter(parsing=luigi.BoolParameter.EXPLICIT_PARSING)
or globally by
luigi.BoolParameter.parsing = luigi.BoolParameter.EXPLICIT_PARSING
for all bool parameters instantiated after this line.
- allow_null_origin
A Parameter whose value is a
bool. This parameter has an implicit default value ofFalse. For the command line interface this means that the value isFalseunless you add"--the-bool-parameter"to your command without giving a parameter value. This is considered implicit parsing (the default). However, in some situations one might want to give the explicit bool value ("--the-bool-parameter true|false"), e.g. when you configure the default value to beTrue. This is called explicit parsing. When omitting the parameter value, it is still consideredTruebut to avoid ambiguities during argument parsing, make sure to always place bool parameters behind the task family on the command line when using explicit parsing.You can toggle between the two parsing modes on a per-parameter base via
class MyTask(luigi.Task): implicit_bool = luigi.BoolParameter(parsing=luigi.BoolParameter.IMPLICIT_PARSING) explicit_bool = luigi.BoolParameter(parsing=luigi.BoolParameter.EXPLICIT_PARSING)
or globally by
luigi.BoolParameter.parsing = luigi.BoolParameter.EXPLICIT_PARSING
for all bool parameters instantiated after this line.
- max_age
Parameter whose value is an
int.
- allowed_methods
Parameter whose value is a
str, and a base class for other parameter types.Parameters are objects set on the Task class level to make it possible to parameterize tasks. For instance:
class MyTask(luigi.Task): foo = luigi.Parameter() class RequiringTask(luigi.Task): def requires(self): return MyTask(foo="hello") def run(self): print(self.requires().foo) # prints "hello"
This makes it possible to instantiate multiple tasks, eg
MyTask(foo='bar')andMyTask(foo='baz'). The task will then have thefooattribute set appropriately.When a task is instantiated, it will first use any argument as the value of the parameter, eg. if you instantiate
a = TaskA(x=44)thena.x == 44. When the value is not provided, the value will be resolved in this order of falling priority:Any value provided on the command line:
To the root task (eg.
--param xyz)Then to the class, using the qualified task name syntax (eg.
--TaskA-param xyz).
With
[TASK_NAME]>PARAM_NAME: <serialized value>syntax. See Parameters from config IngestionAny default value set using the
defaultflag.
Parameter objects may be reused, but you must then set the
positional=Falseflag.
- allowed_headers
Parameter whose value is a
str, and a base class for other parameter types.Parameters are objects set on the Task class level to make it possible to parameterize tasks. For instance:
class MyTask(luigi.Task): foo = luigi.Parameter() class RequiringTask(luigi.Task): def requires(self): return MyTask(foo="hello") def run(self): print(self.requires().foo) # prints "hello"
This makes it possible to instantiate multiple tasks, eg
MyTask(foo='bar')andMyTask(foo='baz'). The task will then have thefooattribute set appropriately.When a task is instantiated, it will first use any argument as the value of the parameter, eg. if you instantiate
a = TaskA(x=44)thena.x == 44. When the value is not provided, the value will be resolved in this order of falling priority:Any value provided on the command line:
To the root task (eg.
--param xyz)Then to the class, using the qualified task name syntax (eg.
--TaskA-param xyz).
With
[TASK_NAME]>PARAM_NAME: <serialized value>syntax. See Parameters from config IngestionAny default value set using the
defaultflag.
Parameter objects may be reused, but you must then set the
positional=Falseflag.
- exposed_headers
Parameter whose value is a
str, and a base class for other parameter types.Parameters are objects set on the Task class level to make it possible to parameterize tasks. For instance:
class MyTask(luigi.Task): foo = luigi.Parameter() class RequiringTask(luigi.Task): def requires(self): return MyTask(foo="hello") def run(self): print(self.requires().foo) # prints "hello"
This makes it possible to instantiate multiple tasks, eg
MyTask(foo='bar')andMyTask(foo='baz'). The task will then have thefooattribute set appropriately.When a task is instantiated, it will first use any argument as the value of the parameter, eg. if you instantiate
a = TaskA(x=44)thena.x == 44. When the value is not provided, the value will be resolved in this order of falling priority:Any value provided on the command line:
To the root task (eg.
--param xyz)Then to the class, using the qualified task name syntax (eg.
--TaskA-param xyz).
With
[TASK_NAME]>PARAM_NAME: <serialized value>syntax. See Parameters from config IngestionAny default value set using the
defaultflag.
Parameter objects may be reused, but you must then set the
positional=Falseflag.
- allow_credentials
A Parameter whose value is a
bool. This parameter has an implicit default value ofFalse. For the command line interface this means that the value isFalseunless you add"--the-bool-parameter"to your command without giving a parameter value. This is considered implicit parsing (the default). However, in some situations one might want to give the explicit bool value ("--the-bool-parameter true|false"), e.g. when you configure the default value to beTrue. This is called explicit parsing. When omitting the parameter value, it is still consideredTruebut to avoid ambiguities during argument parsing, make sure to always place bool parameters behind the task family on the command line when using explicit parsing.You can toggle between the two parsing modes on a per-parameter base via
class MyTask(luigi.Task): implicit_bool = luigi.BoolParameter(parsing=luigi.BoolParameter.IMPLICIT_PARSING) explicit_bool = luigi.BoolParameter(parsing=luigi.BoolParameter.EXPLICIT_PARSING)
or globally by
luigi.BoolParameter.parsing = luigi.BoolParameter.EXPLICIT_PARSING
for all bool parameters instantiated after this line.
- allowed_origins
Parameter whose value is a
list.In the task definition, use
class MyTask(luigi.Task): grades = luigi.ListParameter() def run(self): sum = 0 for element in self.grades: sum += element avg = sum / len(self.grades)
At the command line, use
$ luigi --module my_tasks MyTask --grades <JSON string>
Simple example with two grades:
$ luigi --module my_tasks MyTask --grades '[100,70]'
It is possible to provide a JSON schema that should be validated by the given value:
class MyTask(luigi.Task): grades = luigi.ListParameter( schema={ "type": "array", "items": { "type": "number", "minimum": 0, "maximum": 10 }, "minItems": 1 } ) def run(self): sum = 0 for element in self.grades: sum += element avg = sum / len(self.grades)
Using this schema, the following command will work:
$ luigi --module my_tasks MyTask --numbers '[1, 8.7, 6]'
while these commands will fail because the parameter is not valid:
$ luigi --module my_tasks MyTask --numbers '[]' # must have at least 1 element $ luigi --module my_tasks MyTask --numbers '[-999, 999]' # elements must be in [0, 10]
Finally, the provided schema can be a custom validator:
custom_validator = jsonschema.Draft4Validator( schema={ "type": "array", "items": { "type": "number", "minimum": 0, "maximum": 10 }, "minItems": 1 } ) class MyTask(luigi.Task): grades = luigi.ListParameter(schema=custom_validator) def run(self): sum = 0 for element in self.grades: sum += element avg = sum / len(self.grades)
- class luigi.server.RPCHandler(*args, **kwargs)[source]
Handle remote scheduling calls using rpc.RemoteSchedulerResponder.
- post(method)
- class luigi.server.BaseTaskHistoryHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]
- class luigi.server.AllRunHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]
- class luigi.server.SelectedRunHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]
- luigi.server.from_utc(utcTime, fmt=None)[source]
convert UTC time string to time.struct_time: change datetime.datetime to time, return time.struct_time type
- class luigi.server.RecentRunHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]
- class luigi.server.ByNameHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]
- class luigi.server.ByIdHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]
- class luigi.server.ByTaskIdHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]
- class luigi.server.ByParamsHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]
- class luigi.server.RootPathHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]
- class luigi.server.MetricsHandler(application: Application, request: HTTPServerRequest, **kwargs: Any)[source]