{
 "kind": "tool",
 "slug": "testcontainers-pypi",
 "path": "tools/testcontainers-pypi/",
 "name": "testcontainers",
 "maker": null,
 "density": "full",
 "crumbs": [
  [
   "Tools",
   "tools/"
  ],
  [
   "Testing",
   "tools/testing/"
  ]
 ],
 "lead": "Real databases in your tests.",
 "chips": [
  {
   "label": "Testing",
   "path": "tools/testing/"
  },
  {
   "label": "PYPI"
  }
 ],
 "primary": {
  "label": "Copy install command",
  "copy": "pip install testcontainers"
 },
 "links": [
  {
   "label": "GitHub",
   "href": "https://github.com/testcontainers/testcontainers-python"
  },
  {
   "label": "Website",
   "href": "https://github.com/testcontainers/testcontainers-python"
  }
 ],
 "track": "New versions, deprecation and license changes on your dashboard",
 "verdicts": [
  {
   "key": "license",
   "label": "License",
   "value": "Apache-2.0",
   "status": "yes",
   "sub": "Use it in paid apps",
   "quote": "Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license",
   "note": "Apache 2.0 allows commercial use free of charge; it is usually only a test tool, not shipped to users.",
   "src": "https://github.com/testcontainers/testcontainers-python/blob/main/LICENSE.txt"
  },
  {
   "key": "maint",
   "label": "Maintained",
   "value": "Maintained",
   "status": "yes",
   "sub": "Last change Oct 9, 2026",
   "note": "Latest GitHub release Jul 24, 2026. ",
   "src": "https://github.com/testcontainers/testcontainers-python"
  },
  {
   "key": "pop",
   "label": "Used by agents' projects",
   "value": "Not in our scan",
   "status": "info",
   "sub": "#121 of 122 in its category",
   "note": "Dependency in 0 public GitHub projects set up for AI coding agents that we scanned (0.0%).",
   "src": null
  },
  {
   "key": "agent",
   "label": "Agent access",
   "value": "Community skills",
   "status": "info",
   "sub": "1 skills by others",
   "note": "Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.",
   "src": null
  }
 ],
 "vfoot": "From the package registry and GitHub, checked daily; card checked Nov 10, 2026.",
 "blocks": [
  {
   "id": "overview",
   "nav": "Overview",
   "h2": "What testcontainers does",
   "parts": [
    {
     "t": "prose",
     "text": "Testcontainers is a free Python library that starts a real database, cache or other service in Docker just for your tests, and removes it afterwards. Your tests then talk to the same kind of Postgres or Redis you run in production instead of a fake. It needs Docker running on the machine."
    },
    {
     "t": "h3",
     "text": "What people build with it"
    },
    {
     "t": "uses",
     "items": [
      {
       "title": "Test against a real Postgres",
       "text": "Your tests for sign-up or checkout run their queries on a fresh Postgres database that disappears when the tests end.",
       "idea": false
      },
      {
       "title": "Give each test its own Redis",
       "text": "Tests that use a cache or a job queue each get a clean Redis on their own port, so they can run side by side.",
       "idea": false
      },
      {
       "title": "Run the same tests in CI",
       "text": "Your automated checks on every push start the same services, as long as the CI machine can reach Docker.",
       "idea": false
      },
      {
       "title": "No leftovers after a crash",
       "text": "If a test run is killed halfway, a small helper container still removes the services it started.",
       "idea": false
      },
      {
       "title": "Try a database upgrade first",
       "text": "Run your tests on the next Postgres version by changing one image name, before you upgrade the real server.",
       "idea": true
      },
      {
       "title": "Check database setup scripts",
       "text": "Run your table-creation and data-change scripts on a throwaway database to see they finish without errors.",
       "idea": true
      }
     ]
    }
   ]
  },
  {
   "id": "popularity",
   "nav": "Popularity",
   "h2": "testcontainers popularity",
   "parts": [
    {
     "t": "stats",
     "items": [
      {
       "n": "47",
       "of": "/ 100",
       "l": "Gid Score, #2291 overall"
      },
      {
       "n": "9.8M",
       "l": "downloads a week, pypi"
      },
      {
       "n": "2,322",
       "l": "GitHub stars"
      }
     ]
    },
    {
     "t": "small",
     "text": "Gid Score measures public popularity and activity, not quality.",
     "link": "How the Gid Score is calculated",
     "path": "tools/top/"
    }
   ]
  },
  {
   "id": "usage",
   "nav": "How it is used",
   "h2": "How testcontainers is used",
   "parts": [
    {
     "t": "list",
     "items": [
      "testcontainers joined the catalog on its public numbers (9,779,247 downloads a week on PyPI and 2,322 GitHub stars), not on our project count: it is a dependency in 6 public GitHub projects of our scan, 0 of them set up for AI coding agents.",
      "Projects that use it most often also use pytest (100.0%), NumPy (83.3%), OpenAI Python Library (83.3%)."
     ]
    },
    {
     "t": "h3",
     "text": "Often used with"
    },
    {
     "t": "rows",
     "rows": [
      {
       "l": "In 100.0% of its projects",
       "v": "pytest",
       "path": "tools/pytest/"
      },
      {
       "l": "In 83.3% of its projects",
       "v": "NumPy",
       "path": "tools/numpy/"
      },
      {
       "l": "In 83.3% of its projects",
       "v": "OpenAI Python Library",
       "path": "tools/openai-pypi/"
      },
      {
       "l": "In 83.3% of its projects",
       "v": "Pydantic",
       "path": "tools/pydantic/"
      },
      {
       "l": "In 83.3% of its projects",
       "v": "python-dotenv",
       "path": "tools/python-dotenv/"
      },
      {
       "l": "In 83.3% of its projects",
       "v": "Requests",
       "path": "tools/requests-py/"
      },
      {
       "l": "In 83.3% of its projects",
       "v": "Rich",
       "path": "tools/rich/"
      },
      {
       "l": "In 66.7% of its projects",
       "v": "FastAPI",
       "path": "tools/fastapi/"
      }
     ]
    }
   ]
  },
  {
   "id": "more",
   "nav": null,
   "spy_as": "usage",
   "h2": "More about testcontainers",
   "parts": [
    {
     "t": "more",
     "items": [
      {
       "title": "Agent Skills for it",
       "path": "skills/",
       "items": [
        "testcontainers-integration-tests: Write integration tests using TestContainers for .NET with xUnit. Covers infrastructure testing with real databases, message queues, and cac"
       ]
      },
      {
       "title": "More in Testing",
       "path": "tools/testing/",
       "items": [
        {
         "text": "Vitest",
         "path": "tools/vitest/"
        },
        {
         "text": "Playwright (JavaScript)",
         "path": "tools/playwright-test/"
        },
        {
         "text": "Testing Library",
         "path": "tools/testing-library/"
        },
        {
         "text": "jsdom",
         "path": "tools/jsdom/"
        },
        {
         "text": "Jest",
         "path": "tools/jest/"
        },
        {
         "text": "pytest",
         "path": "tools/pytest/"
        },
        {
         "text": "Happy DOM",
         "path": "tools/happy-dom/"
        },
        {
         "text": "axe-core Playwright",
         "path": "tools/axe-core-playwright/"
        }
       ]
      }
     ]
    }
   ]
  },
  {
   "id": "alternatives",
   "nav": "Alternatives",
   "h2": "Alternatives",
   "parts": [
    {
     "t": "alts",
     "items": [
      {
       "name": "testcontainers",
       "me": true,
       "facts": [
        "Apache-2.0",
        "Gid 47",
        "9.8M/wk"
       ]
      },
      {
       "name": "fakeredis",
       "why": "Pick fakeredis when Docker is not available and an in-memory fake of Redis is good enough for your Python tests.",
       "path": "tools/fakeredis/",
       "facts": []
      },
      {
       "name": "Moto",
       "why": "Pick Moto when you only need to mock AWS services in Python tests, without containers.",
       "path": "tools/moto/",
       "facts": []
      },
      {
       "name": "Docker Python",
       "why": "Pick the Docker Python library when you want to drive the Docker Engine yourself rather than use ready test helpers.",
       "path": "tools/docker/",
       "facts": []
      }
     ],
     "more": "Compare testcontainers with another tool",
     "more_path": "tools/compare/"
    }
   ]
  },
  {
   "id": "start",
   "nav": "Get started",
   "h2": "Get started",
   "parts": [
    {
     "t": "prompt",
     "text": "Use testcontainers for Python (pin testcontainers==4.15.0, Python 3.10+) with imports from testcontainers.community.<module>, start containers in with blocks or pytest fixtures, install the database driver separately, and use wait strategies instead of wait_for_logs."
    },
    {
     "t": "steps",
     "items": [
      {
       "text": "Make sure Docker (or another Docker-compatible runtime) is installed and running.",
       "code": null,
       "src": "https://github.com/testcontainers/testcontainers-python/blob/main/docs/system_requirements/docker.md"
      },
      {
       "text": "Install the library with the module you need and your own database driver.",
       "code": "pip install testcontainers[postgres] sqlalchemy psycopg2",
       "src": "https://github.com/testcontainers/testcontainers-python/blob/main/docs/modules/postgres.md"
      },
      {
       "text": "Start the service in a with block inside your test and run the tests with pytest.",
       "code": "pytest test_redis.py",
       "src": "https://github.com/testcontainers/testcontainers-python/blob/main/docs/quickstart.md"
      }
     ]
    },
    {
     "t": "h3",
     "text": "Mistakes to avoid"
    },
    {
     "t": "mistakes",
     "items": [
      {
       "dont": "from testcontainers.postgres import PostgresContainer (as in the README and older guides)",
       "fix": "from testcontainers.community.postgres import PostgresContainer",
       "why": "In 4.15.0 the old paths still work but warn; our run printed \"testcontainers.postgres is deprecated, use testcontainers.community.postgres instead\"."
      },
      {
       "dont": "wait_for_logs(container, \"ready to accept connections\")",
       "fix": "container.waiting_for(LogMessageWaitStrategy(\"ready to accept connections\")) with LogMessageWaitStrategy from testcontainers.core.wait_strategies",
       "why": "String and callable predicates for wait_for_logs are deprecated in 4.15.0 and modules moved to wait strategies."
      },
      {
       "dont": "pip install testcontainers[postgres] and expecting SQLAlchemy or psycopg to come with it",
       "fix": "pip install testcontainers[postgres] sqlalchemy psycopg2 (or the driver your code uses)",
       "why": "The extra no longer pulls in database drivers."
      },
      {
       "dont": "Running the tests inside a CI job container with no Docker access",
       "fix": "Use an image with the Docker client and mount /var/run/docker.sock or set DOCKER_HOST",
       "why": "Without a reachable Docker daemon the first container start fails; our check raised DockerException."
      },
      {
       "dont": "testcontainers>=4 in requirements",
       "fix": "testcontainers==4.15.0, upgraded on purpose",
       "why": "Community modules can break in minor releases."
      }
     ]
    }
   ]
  },
  {
   "id": "faq",
   "nav": "Questions",
   "h2": "Questions",
   "parts": [
    {
     "t": "faq",
     "items": [
      {
       "q": "Does it work without Docker?",
       "a": "No. It needs a Docker-compatible runtime; our check without Docker failed at once with a DockerException.",
       "evidence": {
        "url": "https://testcontainers.com/getting-started/",
        "quote": "to run Testcontainers-based tests, you need a Docker-API compatible container runtime"
       }
      },
      {
       "q": "Can I use Podman instead of Docker?",
       "a": "Yes, by setting DOCKER_HOST to the Podman socket; other runtimes are not tested as actively as Docker.",
       "evidence": {
        "url": "https://github.com/testcontainers/testcontainers-python/blob/main/docs/system_requirements/docker.md",
        "quote": "In order to run Testcontainers against Podman, the env var below should be set."
       }
      },
      {
       "q": "Who removes the containers if my tests crash?",
       "a": "A helper container called Ryuk starts with the first container and cleans up when the Python process ends or dies.",
       "evidence": {
        "url": "https://github.com/testcontainers/testcontainers-python/blob/main/docs/features/garbage_collector.md",
        "quote": "This container is automatically started when you create your first test container and is responsible for cleaning up resources when:"
       }
      },
      {
       "q": "Can I start my own image, not just ready modules?",
       "a": "Yes. The core module runs containers from any image.",
       "evidence": {
        "url": "https://testcontainers-python.readthedocs.io/en/latest/",
        "quote": "Crafting containers that are based on custom images is supported by the core module."
       }
      }
     ]
    }
   ]
  }
 ],
 "glance": [
  [
   "Package",
   "pypi testcontainers"
  ],
  [
   "Category",
   "Testing"
  ],
  [
   "License",
   "Apache-2.0"
  ],
  [
   "Gid Score",
   "47.3"
  ],
  [
   "Rank in category",
   "#121 of 122"
  ],
  [
   "GitHub",
   "testcontainers/testcontainers-python"
  ],
  [
   "Last change",
   "Oct 9, 2026"
  ]
 ],
 "good": [
  "It does nothing unless Docker, or a program compatible with it, runs on the machine that runs the tests.",
  "Database drivers are not included; install the one your code uses, for example psycopg or SQLAlchemy.",
  "Modules for single services may change in minor versions, so pin the exact version."
 ],
 "checked_line": "Read by AgentGid from 16 official pages, card checked Nov 10, 2026; numbers update daily.",
 "logo": "https://agentgid.com/media/avatars/testcontainers.png"
}