a4i 0.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
a4i/__init__.py ADDED
@@ -0,0 +1,84 @@
1
+ """a4i - a CLI for the Cisco ACI (APIC) REST API, and the library behind it.
2
+
3
+ import a4i
4
+
5
+ with a4i.Client("apic1.example.com") as client:
6
+ client.login("admin", password)
7
+ data = client.get("fvTenant", kind="class", query_target="subtree")
8
+
9
+ async with a4i.AsyncClient("apic1.example.com") as client:
10
+ await client.login("admin", password)
11
+ data = await client.get("fvTenant", kind="class", query_target="subtree")
12
+
13
+ The names below are resolved on first use rather than imported here. Reaching
14
+ :class:`~a4i.client.Client` pulls in the whole request and comparison stack,
15
+ which costs more than a whole shell completion -- and completion runs through
16
+ this package on every tab press. ``__version__`` is held back for the same
17
+ reason: reading it takes importlib.metadata, which alone costs more than the
18
+ completion it would be paid for.
19
+ """
20
+
21
+ from __future__ import annotations
22
+
23
+ from typing import TYPE_CHECKING
24
+
25
+ if TYPE_CHECKING:
26
+ # Redundant aliases: these exist for a type checker and an IDE, which cannot
27
+ # follow __getattr__ below. Nothing is imported at run time.
28
+ __version__: str
29
+
30
+ from a4i.client import AsyncClient as AsyncClient
31
+ from a4i.client import Client as Client
32
+ from a4i.errors import A4iError as A4iError
33
+ from a4i.errors import ApicError as ApicError
34
+ from a4i.errors import NotLoggedInError as NotLoggedInError
35
+ from a4i.errors import ReadOnlyError as ReadOnlyError
36
+ from a4i.errors import SessionExpiredError as SessionExpiredError
37
+ from a4i.mo import Change as Change
38
+
39
+ # What __version__ reads when the package is not installed, which is what an
40
+ # uninstalled source tree looks like to importlib.metadata.
41
+ _FALLBACK_VERSION = "0.0.1"
42
+
43
+ # Public name -> the module it lives in.
44
+ _EXPORTS = {
45
+ "Client": "a4i.client",
46
+ "AsyncClient": "a4i.client",
47
+ "Change": "a4i.mo",
48
+ "A4iError": "a4i.errors",
49
+ "ApicError": "a4i.errors",
50
+ "NotLoggedInError": "a4i.errors",
51
+ "ReadOnlyError": "a4i.errors",
52
+ "SessionExpiredError": "a4i.errors",
53
+ }
54
+
55
+ __all__ = ["__version__", *_EXPORTS]
56
+
57
+
58
+ def __getattr__(name: str) -> object:
59
+ if name == "__version__":
60
+ # The version is whatever the build recorded, which hatch-vcs takes from
61
+ # the git tag, so nothing here has to be bumped for a release.
62
+ from importlib.metadata import PackageNotFoundError, version
63
+
64
+ resolved: object
65
+ try:
66
+ resolved = version("a4i")
67
+ except PackageNotFoundError:
68
+ resolved = _FALLBACK_VERSION
69
+ globals()[name] = resolved
70
+ return resolved
71
+
72
+ module = _EXPORTS.get(name)
73
+ if module is None:
74
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
75
+ import importlib
76
+
77
+ value = getattr(importlib.import_module(module), name)
78
+ # Cached in the module's own namespace, so the lookup happens once.
79
+ globals()[name] = value
80
+ return value
81
+
82
+
83
+ def __dir__() -> list[str]:
84
+ return sorted(__all__)
a4i/__main__.py ADDED
@@ -0,0 +1,8 @@
1
+ """Entry point: ``a4i`` console script and ``python -m a4i``."""
2
+
3
+ from __future__ import annotations
4
+
5
+ from a4i.cli import main
6
+
7
+ if __name__ == "__main__":
8
+ raise SystemExit(main())