{"id":22901485,"url":"https://github.com/whisperpine/python-container-demo","last_synced_at":"2026-04-15T13:34:06.409Z","repository":{"id":266559276,"uuid":"898194209","full_name":"whisperpine/python-container-demo","owner":"whisperpine","description":"A demo project to show how to build container images for a python project with best practices.","archived":false,"fork":false,"pushed_at":"2026-04-02T09:52:08.000Z","size":94,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-03T00:34:24.619Z","etag":null,"topics":["container","direnv","docker","docker-compose","nix-flake","python","uv"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/whisperpine.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-12-04T00:39:26.000Z","updated_at":"2026-04-02T09:52:12.000Z","dependencies_parsed_at":"2025-07-11T15:08:22.854Z","dependency_job_id":"c32def5e-6327-4a23-9353-7184ec3b77e2","html_url":"https://github.com/whisperpine/python-container-demo","commit_stats":null,"previous_names":["whisperpine/python-container-demo"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/whisperpine/python-container-demo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whisperpine%2Fpython-container-demo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whisperpine%2Fpython-container-demo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whisperpine%2Fpython-container-demo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whisperpine%2Fpython-container-demo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/whisperpine","download_url":"https://codeload.github.com/whisperpine/python-container-demo/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/whisperpine%2Fpython-container-demo/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31842976,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T13:28:40.153Z","status":"ssl_error","status_checked_at":"2026-04-15T13:28:29.396Z","response_time":63,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["container","direnv","docker","docker-compose","nix-flake","python","uv"],"created_at":"2024-12-14T01:33:34.990Z","updated_at":"2026-04-15T13:34:06.402Z","avatar_url":"https://github.com/whisperpine.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python Container Demo\n\nA demo project to show how to build container images for a python project with\nbest practices.\n\n## Reference\n\n- [astral-sh/uv-docker-example](https://github.com/astral-sh/uv-docker-example).\n- [Using uv in Docker - uv docs](https://docs.astral.sh/uv/guides/integration/docker/).\n\n## Tech Stack Selection\n\n- The dev environment is managed by [nix flakes](https://nixos.wiki/wiki/Flakes).\n- The python package and project manager is [uv](https://github.com/astral-sh/uv).\n\n## Prerequisites\n\n- Linux or macOS with [nixpkgs](https://github.com/NixOS/nixpkgs) installed,\n  and with `flakes` and `nix-command` features enabled.\n- A tool that can build container images.\n  In this demo, [docker](https://www.docker.com/) is preferred.\n\n## Nix Dev Environment\n\n[nix-direnv](https://github.com/nix-community/nix-direnv) is highly recommended\nto improve the quality of life working with nix managed dev environment. Besides\nother benefits (e.g. caching), nix-direnv automatically runs `nix develop` every\ntime you `cd` to the project. All you need to do is to initialize each project\nonce with `direnv allow` command.\n\n```sh\n# `dirnev allow` needs to be run only once.\n# After that, when you `cd` in, nix dev env will be automatically loaded.\ncd THIS_REPO \u0026\u0026 dirnev allow\n# Check if the dev environment loads as expected.\npython --version \u0026\u0026 which python\n```\n\nWithout the help of [nix-direnv](https://github.com/nix-community/nix-direnv),\nthe `nix develop` needs to be run manually every time:\n\n```sh\n# `nix develop` needs to be run every time you `cd` in.\ncd THIS_REPO \u0026\u0026 nix develop\n# Check if the dev environment loads as expected.\npython --version \u0026\u0026 which python\n```\n\n## Python Packages\n\n[uv](https://github.com/astral-sh/uv)\nis an extremely fast Python package and project manager.\nIt's a drop-in replacement of `pip`, `pyenv`, `virtualenv` and more.\nIn this repo, `uv` is used both in the building stage and dev stage:\n\n- During the building stage, `uv`'s official container image is used to\n  install all the dependencies.\n- During the dev stage, `uv` command will be available when\n  [nix dev environment](#nix-dev-environment) is loaded.\n\n```sh\n# install dependencies specified in uv.lock\nuv sync               \n# add or remove dependencies\nuv add PACKAGE_NAME\nuv remove PACKAGE_NAME\n```\n\n## Python Version\n\nAlthough `uv` can handle python versions properly in virtual environment,\nthe package management mechanism of nix conflicts with `uv`'s.\nHence, use `flake.nix` to manage python version.\n\n```nix\n# modify \"python313\" to change python version.\npackages = with pkgs; [ python313 ];\n```\n\n(Optional) If the required python version changes, modify [pyproject.toml](./pyproject.toml):\n\n```toml\n[project]\nrequires-python = \"\u003e=3.13\" # reconfigure this field\n```\n\nTo make `uv` notice the altered python version and use it in .venv,\nrun the following command:\n\n```sh\nuv venv --clear\n```\n\nDon't forget to change both of the base image tags in [Dockerfile](./Dockerfile)\naccordingly.\n\n## Build Container Image\n\nSuppose `docker` is used to build container image.\n\n```sh\n# build image and print the result\nsh ./scripts/build.sh\n```\n\n## Docker Compose\n\nDespite that `docker compose` is often used to deploy containerized app,\nit can also be quite useful to facilitate local development.\nAnd [compose.yaml](./compose.yaml) herein is a simple showcase.\n\n```sh\n# Build and start the containerized app, and watch if there is a change.\n# If any changes detected in local file system, auto rebuild and restart.\ndocker compose watch\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhisperpine%2Fpython-container-demo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwhisperpine%2Fpython-container-demo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwhisperpine%2Fpython-container-demo/lists"}