{"id":20712911,"url":"https://github.com/thesis/sockfilter","last_synced_at":"2026-02-27T17:42:37.211Z","repository":{"id":18440373,"uuid":"21629236","full_name":"thesis/sockfilter","owner":"thesis","description":"Block socket creation by host/port in Python.","archived":false,"fork":false,"pushed_at":"2019-10-03T01:18:48.000Z","size":15,"stargazers_count":3,"open_issues_count":3,"forks_count":1,"subscribers_count":6,"default_branch":"master","last_synced_at":"2025-05-05T00:53:25.617Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/thesis.png","metadata":{"files":{"readme":"README.rst","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":"2014-07-08T20:56:39.000Z","updated_at":"2020-03-29T22:00:31.000Z","dependencies_parsed_at":"2022-09-10T23:34:49.957Z","dependency_job_id":null,"html_url":"https://github.com/thesis/sockfilter","commit_stats":null,"previous_names":["cardforcoin/sockfilter"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thesis%2Fsockfilter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thesis%2Fsockfilter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thesis%2Fsockfilter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thesis%2Fsockfilter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thesis","download_url":"https://codeload.github.com/thesis/sockfilter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253486095,"owners_count":21916127,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":[],"created_at":"2024-11-17T02:22:29.844Z","updated_at":"2026-02-27T17:42:32.175Z","avatar_url":"https://github.com/thesis.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":".. figure:: https://circleci.com/gh/cardforcoin/sockfilter.png?circle-token=66b5b9e9a839f873d98889f5ca1655c7f31080a3\n   :alt: Build status\n\n\nsockfilter\n==========\n\nBlock socket creation based on hostname/port to suppress unwanted\nnetwork activity.\n\n.. pypi - Everything below this line goes into the description for PyPI.\n\n\nUsage\n-----\n\nThe intended use is for making sure your unit tests don't make network\nconnections. Activate ``sockfilter`` with a predicate like:\n\n.. code:: python\n\n    # only allow http connections to localhost\n    def socket_address_allowed(address):\n        return (address.host in ['localhost', '127.0.0.1'] and\n                address.port == 80)\n\n    sockfilter.enable(socket_address_allowed)\n\nAny subsequent attempts to open a connection at an address not satisfying\nthe predicate will raise ``sockfilter.SockFilterError``.\n\n\n``with_sockfiltering`` decorator\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code:: python\n\n    from sockfilter import with_sockfiltering\n\n    @with_sockfiltering(socket_address_allowed)\n    def test_foo():\n        foo()\n\n\n``sockfiltering`` context manager\n~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code:: python\n\n    from sockfilter import sockfiltering\n\n    def test_foo():\n        with sockfiltering(socket_address_allowed):\n            foo()\n\n\n``enable`` and ``disable``\n~~~~~~~~~~~~~~~~~~~~~~~~~~\n\n.. code:: python\n\n    import sockfilter\n    from unittest import TestCase\n\n    class FooTest(TestCase):\n\n        def setUp(self):\n            sockfilter.enable(socket_address_allowed)\n\n        def tearDown(self):\n            sockfilter.disable()\n\n        def test_foo(self):\n            foo()\n\n\nUnder the hood\n--------------\n\nSockfilter works by monkey-patching Python's ``socket`` library,\ninspired by HTTPretty_.\n\n.. _HTTPretty: https://github.com/gabrielfalcao/HTTPretty\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthesis%2Fsockfilter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthesis%2Fsockfilter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthesis%2Fsockfilter/lists"}