liveBook · Manning

Unique identifier

As explained in The Well-Grounded Python Developer: How the pros use Python and Flask

A unique identifier is a value intended to distinguish one entity or record from all others within a specified context.

When several records describe one order, their position in a file is not enough to keep them connected. A unique identifier gives each record a value that distinguishes it within a defined scope. For a CSV file, that scope can be just its own rows; an incrementing integer in a new column is enough to identify each one. section 10.2

Once records have identifiers, their values can do different jobs:

  • Connect data: put a customer’s identifier in each related order. Put both an order identifier and a product identifier in an item record to connect orders with products. section 10.2
  • Recognize a returning client: a server-generated session identifier lets the server relate successive requests to a user. Flask signs its session cookie so the browser can view it but cannot modify it without the secret key. section 8.1.1
  • Find a user at login: an email address can serve as a unique, memorable lookup value, while a separate UUID-derived value can serve as the user record’s primary key. section 8.2.1

From an order to a user account

Suppose customer row 12 places two orders. Each order stores 12 to identify its customer; each item stores the identifiers of its order and product. In a user model, the same principle appears as a string primary key generated by `uuid4().hex`, alongside an email field marked unique. The identifier’s form changes, but its job remains to distinguish the right record in its context. section 10.2 section 8.2.1

Uniqueness does not make a value a useful human-readable name. A UUID may be practical for distinguishing records, yet a UUID-based Python variable name conveys little about what the variable means. Use identifiers to establish identity; use descriptive names when people need to understand the code. section 2.1

How The Well-Grounded Python Developer: How the pros use Python and Flask covers it

How deep it goes
Works through per-file row IDs and cross-file links, then illustrates a UUID-backed user primary key without explaining UUID generation.
Examples
Illustrates incrementing CSV row IDs, order-item links, email-based login lookup, and a UUID-backed user model.
What it assumes
Builds on CSV rows and web requests while explaining why row identifiers and session cookies are needed.
What you can do after
Apply it via incrementing CSV identifiers or a Python UUID-backed user model to distinguish records and connect related data.
How it connects
Connects unique identifiers to one-to-many relationships, many-to-many relationships, session cookies, and authentication.

Also explained in

Compare how 9 books explain unique identifier →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of The Well-Grounded Python Developer: How the pros use Python and Flask. The section links point to the parts of the book it draws on.