How to Create a Dictionary in Python
A dictionary stores values under names, called keys: a book's title under "title", its year under "year". You write one in Python with curly braces and key: value pairs, and add more pairs at any time.
uv, the Fast Python Package and Project Manager, Its Commands and pyproject.toml
View All TagsA dictionary stores values under names, called keys: a book's title under "title", its year under "year". You write one in Python with curly braces and key: value pairs, and add more pairs at any time.
"Fifteen minutes from now", "a week after signup", "how long did it take": all of these are a datetime plus or minus a length of time. Python's timedelta is that length of time, and adding one to a datetime moves it forward.
Times stored or sent between systems are safest in UTC, the time zone that never changes for daylight saving. In Python, datetime.now(tz=timezone.utc) gives you the current time in UTC, labelled as UTC, so nothing downstream has to guess which zone it's in.
A docstring is the short description that sits at the top of a function and says what it does. Unlike a comment, Python keeps it with the function, so help(), editors and documentation tools can show it to anyone who uses your code.
A type hint writes down what kind of value a function expects and returns: a float here, an int there. Editors use the hints to warn you early, and readers see at a glance what to pass, but Python itself doesn't check them when the code runs.
A function gives a name to a piece of work so you can run it whenever you need it, with different values each time. In Python you write one with def, list the values it needs in brackets and send the answer back with return.
Python ships with hundreds of modules, such as math, datetime and os, and you can install thousands more. A program uses one by importing it: import math brings in the whole module, and from math import pi brings in just one name from it.
Before mlflow models serve can start a model, it builds an environment with the model's Python version and packages. mlflow models prepare-env does that step on its own, ahead of time, so serve finds the environment ready. This guide prepares one and serves the model after it, with real output and times from MLflow 3.18.0 on a Mac.
I ran mlflow models serve the way MLflow's local deployment guide shows it, and it stopped before the server started, with mlflow.exceptions.MlflowException: Could not find the pyenv binary. Without --env-manager, the command builds the model's environment with virtualenv, which needs pyenv to install the model's Python version, and pyenv isn't installed on my Mac. --env-manager uv fixed it.
I upgraded a project's packages and then scored some sessions with a model I had logged before the upgrade. MLflow printed WARNING mlflow.utils.requirements_utils: Detected one or more mismatches between the model's dependencies and the current Python environment, with five packages one release apart. MLflow had pinned the project's whole lockfile into the model when it logged it; running the model in its own environment, built from those pins, fixed it.