Skip to main content

xal

xal is a Python library which provides an high-level API to interact with system resources (files, commands, …) and low-level execution via third-parties (stdlib, Fabric, Salt, …).

The concept is you open a session in system, then you run commands within the session:

  • session is specific, it holds the execution context, it knows the low-level implementation.

  • commands use a generic API. You could run the same commands in another session.

Example

Let’s initialize a session on local system:

>>> import xal
>>> local_session = xal.LocalSession()

In this session, we can manage files:

>>> path = local_session.path('hello-xal.txt')
>>> path.exists()
False
>>> written = path.open('w').write(u'Hello world!')
>>> path.exists()
True
>>> print path.open().read()
Hello world!
>>> path.unlink()
>>> path.exists()
False

We can also execute sh commands:

>>> result = local_session.sh.run(u"echo 'Goodbye!'")
>>> print result.stdout
Goodbye!
<BLANKLINE>

Now let’s make a function that does the same. It takes the session as input argument:

>>> def hello(session):
...     path = session.path('hello-xal.txt')
...     path.open('w').write(u"Hello world!")
...     print path.open().read()
...     path.unlink()
...     print session.sh.run(u"echo 'Goodbye!'").stdout

Of course, we can run it in local session:

>>> hello(local_session)
Hello world!
Goodbye!
<BLANKLINE>

What’s nice is that we can reuse the same function in another session. Let’s create a remote SSH session using Fabric…

>>> remote_session = xal.FabricSession(host='localhost')

… then just run the same function with this remote session:

>>> hello(remote_session)
Hello world!
Goodbye!
<BLANKLINE>

Motivations

xal ideas are:

  • Python users (including sysadmins and devops) have a consistent and unified API to write scripts that perform operations on system.

  • such scripts are portable, i.e. they can be executed in various environments. Whatever the operating system, whatever the protocol to connect to and communicate with the system…

  • Python community can share libraries that are compatible with tools such as Fabric, zc.buildout, Salt, Ansible…

  • it is easier to switch from one tool to another: reconfigure the session, don’t change the scripts. Develop scripts locally, test them remotely via Fabric, distribute them using Salt… or vice-versa.

Project’s status

Today: xal is a proof-of-concept. It focuses on sample implementation of basic features such as managing files and directories, or executing sh commands. The idea is that, as a Python user, you can give it a try and, if you like it, use it for simple tasks.

Tomorrow, depending on feedback from community, xal may improve or be deprecated. As xal’s author, I would like the following things to happen:

  • increased stability and performances for current features.

  • more execution contexts (i.e. sessions): Salt, Fabric as sudoer, …

  • more resources: users, system packages, …

  • better API, preferrably built as PEPs. Just as xal’s proof of concept tries to mimic pathlib, there could be a PEP related to every resource. Sh commands (a.k.a. replacement for subprocess) are an epic example.

As xal’s author, I can’t do it alone. If you’d like to help:

  • provide feedback. Do you like xal? What do you dislike in xal? Your feedback matters!

  • join the project on Github.

Ressources

Metadata

Release files for xal 0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xal 0.3
File Size Uploaded Provenance
xal-0.3.tar.gz 17.1 kB Without provenance Details

Release files / xal-0.3.tar.gz

Download URL xal-0.3.tar.gz
Size 17.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a1f2d03ba4bdba7f44e43dfd4eb0a25abd8d813c3312d0939d543fb0b128d0e2
BLAKE2b-256 checksum
How to use checksums
0a3d76e588aa243fac447a244cc1813ec7e198a894c56c019fe8b90065a0a5eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for xal 0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.3 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page