{"id":18300477,"url":"https://github.com/comet-ml/oscontainer","last_synced_at":"2026-02-11T04:02:05.476Z","repository":{"id":44533312,"uuid":"456568690","full_name":"comet-ml/oscontainer","owner":"comet-ml","description":"The small Python library to read resources available for Linux OS container.","archived":false,"fork":false,"pushed_at":"2022-02-10T10:30:24.000Z","size":69,"stargazers_count":2,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-21T18:47:15.051Z","etag":null,"topics":["containers","docker-container","kubernetes","linux","linux-containers"],"latest_commit_sha":null,"homepage":"","language":"Python","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/comet-ml.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}},"created_at":"2022-02-07T15:41:53.000Z","updated_at":"2023-01-14T14:44:31.000Z","dependencies_parsed_at":"2022-09-04T00:31:15.069Z","dependency_job_id":null,"html_url":"https://github.com/comet-ml/oscontainer","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/comet-ml/oscontainer","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comet-ml%2Foscontainer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comet-ml%2Foscontainer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comet-ml%2Foscontainer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comet-ml%2Foscontainer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/comet-ml","download_url":"https://codeload.github.com/comet-ml/oscontainer/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/comet-ml%2Foscontainer/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29326819,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T03:52:29.695Z","status":"ssl_error","status_checked_at":"2026-02-11T03:52:23.094Z","response_time":97,"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":["containers","docker-container","kubernetes","linux","linux-containers"],"created_at":"2024-11-05T15:12:34.857Z","updated_at":"2026-02-11T04:02:05.459Z","avatar_url":"https://github.com/comet-ml.png","language":"Python","readme":"[![Python package](https://github.com/yaricom/oscontainer/actions/workflows/python-package.yml/badge.svg)](https://github.com/yaricom/oscontainer/actions/workflows/python-package.yml)\n[![pypi](https://img.shields.io/pypi/v/oscontainer.svg)](https://pypi.org/project/oscontainer/)\n![versions](https://img.shields.io/pypi/pyversions/oscontainer.svg)\n[![license](https://img.shields.io/github/license/yaricom/oscontainer.svg)](https://github.com/yaricom/oscontainer/blob/master/LICENSE)\n\n# Overview\n\nThe simple library to gather CPU and memory resource limits from within OS Container bases on Linux.\n\n## Install\n\n```bash\npip install oscontainer\n```\n\n## Usage in code\n\nThe library can be used to acquire current limits exposed to the container or process as following:\n\n```python\nfrom oscontainer import OSContainer\n\n# Get the container instance\ncontainer = OSContainer()\n\n# Check if current process runs inside container\nif container.is_containerized():\n    # Get active processors\n    cpus_count = container.active_processor_count()\n    \n    # Get the limit of available memory for this process.\n    mem_limit = container.memory_limit_in_bytes()\nelse:\n    print(\"No Container support detected\")\n```\n\nFor extra metrics available see [OSContainer](./oscontainer/os_container.py).\n\n## Run in Docker from source code\n\nTo run library in the test container you need to build the docker image and run it as container.\n\nCheckout the repository.\n\n```bash\ngit clone git@github.com:yaricom/oscontainer.git\n```\n\nBuild local image with `oscontainer` name.\n\n```bash\ncd oscontainer\n\ndocker build -f Dockerfile -t oscontainer . \n```\n\nRun the image we built within container with specific CPU limits set. \nFor details about setting container resources limits with Docker, see: [Runtime options with Memory, CPUs, and GPUs](https://docs.docker.com/config/containers/resource_constraints).\n\nThe following command will start container and open interactive shell:\n\n```bash\ndocker run -it --cpus=\".5\" oscontainer /bin/bash\n```\n\nNow, execute `main.py` script within shell to see resource constraints that was detected:\n\n```bash\npython main.py \n```\n\nThis will produce the output like following:\n\n```text\nOSContainer:\n==========================\n   active processors: 1\n      container type: cgroup2\n--------------------------\n \u003e MEMORY:\n--------------------------\nmemory limit (bytes): -1\nmemory usage (bytes): 8413184\n--------------------------\n \u003e CPU:\n--------------------------\n               quota: 50000\n              period: 100000\n              shares: -1\n         cpuset cpus: 0-2\n==========================\nSystem information:\n==========================\nmultiprocessing.cpu_count: 3\n     process cpu affinity: {0, 1, 2}\n==========================\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomet-ml%2Foscontainer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcomet-ml%2Foscontainer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcomet-ml%2Foscontainer/lists"}