Project
An OrbiterProject
holds everything necessary to render an Airflow Project.
It is generated by a TranslationRuleset.translate_fn
.
Diagram¶
classDiagram
direction LR
OrbiterProject --> "many" OrbiterConnection
OrbiterProject --> "many" OrbiterDAG
OrbiterProject --> "many" OrbiterEnvVar
OrbiterProject --> "many" OrbiterInclude
OrbiterProject --> "many" OrbiterPool
OrbiterProject --> "many" OrbiterRequirement
OrbiterProject --> "many" OrbiterVariable
class OrbiterProject["orbiter.objects.project.OrbiterProject"] {
connections: Dict[str, OrbiterConnection]
dags: Dict[str, OrbiterDAG]
env_vars: Dict[str, OrbiterEnvVar]
includes: Dict[str, OrbiterInclude]
pools: Dict[str, OrbiterPool]
requirements: Set[OrbiterRequirement]
variables: Dict[str, OrbiterVariable]
}
click OrbiterProject href "#orbiter.objects.project.OrbiterProject" "OrbiterProject Documentation"
class OrbiterConnection["orbiter.objects.connection.OrbiterConnection"] {
conn_id: str
conn_type: str
**kwargs
}
click OrbiterConnection href "#orbiter.objects.connection.OrbiterConnection" "OrbiterConnection Documentation"
OrbiterDAG --> "many" OrbiterInclude
OrbiterDAG --> "many" OrbiterConnection
OrbiterDAG --> "many" OrbiterEnvVar
OrbiterDAG --> "many" OrbiterRequirement
OrbiterDAG --> "many" OrbiterVariable
class OrbiterDAG["orbiter.objects.dag.OrbiterDAG"] {
imports: List[OrbiterRequirement]
file_path: str
dag_id: str
schedule: str | OrbiterTimetable | None
catchup: bool
start_date: DateTime
tags: List[str]
default_args: Dict[str, Any]
params: Dict[str, Any]
doc_md: str | None
tasks: Dict[str, OrbiterOperator]
kwargs: dict
orbiter_kwargs: dict
orbiter_conns: Set[OrbiterConnection]
orbiter_vars: Set[OrbiterVariable]
orbiter_env_vars: Set[OrbiterEnvVar]
orbiter_includes: Set[OrbiterInclude]
}
class OrbiterEnvVar["orbiter.objects.env_var.OrbiterEnvVar"] {
key: str
value: str
}
click OrbiterEnvVar href "#orbiter.objects.env_var.OrbiterEnvVar" "OrbiterEnvVar Documentation"
class OrbiterInclude["orbiter.objects.include.OrbiterInclude"] {
filepath: str
contents: str
}
click OrbiterInclude href "#orbiter.objects.include.OrbiterInclude" "OrbiterInclude Documentation"
class OrbiterPool["orbiter.objects.pool.OrbiterPool"] {
name: str
description: str | None
slots: int | None
}
click OrbiterPool href "#orbiter.objects.pool.OrbiterPool" "OrbiterPool Documentation"
class OrbiterRequirement["orbiter.objects.requirement.OrbiterRequirement"] {
package: str | None
module: str | None
names: List[str] | None
sys_package: str | None
}
click OrbiterRequirement href "#orbiter.objects.requirement.OrbiterRequirement" "OrbiterRequirement Documentation"
class OrbiterVariable["orbiter.objects.variable.OrbiterVariable"] {
key: str
value: str
}
click OrbiterVariable href "#orbiter.objects.variable.OrbiterVariable" "OrbiterVariable Documentation"
orbiter.objects.connection.OrbiterConnection ¶
An Airflow
Connection,
rendered to an
airflow_settings.yaml
file.
See also other Connection documentation.
>>> OrbiterConnection(
... conn_id="my_conn_id", conn_type="mysql", host="localhost", port=3306, login="root"
... ).render()
{'conn_id': 'my_conn_id', 'conn_type': 'mysql', 'conn_host': 'localhost', 'conn_port': 3306, 'conn_login': 'root'}
Note
Use the utility conn_id
function to generate both an OrbiterConnection
and connection property for an operator
Parameters:
Name | Type | Description |
---|---|---|
conn_id |
str
|
The ID of the connection |
conn_type |
str, optional
|
The type of the connection, always lowercase. Defaults to 'generic' |
**kwargs |
Additional properties for the connection |
orbiter.objects.env_var.OrbiterEnvVar ¶
orbiter.objects.include.OrbiterInclude ¶
Represents an included file in an /include
directory
Parameters:
Name | Type | Description |
---|---|---|
filepath |
str
|
The relative path (from the output directory) to write the file to |
contents |
str
|
The contents of the file |
orbiter.objects.pool.OrbiterPool ¶
An Airflow
Pool,
rendered to an
airflow_settings.yaml
file.
>>> OrbiterPool(name="foo", description="bar", slots=5).render()
{'pool_name': 'foo', 'pool_description': 'bar', 'pool_slot': 5}
Note
Use the utility pool
function to easily generate both an OrbiterPool
and pool
property for an operator
Parameters:
Name | Type | Description |
---|---|---|
name |
str
|
The name of the pool |
description |
str, optional
|
The description of the pool |
slots |
int, optional
|
The number of slots in the pool. Defaults to 128 |
orbiter.objects.requirement.OrbiterRequirement ¶
A requirement for a project (e.g. apache-airflow-providers-google
), and it's representation in the DAG file.
Renders via the DAG File (as an import statement),
requirements.txt
, and packages.txt
Tip
If a given requirement has multiple packages required,
it can be defined as multiple OrbiterRequirement
objects.
Example:
Parameters:
Name | Type | Description |
---|---|---|
package |
str, optional
|
e.g. |
module |
str, optional
|
e.g. |
names |
List[str], optional
|
e.g. |
sys_package |
Set[str], optional
|
e.g. |
orbiter.objects.variable.OrbiterVariable ¶
An Airflow
Variable,
rendered to an
airflow_settings.yaml
file.
>>> OrbiterVariable(key="foo", value="bar").render()
{'variable_value': 'bar', 'variable_name': 'foo'}
Parameters:
Name | Type | Description |
---|---|---|
key |
str
|
The key of the variable |
value |
str
|
The value of the variable |
orbiter.objects.project.OrbiterProject ¶
Holds everything necessary to render an Airflow Project.
This is generated by a TranslationRuleset.translate_fn
.
Tip
They can be added together
>>> OrbiterProject() + OrbiterProject()
OrbiterProject(dags=[], requirements=[], pools=[], connections=[], variables=[], env_vars=[])
And compared
Parameters:
Name | Type | Description |
---|---|---|
connections |
Dict[str, OrbiterConnection]
|
A dictionary of OrbiterConnections |
dags |
Dict[str, OrbiterDAG]
|
A dictionary of OrbiterDAGs |
env_vars |
Dict[str, OrbiterEnvVar]
|
A dictionary of OrbiterEnvVars |
includes |
Dict[str, OrbiterInclude]
|
A dictionary of OrbiterIncludes |
pools |
Dict[str, OrbiterPool]
|
A dictionary of OrbiterPools |
requirements |
Set[OrbiterRequirement]
|
A set of OrbiterRequirements |
variables |
Dict[str, OrbiterVariable]
|
A dictionary of OrbiterVariables |
Source code in orbiter/objects/project.py
add_connections ¶
add_connections(
connections: (
OrbiterConnection | Iterable[OrbiterConnection]
),
) -> "OrbiterProject"
Add OrbiterConnections
to the Project
or override an existing connection with new properties
>>> OrbiterProject().add_connections(OrbiterConnection(conn_id='foo')).connections
{'foo': OrbiterConnection(conn_id=foo, conn_type=generic)}
>>> OrbiterProject().add_connections(
... [OrbiterConnection(conn_id='foo'), OrbiterConnection(conn_id='bar')]
... ).connections
{'foo': OrbiterConnection(conn_id=foo, conn_type=generic), 'bar': OrbiterConnection(conn_id=bar, conn_type=generic)}
Tip
Validation requires an OrbiterConnection
to be passed
>>> # noinspection PyTypeChecker
... OrbiterProject().add_connections('foo')
... # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
pydantic_core._pydantic_core.ValidationError: ...
>>> # noinspection PyTypeChecker
>>> OrbiterProject().add_connections(['foo'])
... # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
pydantic_core._pydantic_core.ValidationError: ...
Parameters:
Name | Type | Description |
---|---|---|
connections |
OrbiterConnection | Iterable[OrbiterConnection]
|
List of |
Returns:
Type | Description |
---|---|
OrbiterProject
|
self |
Source code in orbiter/objects/project.py
add_dags ¶
add_dags(
dags: OrbiterDAG | Iterable[OrbiterDAG],
) -> "OrbiterProject"
Add OrbiterDAGs (and any OrbiterRequirements, OrbiterConns, OrbiterVars, OrbiterPools, OrbiterEnvVars, etc.) to the Project.
>>> OrbiterProject().add_dags(OrbiterDAG(dag_id='foo', file_path="")).dags['foo'].repr()
'OrbiterDAG(dag_id=foo, schedule=None, start_date=1970-01-01 00:00:00, catchup=False)'
>>> dags = OrbiterProject().add_dags(
... [OrbiterDAG(dag_id='foo', file_path=""), OrbiterDAG(dag_id='bar', file_path="")]
... ).dags; dags['foo'].repr(), dags['bar'].repr()
... # doctest: +NORMALIZE_WHITESPACE
('OrbiterDAG(dag_id=foo, schedule=None, start_date=1970-01-01 00:00:00, catchup=False)', 'OrbiterDAG(dag_id=bar, schedule=None, start_date=1970-01-01 00:00:00, catchup=False)')
>>> # An example adding a little of everything, including deeply nested things
... from orbiter.objects.operators.bash import OrbiterBashOperator
>>> from orbiter.objects.timetables.multi_cron_timetable import OrbiterMultiCronTimetable
>>> from orbiter.objects.callbacks.smtp import OrbiterSmtpNotifierCallback
>>> OrbiterProject().add_dags(OrbiterDAG(
... dag_id='foo', file_path="",
... orbiter_env_vars={OrbiterEnvVar(key="foo", value="bar")},
... orbiter_includes={OrbiterInclude(filepath='foo.txt', contents="Hello, World!")},
... schedule=OrbiterMultiCronTimetable(cron_defs=["0 */5 * * *", "0 */3 * * *"]),
... tasks={'foo': OrbiterTaskGroup(task_group_id="foo",
... tasks=[OrbiterBashOperator(
... task_id='foo', bash_command='echo "Hello, World!"',
... orbiter_pool=OrbiterPool(name='foo', slots=1),
... orbiter_vars={OrbiterVariable(key='foo', value='bar')},
... orbiter_conns={OrbiterConnection(conn_id='foo')},
... orbiter_env_vars={OrbiterEnvVar(key='foo', value='bar')},
... on_success_callback=OrbiterSmtpNotifierCallback(
... to="foo@bar.com",
... smtp_conn_id="SMTP",
... orbiter_conns={OrbiterConnection(conn_id="SMTP", conn_type="smtp")}
... )
... )]
... )}
... ))
... # doctest: +NORMALIZE_WHITESPACE
OrbiterProject(dags=[foo],
requirements=[OrbiterRequirements(names=[DAG], package=apache-airflow, module=airflow, sys_package=None),
OrbiterRequirements(names=[BashOperator], package=apache-airflow, module=airflow.operators.bash, sys_package=None),
OrbiterRequirements(names=[send_smtp_notification], package=apache-airflow-providers-smtp, module=airflow.providers.smtp.notifications.smtp, sys_package=None),
OrbiterRequirements(names=[TaskGroup], package=apache-airflow, module=airflow.utils.task_group, sys_package=None),
OrbiterRequirements(names=[MultiCronTimetable], package=croniter, module=multi_cron_timetable, sys_package=None),
OrbiterRequirements(names=[DateTime,Timezone], package=pendulum, module=pendulum, sys_package=None)],
pools=['foo'],
connections=['SMTP', 'foo'],
variables=['foo'],
env_vars=['foo'])
Tip
Validation requires an OrbiterDAG
to be passed
>>> # noinspection PyTypeChecker
... OrbiterProject().add_dags('foo')
... # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
pydantic_core._pydantic_core.ValidationError: ...
>>> # noinspection PyTypeChecker
>>> OrbiterProject().add_dags(['foo'])
... # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
pydantic_core._pydantic_core.ValidationError: ...
Parameters:
Name | Type | Description |
---|---|---|
dags |
OrbiterDAG | Iterable[OrbiterDAG]
|
List of OrbiterDAGs |
Returns:
Type | Description |
---|---|
OrbiterProject
|
self |
Source code in orbiter/objects/project.py
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 |
|
add_env_vars ¶
add_env_vars(
env_vars: OrbiterEnvVar | Iterable[OrbiterEnvVar],
) -> "OrbiterProject"
Add OrbiterEnvVars to the Project or override an existing env var with new properties
>>> OrbiterProject().add_env_vars(OrbiterEnvVar(key="foo", value="bar")).env_vars
{'foo': OrbiterEnvVar(key='foo', value='bar')}
>>> OrbiterProject().add_env_vars([OrbiterEnvVar(key="foo", value="bar")]).env_vars
{'foo': OrbiterEnvVar(key='foo', value='bar')}
Tip
Validation requires an OrbiterEnvVar
to be passed
>>> # noinspection PyTypeChecker
... OrbiterProject().add_env_vars('foo')
... # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
pydantic_core._pydantic_core.ValidationError: ...
>>> # noinspection PyTypeChecker
... OrbiterProject().add_env_vars(['foo'])
... # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
pydantic_core._pydantic_core.ValidationError: ...
Parameters:
Name | Type | Description |
---|---|---|
env_vars |
OrbiterEnvVar | Iterable[OrbiterEnvVar]
|
List of OrbiterEnvVar |
Returns:
Type | Description |
---|---|
OrbiterProject
|
self |
Source code in orbiter/objects/project.py
add_includes ¶
add_includes(
includes: OrbiterInclude | Iterable[OrbiterInclude],
) -> "OrbiterProject"
Add OrbiterIncludes to the Project or override an existing OrbiterInclude with new properties
>>> OrbiterProject().add_includes(OrbiterInclude(filepath="foo", contents="bar")).includes
{'foo': OrbiterInclude(filepath='foo', contents='bar')}
>>> OrbiterProject().add_includes([OrbiterInclude(filepath="foo", contents="bar")]).includes
{'foo': OrbiterInclude(filepath='foo', contents='bar')}
Tip
Validation requires an OrbiterInclude
to be passed
>>> # noinspection PyTypeChecker
... OrbiterProject().add_includes('foo')
... # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
pydantic_core._pydantic_core.ValidationError: ...
>>> # noinspection PyTypeChecker
... OrbiterProject().add_includes(['foo'])
... # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
pydantic_core._pydantic_core.ValidationError: ...
Parameters:
Name | Type | Description |
---|---|---|
includes |
OrbiterInclude | Iterable[OrbiterInclude]
|
List of OrbiterIncludes |
Returns:
Type | Description |
---|---|
OrbiterProject
|
self |
Source code in orbiter/objects/project.py
add_pools ¶
add_pools(
pools: OrbiterPool | Iterable[OrbiterPool],
) -> "OrbiterProject"
Add OrbiterPool to the Project or override existing pools with new properties
>>> OrbiterProject().add_pools(OrbiterPool(name="foo", slots=1)).pools
{'foo': OrbiterPool(name='foo', description='', slots=1)}
>>> ( OrbiterProject()
... .add_pools([OrbiterPool(name="foo", slots=1)])
... .add_pools([OrbiterPool(name="foo", slots=2)])
... .pools
... )
{'foo': OrbiterPool(name='foo', description='', slots=2)}
Tip
Validation requires an OrbiterPool
to be passed
>>> # noinspection PyTypeChecker
... OrbiterProject().add_pools('foo')
... # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
pydantic_core._pydantic_core.ValidationError: ...
>>> # noinspection PyTypeChecker
... OrbiterProject().add_pools(['foo'])
... # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
pydantic_core._pydantic_core.ValidationError: ...
Parameters:
Name | Type | Description |
---|---|---|
pools |
OrbiterPool | Iterable[OrbiterPool]
|
List of OrbiterPools |
Returns:
Type | Description |
---|---|
OrbiterProject
|
self |
Source code in orbiter/objects/project.py
add_requirements ¶
add_requirements(
requirements: (
OrbiterRequirement | Iterable[OrbiterRequirement]
),
) -> "OrbiterProject"
Add OrbiterRequirements to the Project or override an existing requirement with new properties
>>> OrbiterProject().add_requirements(
... OrbiterRequirement(package="apache-airflow", names=['foo'], module='bar'),
... ).requirements
{OrbiterRequirements(names=[foo], package=apache-airflow, module=bar, sys_package=None)}
>>> OrbiterProject().add_requirements(
... [OrbiterRequirement(package="apache-airflow", names=['foo'], module='bar')],
... ).requirements
{OrbiterRequirements(names=[foo], package=apache-airflow, module=bar, sys_package=None)}
Tip
Validation requires an OrbiterRequirement
to be passed
>>> # noinspection PyTypeChecker
... OrbiterProject().add_requirements('foo')
... # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
pydantic_core._pydantic_core.ValidationError: ...
>>> # noinspection PyTypeChecker
>>> OrbiterProject().add_requirements(['foo'])
... # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
pydantic_core._pydantic_core.ValidationError: ...
Parameters:
Name | Type | Description |
---|---|---|
requirements |
OrbiterRequirement | Iterable[OrbiterRequirement]
|
List of OrbiterRequirements |
Returns:
Type | Description |
---|---|
OrbiterProject
|
self |
Source code in orbiter/objects/project.py
add_variables ¶
add_variables(
variables: OrbiterVariable | Iterable[OrbiterVariable],
) -> "OrbiterProject"
Add OrbiterVariables to the Project or override an existing variable with new properties
>>> OrbiterProject().add_variables(OrbiterVariable(key="foo", value="bar")).variables
{'foo': OrbiterVariable(key='foo', value='bar')}
>>> OrbiterProject().add_variables([OrbiterVariable(key="foo", value="bar")]).variables
{'foo': OrbiterVariable(key='foo', value='bar')}
Tip
Validation requires an OrbiterVariable
to be passed
>>> # noinspection PyTypeChecker
... OrbiterProject().add_variables('foo')
... # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
pydantic_core._pydantic_core.ValidationError: ...
>>> # noinspection PyTypeChecker
... OrbiterProject().add_variables(['foo'])
... # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
pydantic_core._pydantic_core.ValidationError: ...
Parameters:
Name | Type | Description |
---|---|---|
variables |
OrbiterVariable | Iterable[OrbiterVariable]
|
List of OrbiterVariable |
Returns:
Type | Description |
---|---|
OrbiterProject
|
self |
Source code in orbiter/objects/project.py
analyze ¶
Print an analysis of the project to the console.
Tip
Looks for a specific [task_type=XYZ]
in the Task's doc_md
property
or uses type(task)
to infer the type of task.
>>> from orbiter.objects.operators.empty import OrbiterEmptyOperator
>>> OrbiterProject().add_dags([
... OrbiterDAG(file_path="", dag_id="foo", orbiter_kwargs={"file_path": "foo.py"},
... tasks={"bar": OrbiterEmptyOperator(task_id="bar")}
... ),
... OrbiterDAG(file_path="", dag_id="baz", orbiter_kwargs={"file_path": "baz.py"},
... tasks={"bop": OrbiterEmptyOperator(task_id="bop")}
... )
... ]).analyze()
... # doctest: +ELLIPSIS
┏━...
...Analysis...
┗━...
<BLANKLINE>
<BLANKLINE>
DAGs OrbiterEmptyOperator
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
foo.py 1 1
baz.py 1 1
Totals 2 2
<BLANKLINE>
Source code in orbiter/objects/project.py
615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 |
|