Skip to main content

Atum is a tiny Python library that you can use to emulate the basic functionality of Erlang’s atom in your Python scripts.

Status: Beta; this is an experiment.

Erlang documentation:

3.3 Atom

An atom is a literal, a constant with name. An atom is to be enclosed in single quotes (’) if it does not begin with a lower-case letter or if it contains other characters than alphanumeric characters, underscore (_), or @. Examples:

hello
phone_number
'Monday'
'phone number'

http://erlang.org/doc/reference_manual/data_types.html

Unlike Erlang’s atom, atum does not impose the same limitations. You may import any valid Python name from atum - even all uppercase.

Install

$ pip install atum

Examples

Instead of writing:

@app.route('/register', methods=['GET', 'POST'])
def register():
    pass

You could write:

from atum import GET, POST

@app.route('/register', methods=[GET, POST])
def register():
    pass

This might be useful if you use autocompletion. Another benefit is exceptions occur sooner in case of typos, since the interpreter itself validates the imported names. Pay attention when importing, simply tab-to-complete later.

You can compare an atum with another atum or a string.

from atum import machine, human

assert human == human
assert machine == machine
assert machine == 'machine'
assert human != machine
assert human is human
assert machine is machine

Atums also make for readable sentinel values or event-names.

from atum import user_is_awake
from queue import Queue

q = Queue()

q.put(user_is_awake)

assert q.get() == user_is_awake

Technical Details

Atum simply imports Python strings with the same content as their name.

Here is the content of atum.py in its entirety:

import sys as _sys

# intern() is a builtin in Python 2.
if _sys.version_info > (3, 0):
    intern = _sys.intern


class Atum(object):
    def __getattr__(self, item):
        if item.startswith('__'):
            return self.__getattribute__(item)
        return intern(item)

    def __getitem__(self, item):
        return item


_sys.modules[__name__] = Atum()

Known Issues

  • Atum does not support using @ in imported names as Python’s syntax does not allow it.

Metadata

Release files for atum 0.3.0-1

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

Source distribution (sdist)

Source distribution for atum 0.3.0-1
File Size Uploaded
atum-0.3.0-1.tar.gz 2.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for atum 0.3.0-1
File Interpreter ABI Platform
atum-0.3.0.post1-py3-none-any.whl Python 3 none any Details

Total release size: 5.6 kB

Release files / atum-0.3.0-1.tar.gz

Download URL atum-0.3.0-1.tar.gz
Size 2.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3f0b9fbc1d7028278acf57bf844722a87f1e8c439b26f91f6b2646fb8c8fa10b
BLAKE2b-256 checksum
How to use checksums
cb69eb0029c5786f35e4b269814b78f956e640a1cbde4d85b0865dd64dc4ac91
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / atum-0.3.0.post1-py3-none-any.whl

Download URL atum-0.3.0.post1-py3-none-any.whl
Size 2.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cbd3a8f01f54b78fe1954d1f15f73789342d49c7ad139bb3cbcac52285ba78a7
BLAKE2b-256 checksum
How to use checksums
c9d3cefd1021739cc5b6d3024f8a162072a3202dead057a5eb6d1d28630a4f5a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.3.0-1 This release

2 release files

0.3.0

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

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