Skip to main content

A simple Python package

Project description

spicy ids for Python

Inspiration and acknowledgments

This package is inspired by django-spicy-id by Mike W.

Package introduction

An unofficial name, spicy ids are unique-ish names for different objects: tables, records, ids, etc. The idea behind this nomenclature is to use a non-referential way to identify objects in a database-like environment.

The structure of a spicy id is as follows:

<object_identifier>_<randomly generated string>[-<masked operation timestamp>]
  • object identifier: the type of object being stored. As a good practice, I encourage the use of short names: rec for records, row for rows, etc.
  • randomly generated string: a unique-ish string that identifies the single record. This allows the masking of the number of records (a common complaint for autoincremental ids) and better identification.
  • (optional) masked operation timestamp: for increased security and uniqueness, a masked timestamp can be added to the object id

Examples of spicy ids would be:

  • For a record without timestamp, rec_1EwvcRbnmkora13
  • For a table without timestamp, tbl_TVDA2134vsfaoin2
  • For a generic object with timestamp, obj_1jni21n9ASDF321va-4203463

Why Spicy Ids?

Mike W provided an excellent summary on why to use spicy ids: (https://github.com/mik3y/django-spicy-id?tab=readme-ov-file#why-use-spicy-ids)

I would add the following reasons:

  • Standard object nomenclature over microservices and system swarms: if nomenclature becomes standard across your platform environment, the whole project is less prone to errors.
  • API expressivity: designing APIs with plain object identificators, such as autoincremental ids, makes debugging API endpoints and interactions harder. By having a standard approach to objects, the API is less prone to unsuspected errors, since you always know which type of object you're expecting.
  • Better data governance: by defining object standards, data governance follows suite on several other object interactions.

Installation

Requirements

Spicy Ids have been tested on Python 3.12.6. You may use it with a lower version, but I cannot guarantee its functionality will behave as expected.

  • Python version: 3.12.6 or greater
  • Dependencies:
    • loggerLogs (GitHub Python package)

pip package

Install the Python package from pip:

> pip install python-spicyid

GitHub repo

Install the Python package from the GitHub release:

> pip install git+https://github.com/DarkestAbed/python-spicyids.git

Usage

>>> from spicyid import SpicyId
>>> print(SpicyId(obj_type="rec", length=10, timestamp=False))
rec_u8rPJn3AlM
>>> print(SpicyId(obj_type="rec", length=10, timestamp=True))
rec_a0Og9su1mU-6961365929088
>>> spicyid.get_object_type(SpicyId(obj_type="tbl", length=25))
'Object type is table'
>>> spicyid.get_object_timestamp(SpicyId(obj_type="tbl", length=25))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/javi/aNewHome/Code/tests/venv/lib/python3.12/site-packages/spicyid/get_object_values.py", line 30, in get_object_timestamp
    raise ValueError("The provided Spicy Id is not timestamped.")
ValueError: The provided Spicy Id is not timestamped.

Sample script

from spicyid import SpicyId, get_object_timestamp, get_object_type


def create_spicy_id() -> str | SpicyId:
    spicy_id = SpicyId(
        obj_type="rec",     ## object type for the id
        length=25,          ## length of the random string
        timestamp=True,     ## should the id include a timestamp string?
    )
    print(spicy_id)
    return spicy_id


def get_timestamp() -> None:
    spicy_id = SpicyId("rec", 20, True)
    res = get_object_timestamp(spicy_id=spicy_id)
    print(res)
    ## if we test a non-timestamped spicy id, a ValueError is raised
    try:
        get_object_timestamp(SpicyId("obj", 10, False))
    except Exception as e:
        print("An exception occurred:", e)
    return None


def get_type() -> None:
    ## several standard objects are included
    print(get_object_type(SpicyId("tbl", 10,)))
    print(get_object_type(SpicyId("vw", 10,)))
    print(get_object_type(SpicyId("lst", 10,)))
    return None


def main() -> None:
    create_spicy_id()
    get_timestamp()
    get_type()
    return None


if __name__ == "__main__":
    main()
else:
    pass

Changelog

See CHANGELOG.md for a summary of changes.

Roadmap and WIP

  • Use different separators than underscore (_)
  • Extend the standard list of objects
  • Encrypt the timestamp using different, better methods

Contributions

If you want to contribute to this package, please fork the code and send a pull request.

Issues and comments

If you want to place an issue or start a conversation around this package, please do so on the Issues section.

The Unlicense Link to license steward's version: Link

This is free and unencumbered software released into the public domain.

Anyone is free to copy, modify, publish, use, compile, sell, or distribute this software, either in source code form or as a compiled binary, for any purpose, commercial or non-commercial, and by any means.

In jurisdictions that recognize copyright laws, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

For more information, please refer to http://unlicense.org/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spicyid-1.0.1.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

spicyid-1.0.1-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file spicyid-1.0.1.tar.gz.

File metadata

  • Download URL: spicyid-1.0.1.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for spicyid-1.0.1.tar.gz
Algorithm Hash digest
SHA256 835123732cce2d54f2102405d2182d876313bbdd8f6b08ed0c881f4eeb4624ab
MD5 46417f6ee0afb5367c0c7b13f41a1af3
BLAKE2b-256 fb018b7cce3a44dd3aa7eecff124b57be7ecd487cbd1ce3f8022bafc24c3aa2c

See more details on using hashes here.

File details

Details for the file spicyid-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: spicyid-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 8.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for spicyid-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 803f961795fe543d11efd6217d42fa1415e1e406855fbb22b9f3d06797cec3e6
MD5 a4d050ff96382b38bb7cdf4e665a48b5
BLAKE2b-256 9cdab37c03e59011c682a75ea0736f81e5c581a17b1a46b16c0c59cd5d2502df

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page