summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--pkgs/development/python-modules/Cython/default.nix8
-rw-r--r--pkgs/development/python-modules/HTSeq/default.nix4
-rw-r--r--pkgs/development/python-modules/Theano/default.nix8
-rw-r--r--pkgs/development/python-modules/aenum/default.nix8
-rw-r--r--pkgs/development/python-modules/aiodns/default.nix6
-rw-r--r--pkgs/development/python-modules/aioredis/default.nix2
-rw-r--r--pkgs/development/python-modules/altair/default.nix2
-rw-r--r--pkgs/development/python-modules/aniso8601/default.nix2
-rw-r--r--pkgs/development/python-modules/apipkg/default.nix6
-rw-r--r--pkgs/development/python-modules/avro/default.nix2
-rw-r--r--pkgs/development/python-modules/bcrypt/default.nix10
-rw-r--r--pkgs/development/python-modules/beancount/default.nix8
-rw-r--r--pkgs/development/python-modules/beanstalkc/default.nix8
-rw-r--r--pkgs/development/python-modules/bedup/default.nix2
-rw-r--r--pkgs/development/python-modules/behave/default.nix2
-rw-r--r--pkgs/development/python-modules/binwalk/default.nix2
-rw-r--r--pkgs/development/python-modules/bootstrapped-pip/default.nix6
-rw-r--r--pkgs/development/python-modules/buildout-nix/default.nix8
-rw-r--r--pkgs/development/python-modules/cadquery/default.nix2
-rw-r--r--pkgs/development/python-modules/capstone/default.nix2
-rw-r--r--pkgs/development/python-modules/cddb/default.nix2
-rw-r--r--pkgs/development/python-modules/cdecimal/default.nix4
-rw-r--r--pkgs/development/python-modules/cffi/default.nix6
-rw-r--r--pkgs/development/python-modules/cheetah3/default.nix8
-rw-r--r--pkgs/development/python-modules/cherrypy/17.nix2
-rw-r--r--pkgs/development/python-modules/cherrypy/default.nix2
-rw-r--r--pkgs/development/python-modules/cld2-cffi/default.nix2
-rw-r--r--pkgs/development/python-modules/cmd2/default.nix6
-rw-r--r--pkgs/development/python-modules/codecov/default.nix6
-rw-r--r--pkgs/development/python-modules/colorlover/default.nix10
-rw-r--r--pkgs/development/python-modules/construct/default.nix2
-rw-r--r--pkgs/development/python-modules/cot/default.nix2
-rw-r--r--pkgs/development/python-modules/cryptography/3.3.nix8
-rw-r--r--pkgs/development/python-modules/cryptography/default.nix8
-rw-r--r--pkgs/development/python-modules/csscompressor/default.nix7
-rw-r--r--pkgs/development/python-modules/curtsies/default.nix2
-rw-r--r--pkgs/development/python-modules/dbf/default.nix2
-rw-r--r--pkgs/development/python-modules/demjson/default.nix2
-rw-r--r--pkgs/development/python-modules/django-polymorphic/default.nix6
-rw-r--r--pkgs/development/python-modules/django-raster/default.nix2
-rw-r--r--pkgs/development/python-modules/django/2.nix2
-rw-r--r--pkgs/development/python-modules/django/3.nix2
-rw-r--r--pkgs/development/python-modules/dufte/default.nix2
-rw-r--r--pkgs/development/python-modules/easydict/default.nix6
-rw-r--r--pkgs/development/python-modules/elasticsearch-dsl/default.nix2
-rw-r--r--pkgs/development/python-modules/enzyme/default.nix6
-rw-r--r--pkgs/development/python-modules/etebase/default.nix2
-rw-r--r--pkgs/development/python-modules/fasteners/default.nix2
-rw-r--r--pkgs/development/python-modules/fire/default.nix2
-rw-r--r--pkgs/development/python-modules/flake8/default.nix8
-rw-r--r--pkgs/development/python-modules/flask-migrate/default.nix10
-rw-r--r--pkgs/development/python-modules/flask-testing/default.nix2
-rw-r--r--pkgs/development/python-modules/flatbuffers/default.nix4
-rw-r--r--pkgs/development/python-modules/funcsigs/default.nix2
-rw-r--r--pkgs/development/python-modules/gevent/default.nix2
-rw-r--r--pkgs/development/python-modules/glymur/default.nix2
-rw-r--r--pkgs/development/python-modules/goocalendar/default.nix4
-rw-r--r--pkgs/development/python-modules/grpcio/default.nix6
-rw-r--r--pkgs/development/python-modules/gst-python/default.nix9
-rw-r--r--pkgs/development/python-modules/gumath/default.nix5
-rw-r--r--pkgs/development/python-modules/gyp/default.nix2
-rw-r--r--pkgs/development/python-modules/h5py/default.nix21
-rw-r--r--pkgs/development/python-modules/hg-evolve/default.nix4
-rw-r--r--pkgs/development/python-modules/hg-git/default.nix4
-rw-r--r--pkgs/development/python-modules/hidapi/default.nix8
-rw-r--r--pkgs/development/python-modules/hoomd-blue/default.nix4
-rw-r--r--pkgs/development/python-modules/htmlmin/default.nix7
-rw-r--r--pkgs/development/python-modules/httpretty/0.nix6
-rw-r--r--pkgs/development/python-modules/httpretty/default.nix6
-rw-r--r--pkgs/development/python-modules/hupper/default.nix4
-rw-r--r--pkgs/development/python-modules/imageio/default.nix2
-rw-r--r--pkgs/development/python-modules/influxgraph/default.nix2
-rw-r--r--pkgs/development/python-modules/ipython/5.nix2
-rw-r--r--pkgs/development/python-modules/johnnycanencrypt/default.nix7
-rw-r--r--pkgs/development/python-modules/json-schema-for-humans/default.nix4
-rw-r--r--pkgs/development/python-modules/jsonpointer/default.nix4
-rw-r--r--pkgs/development/python-modules/keyring/2.nix2
-rw-r--r--pkgs/development/python-modules/keyrings-alt/default.nix2
-rw-r--r--pkgs/development/python-modules/kiwisolver/1_1.nix2
-rw-r--r--pkgs/development/python-modules/kiwisolver/default.nix2
-rw-r--r--pkgs/development/python-modules/koji/default.nix8
-rw-r--r--pkgs/development/python-modules/latexcodec/default.nix6
-rw-r--r--pkgs/development/python-modules/ledgerwallet/default.nix2
-rw-r--r--pkgs/development/python-modules/libevdev/default.nix4
-rw-r--r--pkgs/development/python-modules/libgpuarray/default.nix2
-rw-r--r--pkgs/development/python-modules/lightgbm/default.nix4
-rw-r--r--pkgs/development/python-modules/linode-api/default.nix4
-rw-r--r--pkgs/development/python-modules/livestreamer/default.nix2
-rw-r--r--pkgs/development/python-modules/llfuse/default.nix14
-rw-r--r--pkgs/development/python-modules/llvmlite/default.nix13
-rw-r--r--pkgs/development/python-modules/loguru/default.nix4
-rw-r--r--pkgs/development/python-modules/maestral/default.nix8
-rw-r--r--pkgs/development/python-modules/magic-wormhole/default.nix2
-rw-r--r--pkgs/development/python-modules/mailman-rss/default.nix2
-rw-r--r--pkgs/development/python-modules/markdownsuperscript/default.nix6
-rw-r--r--pkgs/development/python-modules/matplotlib/2.nix19
-rw-r--r--pkgs/development/python-modules/matplotlib/default.nix15
-rw-r--r--pkgs/development/python-modules/mezzanine/default.nix4
-rw-r--r--pkgs/development/python-modules/mockito/default.nix2
-rw-r--r--pkgs/development/python-modules/modestmaps/default.nix2
-rw-r--r--pkgs/development/python-modules/monotonic/default.nix4
-rw-r--r--pkgs/development/python-modules/moviepy/default.nix2
-rw-r--r--pkgs/development/python-modules/mpi4py/default.nix9
-rw-r--r--pkgs/development/python-modules/mxnet/default.nix4
-rw-r--r--pkgs/development/python-modules/ndtypes/default.nix5
-rw-r--r--pkgs/development/python-modules/netaddr/default.nix2
-rw-r--r--pkgs/development/python-modules/nipy/default.nix2
-rw-r--r--pkgs/development/python-modules/notify/default.nix2
-rw-r--r--pkgs/development/python-modules/nuitka/default.nix2
-rw-r--r--pkgs/development/python-modules/numba/default.nix13
-rw-r--r--pkgs/development/python-modules/omegaconf/default.nix2
-rw-r--r--pkgs/development/python-modules/orderedmultidict/default.nix2
-rw-r--r--pkgs/development/python-modules/oset/default.nix6
-rw-r--r--pkgs/development/python-modules/pamela/default.nix4
-rw-r--r--pkgs/development/python-modules/pandas/2.nix27
-rw-r--r--pkgs/development/python-modules/pandas/default.nix18
-rw-r--r--pkgs/development/python-modules/parse-type/default.nix2
-rw-r--r--pkgs/development/python-modules/pbr/default.nix6
-rw-r--r--pkgs/development/python-modules/pecan/default.nix2
-rw-r--r--pkgs/development/python-modules/peewee/default.nix6
-rw-r--r--pkgs/development/python-modules/pgsanity/default.nix4
-rw-r--r--pkgs/development/python-modules/phonenumbers/default.nix8
-rw-r--r--pkgs/development/python-modules/pickleshare/default.nix2
-rw-r--r--pkgs/development/python-modules/pillow/6.nix6
-rw-r--r--pkgs/development/python-modules/pillow/default.nix6
-rw-r--r--pkgs/development/python-modules/pip-tools/default.nix4
-rw-r--r--pkgs/development/python-modules/plyvel/default.nix2
-rw-r--r--pkgs/development/python-modules/protobuf/default.nix23
-rw-r--r--pkgs/development/python-modules/pulp/default.nix2
-rw-r--r--pkgs/development/python-modules/pwntools/default.nix2
-rw-r--r--pkgs/development/python-modules/py3exiv2/default.nix12
-rw-r--r--pkgs/development/python-modules/pyannotate/default.nix2
-rw-r--r--pkgs/development/python-modules/pyatspi/default.nix4
-rw-r--r--pkgs/development/python-modules/pybtex-docutils/default.nix6
-rw-r--r--pkgs/development/python-modules/pybtex/default.nix6
-rw-r--r--pkgs/development/python-modules/pycassa/default.nix6
-rw-r--r--pkgs/development/python-modules/pycdio/default.nix2
-rw-r--r--pkgs/development/python-modules/pycryptodome/default.nix6
-rw-r--r--pkgs/development/python-modules/pycuda/default.nix4
-rw-r--r--pkgs/development/python-modules/pydub/default.nix2
-rw-r--r--pkgs/development/python-modules/pyee/default.nix2
-rw-r--r--pkgs/development/python-modules/pyexiv2/default.nix6
-rw-r--r--pkgs/development/python-modules/pyface/default.nix4
-rw-r--r--pkgs/development/python-modules/pyfakefs/default.nix2
-rw-r--r--pkgs/development/python-modules/pyfribidi/default.nix7
-rw-r--r--pkgs/development/python-modules/pygal/default.nix2
-rw-r--r--pkgs/development/python-modules/pygobject/3.36.nix4
-rw-r--r--pkgs/development/python-modules/pygobject/3.nix4
-rw-r--r--pkgs/development/python-modules/pygobject/default.nix10
-rw-r--r--pkgs/development/python-modules/pygtk/default.nix8
-rw-r--r--pkgs/development/python-modules/pync/default.nix2
-rw-r--r--pkgs/development/python-modules/pynput/default.nix2
-rw-r--r--pkgs/development/python-modules/pyobjc/default.nix8
-rw-r--r--pkgs/development/python-modules/pyopenssl/default.nix17
-rw-r--r--pkgs/development/python-modules/pyparted/default.nix2
-rw-r--r--pkgs/development/python-modules/pypass/default.nix16
-rw-r--r--pkgs/development/python-modules/pyqt/4.x.nix14
-rw-r--r--pkgs/development/python-modules/pyscard/default.nix17
-rw-r--r--pkgs/development/python-modules/pyscss/default.nix4
-rw-r--r--pkgs/development/python-modules/pyside/apiextractor.nix8
-rw-r--r--pkgs/development/python-modules/pyside/generatorrunner.nix8
-rw-r--r--pkgs/development/python-modules/pyspotify/default.nix2
-rw-r--r--pkgs/development/python-modules/pysqlite/default.nix2
-rw-r--r--pkgs/development/python-modules/pytest-asyncio/default.nix2
-rw-r--r--pkgs/development/python-modules/pytest/4.nix4
-rw-r--r--pkgs/development/python-modules/pytest/5.nix2
-rw-r--r--pkgs/development/python-modules/pytest/default.nix2
-rw-r--r--pkgs/development/python-modules/python-engineio/default.nix2
-rw-r--r--pkgs/development/python-modules/python-jsonrpc-server/default.nix2
-rw-r--r--pkgs/development/python-modules/python-language-server/default.nix22
-rw-r--r--pkgs/development/python-modules/python-mapnik/default.nix2
-rw-r--r--pkgs/development/python-modules/python-redis-lock/default.nix2
-rw-r--r--pkgs/development/python-modules/python-xmp-toolkit/default.nix2
-rw-r--r--pkgs/development/python-modules/pythonocc-core/default.nix2
-rw-r--r--pkgs/development/python-modules/pytorch/bin.nix2
-rw-r--r--pkgs/development/python-modules/pytorch/default.nix2
-rw-r--r--pkgs/development/python-modules/pyutil/default.nix2
-rw-r--r--pkgs/development/python-modules/rbtools/default.nix4
-rw-r--r--pkgs/development/python-modules/reikna/default.nix12
-rw-r--r--pkgs/development/python-modules/rfc6555/default.nix8
-rw-r--r--pkgs/development/python-modules/rich/default.nix2
-rw-r--r--pkgs/development/python-modules/rsa/4_0.nix2
-rw-r--r--pkgs/development/python-modules/rsa/default.nix2
-rw-r--r--pkgs/development/python-modules/s3transfer/default.nix8
-rw-r--r--pkgs/development/python-modules/scrapy/default.nix2
-rw-r--r--pkgs/development/python-modules/screeninfo/default.nix2
-rw-r--r--pkgs/development/python-modules/selenium/default.nix2
-rw-r--r--pkgs/development/python-modules/sentry-sdk/default.nix2
-rw-r--r--pkgs/development/python-modules/shapely/default.nix2
-rw-r--r--pkgs/development/python-modules/simplebayes/default.nix2
-rw-r--r--pkgs/development/python-modules/spacy/models.nix6
-rw-r--r--pkgs/development/python-modules/stringtemplate/default.nix6
-rw-r--r--pkgs/development/python-modules/tables/3.5.nix16
-rw-r--r--pkgs/development/python-modules/tables/default.nix16
-rw-r--r--pkgs/development/python-modules/tatsu/default.nix4
-rw-r--r--pkgs/development/python-modules/tensorflow/bin.nix2
-rw-r--r--pkgs/development/python-modules/tkinter/default.nix5
-rw-r--r--pkgs/development/python-modules/todoist/default.nix10
-rw-r--r--pkgs/development/python-modules/trackpy/default.nix2
-rw-r--r--pkgs/development/python-modules/transformers/default.nix2
-rw-r--r--pkgs/development/python-modules/trytond/default.nix8
-rw-r--r--pkgs/development/python-modules/tumpa/default.nix4
-rw-r--r--pkgs/development/python-modules/twisted/default.nix2
-rw-r--r--pkgs/development/python-modules/unicorn/default.nix2
-rw-r--r--pkgs/development/python-modules/urllib3/default.nix4
-rw-r--r--pkgs/development/python-modules/watchdog/default.nix2
-rw-r--r--pkgs/development/python-modules/werkzeug/default.nix2
-rw-r--r--pkgs/development/python-modules/xcffib/default.nix2
-rw-r--r--pkgs/development/python-modules/xnd/default.nix5
-rw-r--r--pkgs/development/python-modules/zconfig/default.nix2
-rw-r--r--pkgs/development/python-modules/zope_lifecycleevent/default.nix2
211 files changed, 524 insertions, 545 deletions
diff --git a/pkgs/development/python-modules/Cython/default.nix b/pkgs/development/python-modules/Cython/default.nix
index 84f54fd7af6..64f5bb3ab65 100644
--- a/pkgs/development/python-modules/Cython/default.nix
+++ b/pkgs/development/python-modules/Cython/default.nix
@@ -16,12 +16,12 @@ let
     ++ [ "reimport_from_subinterpreter" ]
     # cython's testsuite is not working very well with libc++
     # We are however optimistic about things outside of testsuite still working
-    ++ stdenv.lib.optionals (stdenv.cc.isClang or false) [ "cpdef_extern_func" "libcpp_algo" ]
+    ++ lib.optionals (stdenv.cc.isClang or false) [ "cpdef_extern_func" "libcpp_algo" ]
     # Some tests in the test suite isn't working on aarch64. Disable them for
     # now until upstream finds a workaround.
     # Upstream issue here: https://github.com/cython/cython/issues/2308
-    ++ stdenv.lib.optionals stdenv.isAarch64 [ "numpy_memoryview" ]
-    ++ stdenv.lib.optionals stdenv.isi686 [ "future_division" "overflow_check_longlong" ]
+    ++ lib.optionals stdenv.isAarch64 [ "numpy_memoryview" ]
+    ++ lib.optionals stdenv.isi686 [ "future_division" "overflow_check_longlong" ]
   ;
 
 in buildPythonPackage rec {
@@ -55,7 +55,7 @@ in buildPythonPackage rec {
     export HOME="$NIX_BUILD_TOP"
     ${python.interpreter} runtests.py -j$NIX_BUILD_CORES \
       --no-code-style \
-      ${stdenv.lib.optionalString (builtins.length excludedTests != 0)
+      ${lib.optionalString (builtins.length excludedTests != 0)
         ''--exclude="(${builtins.concatStringsSep "|" excludedTests})"''}
   '';
 
diff --git a/pkgs/development/python-modules/HTSeq/default.nix b/pkgs/development/python-modules/HTSeq/default.nix
index 178b6a7b85c..be4bb9e31d3 100644
--- a/pkgs/development/python-modules/HTSeq/default.nix
+++ b/pkgs/development/python-modules/HTSeq/default.nix
@@ -13,9 +13,9 @@ buildPythonPackage rec {
   nativeBuildInputs = [ cython ];
   propagatedBuildInputs = [ numpy pysam matplotlib ];
 
-  checkPhase = stdenv.lib.optionalString isPy27 ''
+  checkPhase = lib.optionalString isPy27 ''
     ${python.interpreter} python2/test/test_general.py
-  '' + stdenv.lib.optionalString isPy3k ''
+  '' + lib.optionalString isPy3k ''
     ${python.interpreter} python3/test/test_general.py
   '';
 
diff --git a/pkgs/development/python-modules/Theano/default.nix b/pkgs/development/python-modules/Theano/default.nix
index c2dd7460b13..e279100e9cc 100644
--- a/pkgs/development/python-modules/Theano/default.nix
+++ b/pkgs/development/python-modules/Theano/default.nix
@@ -40,8 +40,8 @@ let
     if stdenv.cc.isClang then "clang++" else
     throw "Unknown C++ compiler";
   cxx_compiler = wrapped cxx_compiler_name "\\$HOME/.theano"
-    (    stdenv.lib.optional cudaSupport libgpuarray_
-      ++ stdenv.lib.optional cudnnSupport cudnn );
+    (    lib.optional cudaSupport libgpuarray_
+      ++ lib.optional cudnnSupport cudnn );
 
   libgpuarray_ = libgpuarray.override { inherit cudaSupport cudatoolkit; };
 
@@ -60,10 +60,10 @@ in buildPythonPackage rec {
     substituteInPlace theano/configdefaults.py \
       --replace 'StrParam(param, is_valid=warn_cxx)' 'StrParam('\'''${cxx_compiler}'\''', is_valid=warn_cxx)' \
       --replace 'rc == 0 and config.cxx != ""' 'config.cxx != ""'
-  '' + stdenv.lib.optionalString cudaSupport ''
+  '' + lib.optionalString cudaSupport ''
     substituteInPlace theano/configdefaults.py \
       --replace 'StrParam(get_cuda_root)' 'StrParam('\'''${cudatoolkit}'\''')'
-  '' + stdenv.lib.optionalString cudnnSupport ''
+  '' + lib.optionalString cudnnSupport ''
     substituteInPlace theano/configdefaults.py \
       --replace 'StrParam(default_dnn_base_path)' 'StrParam('\'''${cudnn}'\''')'
   '';
diff --git a/pkgs/development/python-modules/aenum/default.nix b/pkgs/development/python-modules/aenum/default.nix
index 32b26a5e035..f21d8f4195a 100644
--- a/pkgs/development/python-modules/aenum/default.nix
+++ b/pkgs/development/python-modules/aenum/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchPypi, buildPythonPackage, python, isPy3k, glibcLocales }:
+{ lib, stdenv, fetchPypi, buildPythonPackage, python, isPy3k, glibcLocales }:
 
 buildPythonPackage rec {
   pname = "aenum";
@@ -22,10 +22,10 @@ buildPythonPackage rec {
   runHook postCheck
   '';
 
-  meta = {
+  meta = with lib; {
     description = "Advanced Enumerations (compatible with Python's stdlib Enum), NamedTuples, and NamedConstants";
-    maintainers = with stdenv.lib.maintainers; [ vrthra ];
-    license = with stdenv.lib.licenses; [ bsd3 ];
+    maintainers = with maintainers; [ vrthra ];
+    license = licenses.bsd3;
     homepage = "https://github.com/ethanfurman/aenum";
   };
 }
diff --git a/pkgs/development/python-modules/aiodns/default.nix b/pkgs/development/python-modules/aiodns/default.nix
index e1130331365..4ba4bd59af2 100644
--- a/pkgs/development/python-modules/aiodns/default.nix
+++ b/pkgs/development/python-modules/aiodns/default.nix
@@ -10,9 +10,9 @@ buildPythonPackage rec {
     sha256 = "815fdef4607474295d68da46978a54481dd1e7be153c7d60f9e72773cd38d77d";
   };
 
-  propagatedBuildInputs = with stdenv.lib; [ pycares ]
-    ++ optional (pythonOlder "3.7") typing
-    ++ optional (isPy27 || isPyPy) trollius;
+  propagatedBuildInputs = [ pycares ]
+    ++ lib.optional (pythonOlder "3.7") typing
+    ++ lib.optional (isPy27 || isPyPy) trollius;
 
   checkPhase = ''
     ${python.interpreter} tests.py
diff --git a/pkgs/development/python-modules/aioredis/default.nix b/pkgs/development/python-modules/aioredis/default.nix
index 2e59168157b..94f503fe2cc 100644
--- a/pkgs/development/python-modules/aioredis/default.nix
+++ b/pkgs/development/python-modules/aioredis/default.nix
@@ -15,7 +15,7 @@ buildPythonPackage rec {
 
   propagatedBuildInputs = [
     async-timeout
-  ] ++ stdenv.lib.optional (!isPyPy) hiredis;
+  ] ++ lib.optional (!isPyPy) hiredis;
 
   # Wants to run redis-server, hardcoded FHS paths, too much trouble.
   doCheck = false;
diff --git a/pkgs/development/python-modules/altair/default.nix b/pkgs/development/python-modules/altair/default.nix
index 018ac7ddf50..a3b515ebeca 100644
--- a/pkgs/development/python-modules/altair/default.nix
+++ b/pkgs/development/python-modules/altair/default.nix
@@ -33,7 +33,7 @@ buildPythonPackage rec {
     pandas
     six
     toolz
-  ] ++ stdenv.lib.optionals (pythonOlder "3.5") [ typing ];
+  ] ++ lib.optionals (pythonOlder "3.5") [ typing ];
 
   checkInputs = [
     glibcLocales
diff --git a/pkgs/development/python-modules/aniso8601/default.nix b/pkgs/development/python-modules/aniso8601/default.nix
index c6c05283f28..804402a4ca6 100644
--- a/pkgs/development/python-modules/aniso8601/default.nix
+++ b/pkgs/development/python-modules/aniso8601/default.nix
@@ -13,7 +13,7 @@ buildPythonPackage rec {
 
   propagatedBuildInputs = [ dateutil ];
 
-  checkInputs = stdenv.lib.optional (!isPy3k) mock;
+  checkInputs = lib.optional (!isPy3k) mock;
 
   src = fetchPypi {
     inherit pname version;
diff --git a/pkgs/development/python-modules/apipkg/default.nix b/pkgs/development/python-modules/apipkg/default.nix
index 88535bb7cf1..604c37b42ba 100644
--- a/pkgs/development/python-modules/apipkg/default.nix
+++ b/pkgs/development/python-modules/apipkg/default.nix
@@ -22,13 +22,13 @@ buildPythonPackage rec {
   # Failing tests on Python 3
   # https://github.com/pytest-dev/apipkg/issues/17
   checkPhase = let
-    disabledTests = stdenv.lib.optionals isPy3k [
+    disabledTests = lib.optionals isPy3k [
       "test_error_loading_one_element"
       "test_aliasmodule_proxy_methods"
       "test_eagerload_on_bython"
     ];
-    testExpression = stdenv.lib.optionalString (disabledTests != [])
-    "-k 'not ${stdenv.lib.concatStringsSep " and not " disabledTests}'";
+    testExpression = lib.optionalString (disabledTests != [])
+    "-k 'not ${lib.concatStringsSep " and not " disabledTests}'";
   in ''
     py.test ${testExpression}
   '';
diff --git a/pkgs/development/python-modules/avro/default.nix b/pkgs/development/python-modules/avro/default.nix
index 6f7b8b9c6c1..35cab724a86 100644
--- a/pkgs/development/python-modules/avro/default.nix
+++ b/pkgs/development/python-modules/avro/default.nix
@@ -12,7 +12,7 @@ buildPythonPackage rec {
   patchPhase = ''
     # this test requires network access
     sed -i 's/test_server_with_path/noop/' avro/test/test_ipc.py
-  '' + (stdenv.lib.optionalString isPy3k ''
+  '' + (lib.optionalString isPy3k ''
     # these files require twisted, which is not python3 compatible
     rm avro/txipc.py
     rm avro/test/txsample*
diff --git a/pkgs/development/python-modules/bcrypt/default.nix b/pkgs/development/python-modules/bcrypt/default.nix
index dc50c56018e..e74b0934b30 100644
--- a/pkgs/development/python-modules/bcrypt/default.nix
+++ b/pkgs/development/python-modules/bcrypt/default.nix
@@ -1,8 +1,6 @@
-{ stdenv, buildPythonPackage, isPyPy, fetchPypi, pythonOlder
+{ lib, stdenv, buildPythonPackage, isPyPy, fetchPypi, pythonOlder
 , cffi, pycparser, mock, pytest, py, six }:
 
-with stdenv.lib;
-
 buildPythonPackage rec {
   version = "3.2.0";
   pname = "bcrypt";
@@ -12,10 +10,12 @@ buildPythonPackage rec {
     inherit pname version;
     sha256 = "5b93c1726e50a93a033c36e5ca7fdcd29a5c7395af50a6892f5d9e7c6cfbfb29";
   };
+
   buildInputs = [ pycparser mock pytest py ];
-  propagatedBuildInputs = [ six ] ++ optional (!isPyPy) cffi;
 
-  meta = {
+  propagatedBuildInputs = [ six ] ++ lib.optional (!isPyPy) cffi;
+
+  meta = with lib; {
     maintainers = with maintainers; [ domenkozar ];
     description = "Modern password hashing for your software and your servers";
     license = licenses.asl20;
diff --git a/pkgs/development/python-modules/beancount/default.nix b/pkgs/development/python-modules/beancount/default.nix
index f1dc7a5349d..fa97c7c97a9 100644
--- a/pkgs/development/python-modules/beancount/default.nix
+++ b/pkgs/development/python-modules/beancount/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, buildPythonPackage, fetchPypi, isPy3k
+{ lib, stdenv, buildPythonPackage, fetchPypi, isPy3k
 , beautifulsoup4, bottle, chardet, dateutil
 , google_api_python_client, lxml, oauth2client
 , ply, python_magic, pytest, requests }:
@@ -33,7 +33,7 @@ buildPythonPackage rec {
     pytest
   ];
 
-  meta = {
+  meta = with lib; {
     homepage = "http://furius.ca/beancount/";
     description = "Double-entry bookkeeping computer language";
     longDescription = ''
@@ -41,8 +41,8 @@ buildPythonPackage rec {
         financial transaction records in a text file, read them in memory,
         generate a variety of reports from them, and provides a web interface.
     '';
-    license = stdenv.lib.licenses.gpl2;
-    maintainers = with stdenv.lib.maintainers; [ ];
+    license = licenses.gpl2;
+    maintainers = with maintainers; [ ];
   };
 }
 
diff --git a/pkgs/development/python-modules/beanstalkc/default.nix b/pkgs/development/python-modules/beanstalkc/default.nix
index c24e9a03d15..a74f6c6f8f2 100644
--- a/pkgs/development/python-modules/beanstalkc/default.nix
+++ b/pkgs/development/python-modules/beanstalkc/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchFromGitHub, buildPythonPackage }:
+{ lib, stdenv, fetchFromGitHub, buildPythonPackage }:
 
 buildPythonPackage rec {
   pname = "beanstalkc";
@@ -13,10 +13,10 @@ buildPythonPackage rec {
 
   doCheck = false;
 
-  meta = {
+  meta = with lib; {
     description = "A simple beanstalkd client library for Python";
-    maintainers = with stdenv.lib.maintainers; [ aanderse ];
-    license = with stdenv.lib.licenses; [ asl20 ];
+    maintainers = with maintainers; [ aanderse ];
+    license = licenses.asl20;
     homepage = "https://github.com/earl/beanstalkc";
   };
 }
diff --git a/pkgs/development/python-modules/bedup/default.nix b/pkgs/development/python-modules/bedup/default.nix
index 0e339dca097..f38d4263c24 100644
--- a/pkgs/development/python-modules/bedup/default.nix
+++ b/pkgs/development/python-modules/bedup/default.nix
@@ -25,7 +25,7 @@ buildPythonPackage rec {
 
   buildInputs = [ btrfs-progs ];
   propagatedBuildInputs = [ contextlib2 pyxdg pycparser alembic ]
-    ++ stdenv.lib.optionals (!isPyPy) [ cffi ];
+    ++ lib.optionals (!isPyPy) [ cffi ];
 
   meta = with lib; {
     description = "Deduplication for Btrfs";
diff --git a/pkgs/development/python-modules/behave/default.nix b/pkgs/development/python-modules/behave/default.nix
index 56217dca617..43c74fc9571 100644
--- a/pkgs/development/python-modules/behave/default.nix
+++ b/pkgs/development/python-modules/behave/default.nix
@@ -26,7 +26,7 @@ buildPythonApplication rec {
 
   # timing-based test flaky on Darwin
   # https://github.com/NixOS/nixpkgs/pull/97737#issuecomment-691489824
-  disabledTests = stdenv.lib.optionals stdenv.isDarwin [ "test_step_decorator_async_run_until_complete" ];
+  disabledTests = lib.optionals stdenv.isDarwin [ "test_step_decorator_async_run_until_complete" ];
 
   postCheck = ''
     export LANG="en_US.UTF-8"
diff --git a/pkgs/development/python-modules/binwalk/default.nix b/pkgs/development/python-modules/binwalk/default.nix
index 3d1b9c0a90c..c2f059dd93d 100644
--- a/pkgs/development/python-modules/binwalk/default.nix
+++ b/pkgs/development/python-modules/binwalk/default.nix
@@ -35,7 +35,7 @@ buildPythonPackage {
   };
 
   propagatedBuildInputs = [ zlib xz ncompress gzip bzip2 gnutar p7zip cabextract cramfsswap cramfsprogs sasquatch squashfsTools lzma pycrypto ]
-  ++ stdenv.lib.optionals visualizationSupport [ matplotlib pyqtgraph ];
+  ++ lib.optionals visualizationSupport [ matplotlib pyqtgraph ];
 
   # setup.py only installs version.py during install, not test
   postPatch = ''
diff --git a/pkgs/development/python-modules/bootstrapped-pip/default.nix b/pkgs/development/python-modules/bootstrapped-pip/default.nix
index 690c88b83f4..5a6333d656a 100644
--- a/pkgs/development/python-modules/bootstrapped-pip/default.nix
+++ b/pkgs/development/python-modules/bootstrapped-pip/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, python, fetchPypi, makeWrapper, unzip, makeSetupHook
+{ lib, stdenv, python, fetchPypi, makeWrapper, unzip, makeSetupHook
 , pipInstallHook
 , setuptoolsBuildHook
 , wheel, pip, setuptools
@@ -32,7 +32,7 @@ stdenv.mkDerivation rec {
 
   buildPhase = ":";
 
-  installPhase = stdenv.lib.strings.optionalString (!stdenv.hostPlatform.isWindows) ''
+  installPhase = lib.strings.optionalString (!stdenv.hostPlatform.isWindows) ''
     export SETUPTOOLS_INSTALL_WINDOWS_SPECIFIC_FILES=0
   '' + ''
     # Give folders a known name
@@ -61,7 +61,7 @@ stdenv.mkDerivation rec {
 
   meta = {
     description = "Version of pip used for bootstrapping";
-    license = stdenv.lib.unique (pip.meta.license ++ setuptools.meta.license ++ wheel.meta.license);
+    license = lib.unique (pip.meta.license ++ setuptools.meta.license ++ wheel.meta.license);
     homepage = pip.meta.homepage;
   };
 }
diff --git a/pkgs/development/python-modules/buildout-nix/default.nix b/pkgs/development/python-modules/buildout-nix/default.nix
index cf8b1382301..7f7afd67e7e 100644
--- a/pkgs/development/python-modules/buildout-nix/default.nix
+++ b/pkgs/development/python-modules/buildout-nix/default.nix
@@ -1,4 +1,4 @@
-{ fetchPypi, stdenv, buildPythonPackage }:
+{ lib, buildPythonPackage, fetchPypi }:
 
 buildPythonPackage rec {
   pname = "zc.buildout";
@@ -13,10 +13,10 @@ buildPythonPackage rec {
 
   postInstall = "mv $out/bin/buildout{,-nix}";
 
-  meta = {
+  meta = with lib; {
     homepage = "http://www.buildout.org";
     description = "A software build and configuration system";
-    license = stdenv.lib.licenses.zpl21;
-    maintainers = [ stdenv.lib.maintainers.goibhniu ];
+    license = licenses.zpl21;
+    maintainers = [ maintainers.goibhniu ];
   };
 }
diff --git a/pkgs/development/python-modules/cadquery/default.nix b/pkgs/development/python-modules/cadquery/default.nix
index e1566baff6b..72334390bc3 100644
--- a/pkgs/development/python-modules/cadquery/default.nix
+++ b/pkgs/development/python-modules/cadquery/default.nix
@@ -48,7 +48,7 @@ let
       libGL
       libGLU
       libX11
-    ] ++ stdenv.lib.optionals stdenv.isDarwin [ Cocoa ];
+    ] ++ lib.optionals stdenv.isDarwin [ Cocoa ];
 
     propagatedBuildInputs = [
       six
diff --git a/pkgs/development/python-modules/capstone/default.nix b/pkgs/development/python-modules/capstone/default.nix
index 7d5e416a9c5..d7df0bee5ca 100644
--- a/pkgs/development/python-modules/capstone/default.nix
+++ b/pkgs/development/python-modules/capstone/default.nix
@@ -8,7 +8,7 @@
 
 buildPythonPackage rec {
   pname = "capstone";
-  version = stdenv.lib.getVersion capstone;
+  version = lib.getVersion capstone;
 
   src = capstone.src;
   sourceRoot = "${capstone.name}/bindings/python";
diff --git a/pkgs/development/python-modules/cddb/default.nix b/pkgs/development/python-modules/cddb/default.nix
index 0956a971ebd..55d659376c6 100644
--- a/pkgs/development/python-modules/cddb/default.nix
+++ b/pkgs/development/python-modules/cddb/default.nix
@@ -9,7 +9,7 @@ buildPythonPackage rec {
   version = "1.4";
   disabled = isPy3k;
 
-  buildInputs = stdenv.lib.optionals stdenv.isDarwin [ pkgs.darwin.apple_sdk.frameworks.IOKit ];
+  buildInputs = lib.optionals stdenv.isDarwin [ pkgs.darwin.apple_sdk.frameworks.IOKit ];
 
   src = pkgs.fetchurl {
     url = "http://cddb-py.sourceforge.net/${pname}-${version}.tar.gz";
diff --git a/pkgs/development/python-modules/cdecimal/default.nix b/pkgs/development/python-modules/cdecimal/default.nix
index f788d32520e..cf889050590 100644
--- a/pkgs/development/python-modules/cdecimal/default.nix
+++ b/pkgs/development/python-modules/cdecimal/default.nix
@@ -1,6 +1,4 @@
-{ lib, stdenv, fetchurl, buildPythonPackage, isPy3k }:
-
-with stdenv.lib;
+{ lib, buildPythonPackage, fetchurl, isPy3k }:
 
 buildPythonPackage rec {
   pname = "cdecimal";
diff --git a/pkgs/development/python-modules/cffi/default.nix b/pkgs/development/python-modules/cffi/default.nix
index 55390ea5ff9..3dcd6a996cb 100644
--- a/pkgs/development/python-modules/cffi/default.nix
+++ b/pkgs/development/python-modules/cffi/default.nix
@@ -17,7 +17,7 @@ if isPyPy then null else buildPythonPackage rec {
   # On Darwin, the cffi tests want to hit libm a lot, and look for it in a global
   # impure search path. It's obnoxious how much repetition there is, and how difficult
   # it is to get it to search somewhere else (since we do actually have a libm symlink in libSystem)
-  prePatch = stdenv.lib.optionalString stdenv.isDarwin ''
+  prePatch = lib.optionalString stdenv.isDarwin ''
     substituteInPlace testing/cffi0/test_parsing.py \
       --replace 'lib_m = "m"' 'lib_m = "System"' \
       --replace '"libm" in name' '"libSystem" in name'
@@ -29,7 +29,7 @@ if isPyPy then null else buildPythonPackage rec {
   '';
 
   # The tests use -Werror but with python3.6 clang detects some unreachable code.
-  NIX_CFLAGS_COMPILE = stdenv.lib.optionalString stdenv.cc.isClang
+  NIX_CFLAGS_COMPILE = lib.optionalString stdenv.cc.isClang
     "-Wno-unused-command-line-argument -Wno-unreachable-code";
 
   doCheck = !stdenv.hostPlatform.isMusl && !stdenv.isDarwin; # TODO: Investigate
@@ -40,7 +40,7 @@ if isPyPy then null else buildPythonPackage rec {
   meta = with lib; {
     maintainers = with maintainers; [ domenkozar lnl7 ];
     homepage = "https://cffi.readthedocs.org/";
-    license = with licenses; [ mit ];
+    license = licenses.mit;
     description = "Foreign Function Interface for Python calling C code";
   };
 }
diff --git a/pkgs/development/python-modules/cheetah3/default.nix b/pkgs/development/python-modules/cheetah3/default.nix
index e4fd549445a..a705bffa810 100644
--- a/pkgs/development/python-modules/cheetah3/default.nix
+++ b/pkgs/development/python-modules/cheetah3/default.nix
@@ -1,4 +1,4 @@
-{ lib, buildPythonPackage, fetchPypi, stdenv }:
+{ lib, buildPythonPackage, fetchPypi }:
 
 buildPythonPackage rec {
   pname = "Cheetah3";
@@ -11,10 +11,10 @@ buildPythonPackage rec {
 
   doCheck = false; # Circular dependency
 
-  meta = {
+  meta = with lib; {
     homepage = "http://www.cheetahtemplate.org/";
     description = "A template engine and code generation tool";
-    license = lib.licenses.mit;
-    maintainers = with stdenv.lib.maintainers; [ pjjw ];
+    license = licenses.mit;
+    maintainers = with maintainers; [ pjjw ];
   };
 }
diff --git a/pkgs/development/python-modules/cherrypy/17.nix b/pkgs/development/python-modules/cherrypy/17.nix
index 9982db19f38..2ee8eb3bd0c 100644
--- a/pkgs/development/python-modules/cherrypy/17.nix
+++ b/pkgs/development/python-modules/cherrypy/17.nix
@@ -25,7 +25,7 @@ buildPythonPackage rec {
   ];
 
   checkPhase = ''
-    pytest ${stdenv.lib.optionalString stdenv.isDarwin "--ignore=cherrypy/test/test_wsgi_unix_socket.py"}
+    pytest ${lib.optionalString stdenv.isDarwin "--ignore=cherrypy/test/test_wsgi_unix_socket.py"}
   '';
 
   meta = with lib; {
diff --git a/pkgs/development/python-modules/cherrypy/default.nix b/pkgs/development/python-modules/cherrypy/default.nix
index 76fd780e523..8a915d520e5 100644
--- a/pkgs/development/python-modules/cherrypy/default.nix
+++ b/pkgs/development/python-modules/cherrypy/default.nix
@@ -41,7 +41,7 @@ buildPythonPackage rec {
       -k 'not KeyboardInterrupt and not daemonize and not Autoreload' \
       --deselect=cherrypy/test/test_static.py::StaticTest::test_null_bytes \
       --deselect=cherrypy/test/test_tools.py::ToolTests::testCombinedTools \
-      ${stdenv.lib.optionalString stdenv.isDarwin
+      ${lib.optionalString stdenv.isDarwin
         "--deselect=cherrypy/test/test_bus.py::BusMethodTests::test_block"}
   '';
 
diff --git a/pkgs/development/python-modules/cld2-cffi/default.nix b/pkgs/development/python-modules/cld2-cffi/default.nix
index df28bcdf3aa..fc5a6b0e54b 100644
--- a/pkgs/development/python-modules/cld2-cffi/default.nix
+++ b/pkgs/development/python-modules/cld2-cffi/default.nix
@@ -13,7 +13,7 @@ buildPythonPackage rec {
   checkInputs = [ nose ];
 
   # gcc doesn't approve of this code, so disable -Werror
-  NIX_CFLAGS_COMPILE = "-w" + stdenv.lib.optionalString stdenv.cc.isClang " -Wno-error=c++11-narrowing";
+  NIX_CFLAGS_COMPILE = "-w" + lib.optionalString stdenv.cc.isClang " -Wno-error=c++11-narrowing";
 
   checkPhase = "nosetests -v";
 
diff --git a/pkgs/development/python-modules/cmd2/default.nix b/pkgs/development/python-modules/cmd2/default.nix
index be4e64f760e..bafdb9cb95d 100644
--- a/pkgs/development/python-modules/cmd2/default.nix
+++ b/pkgs/development/python-modules/cmd2/default.nix
@@ -15,7 +15,7 @@ buildPythonPackage rec {
 
   LC_ALL="en_US.UTF-8";
 
-  postPatch = stdenv.lib.optional stdenv.isDarwin ''
+  postPatch = lib.optional stdenv.isDarwin ''
     # Fake the impure dependencies pbpaste and pbcopy
     mkdir bin
     echo '#!${stdenv.shell}' > bin/pbpaste
@@ -38,7 +38,7 @@ buildPythonPackage rec {
     wcwidth
     attrs
   ]
-  ++ stdenv.lib.optionals (pythonOlder "3.5") [contextlib2 typing]
+  ++ lib.optionals (pythonOlder "3.5") [contextlib2 typing]
   ;
 
 
@@ -46,7 +46,7 @@ buildPythonPackage rec {
   # pytest-cov
   # argcomplete  will generate errors
   checkInputs= [ pytest mock which vim glibcLocales pytest-mock ]
-        ++ stdenv.lib.optional (pythonOlder "3.6") [ mock ];
+        ++ lib.optional (pythonOlder "3.6") [ mock ];
   checkPhase = ''
     # test_path_completion_user_expansion might be fixed in the next release
     py.test -k 'not test_path_completion_user_expansion'
diff --git a/pkgs/development/python-modules/codecov/default.nix b/pkgs/development/python-modules/codecov/default.nix
index 455888c447d..924422bf7d4 100644
--- a/pkgs/development/python-modules/codecov/default.nix
+++ b/pkgs/development/python-modules/codecov/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, buildPythonPackage, fetchPypi, requests, coverage, unittest2 }:
+{ lib, buildPythonPackage, fetchPypi, requests, coverage, unittest2 }:
 
 buildPythonPackage rec {
   pname = "codecov";
@@ -20,9 +20,9 @@ buildPythonPackage rec {
   # No tests in archive
   doCheck = false;
 
-  meta = {
+  meta = with lib; {
     description = "Python report uploader for Codecov";
     homepage = "https://codecov.io/";
-    license = stdenv.lib.licenses.asl20;
+    license = licenses.asl20;
   };
 }
diff --git a/pkgs/development/python-modules/colorlover/default.nix b/pkgs/development/python-modules/colorlover/default.nix
index 6aea26e8936..70dd66e8f81 100644
--- a/pkgs/development/python-modules/colorlover/default.nix
+++ b/pkgs/development/python-modules/colorlover/default.nix
@@ -1,4 +1,6 @@
-{ buildPythonPackage, fetchPypi, stdenv
+{ lib
+, buildPythonPackage
+, fetchPypi
 }:
 
 buildPythonPackage rec {
@@ -13,10 +15,10 @@ buildPythonPackage rec {
   # no tests included in distributed archive
   doCheck = false;
 
-  meta = {
+  meta = with lib; {
     homepage = "https://github.com/jackparmer/colorlover";
     description = "Color scales in Python for humans";
-    license = stdenv.lib.licenses.mit;
-    maintainers = with stdenv.lib.maintainers; [ globin ];
+    license = licenses.mit;
+    maintainers = with maintainers; [ globin ];
   };
 }
diff --git a/pkgs/development/python-modules/construct/default.nix b/pkgs/development/python-modules/construct/default.nix
index bb334f11c75..8d0c83ca9e8 100644
--- a/pkgs/development/python-modules/construct/default.nix
+++ b/pkgs/development/python-modules/construct/default.nix
@@ -18,7 +18,7 @@ buildPythonPackage rec {
 
   checkInputs = [ pytestCheckHook pytest-benchmark numpy arrow ruamel_yaml ];
 
-  disabledTests = stdenv.lib.optionals stdenv.isDarwin [ "test_multiprocessing" ];
+  disabledTests = lib.optionals stdenv.isDarwin [ "test_multiprocessing" ];
 
   pytestFlagsArray = [ "--benchmark-disable" ];
 
diff --git a/pkgs/development/python-modules/cot/default.nix b/pkgs/development/python-modules/cot/default.nix
index 0c2bb961290..a6de8321dc0 100644
--- a/pkgs/development/python-modules/cot/default.nix
+++ b/pkgs/development/python-modules/cot/default.nix
@@ -16,7 +16,7 @@ buildPythonPackage rec {
   };
 
   propagatedBuildInputs = [ colorlog pyvmomi requests verboselogs pyopenssl setuptools ]
-  ++ stdenv.lib.optional (pythonOlder "3.3") psutil;
+  ++ lib.optional (pythonOlder "3.3") psutil;
 
   checkInputs = [ mock pytestCheckHook pytest-mock qemu ];
 
diff --git a/pkgs/development/python-modules/cryptography/3.3.nix b/pkgs/development/python-modules/cryptography/3.3.nix
index a9531824158..b6972e6d56b 100644
--- a/pkgs/development/python-modules/cryptography/3.3.nix
+++ b/pkgs/development/python-modules/cryptography/3.3.nix
@@ -33,18 +33,18 @@ buildPythonPackage rec {
 
   outputs = [ "out" "dev" ];
 
-  nativeBuildInputs = stdenv.lib.optionals (!isPyPy) [
+  nativeBuildInputs = lib.optionals (!isPyPy) [
     cffi
   ];
 
   buildInputs = [ openssl ]
-             ++ stdenv.lib.optional stdenv.isDarwin darwin.apple_sdk.frameworks.Security;
+             ++ lib.optional stdenv.isDarwin darwin.apple_sdk.frameworks.Security;
   propagatedBuildInputs = [
     packaging
     six
-  ] ++ stdenv.lib.optionals (!isPyPy) [
+  ] ++ lib.optionals (!isPyPy) [
     cffi
-  ] ++ stdenv.lib.optionals isPy27 [
+  ] ++ lib.optionals isPy27 [
     ipaddress enum34
   ];
 
diff --git a/pkgs/development/python-modules/cryptography/default.nix b/pkgs/development/python-modules/cryptography/default.nix
index bae494989c7..ad402efd759 100644
--- a/pkgs/development/python-modules/cryptography/default.nix
+++ b/pkgs/development/python-modules/cryptography/default.nix
@@ -31,18 +31,18 @@ buildPythonPackage rec {
 
   outputs = [ "out" "dev" ];
 
-  nativeBuildInputs = stdenv.lib.optionals (!isPyPy) [
+  nativeBuildInputs = lib.optionals (!isPyPy) [
     cffi
   ];
 
   buildInputs = [ openssl ]
-             ++ stdenv.lib.optional stdenv.isDarwin darwin.apple_sdk.frameworks.Security;
+             ++ lib.optional stdenv.isDarwin darwin.apple_sdk.frameworks.Security;
   propagatedBuildInputs = [
     packaging
     six
-  ] ++ stdenv.lib.optionals (!isPyPy) [
+  ] ++ lib.optionals (!isPyPy) [
     cffi
-  ] ++ stdenv.lib.optionals isPy27 [
+  ] ++ lib.optionals isPy27 [
     ipaddress enum34
   ];
 
diff --git a/pkgs/development/python-modules/csscompressor/default.nix b/pkgs/development/python-modules/csscompressor/default.nix
index a7256a54e3b..b3d08c12e62 100644
--- a/pkgs/development/python-modules/csscompressor/default.nix
+++ b/pkgs/development/python-modules/csscompressor/default.nix
@@ -1,4 +1,5 @@
-{ stdenv, buildPythonPackage, fetchPypi }:
+{ lib, buildPythonPackage, fetchPypi }:
+
 buildPythonPackage rec {
   pname = "csscompressor";
   version = "0.9.5";
@@ -10,10 +11,10 @@ buildPythonPackage rec {
 
   doCheck = false; # No tests
 
-  meta = {
+  meta = with lib; {
     description = "A python port of YUI CSS Compressor";
     homepage = "https://pypi.python.org/pypi/csscompressor";
-    license = stdenv.lib.licenses.bsd3;
+    license = licenses.bsd3;
     maintainers = [];
   };
 }
diff --git a/pkgs/development/python-modules/curtsies/default.nix b/pkgs/development/python-modules/curtsies/default.nix
index f860f2ae5eb..4c4c7dbe231 100644
--- a/pkgs/development/python-modules/curtsies/default.nix
+++ b/pkgs/development/python-modules/curtsies/default.nix
@@ -17,7 +17,7 @@ buildPythonPackage rec {
   ];
 
   propagatedBuildInputs = [ blessings wcwidth ]
-    ++ stdenv.lib.optionals (pythonOlder "3.5") [ typing ];
+    ++ lib.optionals (pythonOlder "3.5") [ typing ];
 
   checkInputs = [ mock pyte nose ];
 
diff --git a/pkgs/development/python-modules/dbf/default.nix b/pkgs/development/python-modules/dbf/default.nix
index 348f91ea683..b9c264a2015 100644
--- a/pkgs/development/python-modules/dbf/default.nix
+++ b/pkgs/development/python-modules/dbf/default.nix
@@ -9,7 +9,7 @@ buildPythonPackage rec {
       sha256 = "a4a7a8cdc113d840142d21a796c16c7d329ad35c48f17156446732c83ebc571a";
     };
 
-    propagatedBuildInputs = [ aenum ] ++ stdenv.lib.optional (pythonOlder "3.4") enum34;
+    propagatedBuildInputs = [ aenum ] ++ lib.optional (pythonOlder "3.4") enum34;
 
     doCheck = !isPy3k;
     # tests are not yet ported.
diff --git a/pkgs/development/python-modules/demjson/default.nix b/pkgs/development/python-modules/demjson/default.nix
index 988c2815da8..fc70562938e 100644
--- a/pkgs/development/python-modules/demjson/default.nix
+++ b/pkgs/development/python-modules/demjson/default.nix
@@ -9,7 +9,7 @@ buildPythonPackage rec {
     sha256 = "0ygbddpnvp5lby6mr5kz60la3hkvwwzv3wwb3z0w9ngxl0w21pii";
   };
 
-  checkPhase = stdenv.lib.optionalString isPy3k ''
+  checkPhase = lib.optionalString isPy3k ''
     ${python.interpreter} -m lib2to3 -w test/test_demjson.py
   '' + ''
     ${python.interpreter} test/test_demjson.py
diff --git a/pkgs/development/python-modules/django-polymorphic/default.nix b/pkgs/development/python-modules/django-polymorphic/default.nix
index c08facd3650..b3b71231b75 100644
--- a/pkgs/development/python-modules/django-polymorphic/default.nix
+++ b/pkgs/development/python-modules/django-polymorphic/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, buildPythonPackage, fetchFromGitHub, python, django, dj-database-url }:
+{ lib, stdenv, buildPythonPackage, fetchFromGitHub, python, django, dj-database-url }:
 
 buildPythonPackage rec {
   pname = "django-polymorphic";
@@ -19,9 +19,9 @@ buildPythonPackage rec {
     ${python.interpreter} runtests.py
   '';
 
-  meta = {
+  meta = with lib; {
     homepage = "https://github.com/django-polymorphic/django-polymorphic";
     description = "Improved Django model inheritance with automatic downcasting";
-    license = stdenv.lib.licenses.bsd3;
+    license = licenses.bsd3;
   };
 }
diff --git a/pkgs/development/python-modules/django-raster/default.nix b/pkgs/development/python-modules/django-raster/default.nix
index a3aed647a33..173452ebe48 100644
--- a/pkgs/development/python-modules/django-raster/default.nix
+++ b/pkgs/development/python-modules/django-raster/default.nix
@@ -2,7 +2,7 @@
   numpy, django_colorful, pillow, psycopg2,
   pyparsing, django, celery, boto3, importlib-metadata
 }:
-if stdenv.lib.versionOlder django.version "2.0"
+if lib.versionOlder django.version "2.0"
 then throw "django-raster requires Django >= 2.0. Consider overiding the python package set to use django_2."
 else
 buildPythonPackage rec {
diff --git a/pkgs/development/python-modules/django/2.nix b/pkgs/development/python-modules/django/2.nix
index 641ec02aae0..eac48593de2 100644
--- a/pkgs/development/python-modules/django/2.nix
+++ b/pkgs/development/python-modules/django/2.nix
@@ -15,7 +15,7 @@ buildPythonPackage rec {
     sha256 = "cf5370a4d7765a9dd6d42a7b96b53c74f9446cd38209211304b210fe0404b861";
   };
 
-  patches = stdenv.lib.optional withGdal
+  patches = lib.optional withGdal
     (substituteAll {
       src = ./1.10-gis-libs.template.patch;
       geos = geos;
diff --git a/pkgs/development/python-modules/django/3.nix b/pkgs/development/python-modules/django/3.nix
index 2ea5b5a006c..2444146e837 100644
--- a/pkgs/development/python-modules/django/3.nix
+++ b/pkgs/development/python-modules/django/3.nix
@@ -22,7 +22,7 @@ buildPythonPackage rec {
     sha256 = "2d78425ba74c7a1a74b196058b261b9733a8570782f4e2828974777ccca7edf7";
   };
 
-  patches = stdenv.lib.optional withGdal
+  patches = lib.optional withGdal
     (substituteAll {
       src = ./django_3_set_geos_gdal_lib.patch;
       geos = geos;
diff --git a/pkgs/development/python-modules/dufte/default.nix b/pkgs/development/python-modules/dufte/default.nix
index 7836c8aa60a..d8435afa3f9 100644
--- a/pkgs/development/python-modules/dufte/default.nix
+++ b/pkgs/development/python-modules/dufte/default.nix
@@ -23,7 +23,7 @@ buildPythonPackage rec {
   propagatedBuildInputs = [
     matplotlib
     numpy
-  ] ++ stdenv.lib.optionals (pythonOlder "3.8") [
+  ] ++ lib.optionals (pythonOlder "3.8") [
     importlib-metadata
   ];
 
diff --git a/pkgs/development/python-modules/easydict/default.nix b/pkgs/development/python-modules/easydict/default.nix
index d8dbb045ddc..e1898d3fc9e 100644
--- a/pkgs/development/python-modules/easydict/default.nix
+++ b/pkgs/development/python-modules/easydict/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchPypi, buildPythonPackage }:
+{ lib, buildPythonPackage, fetchPypi }:
 
 buildPythonPackage rec {
   pname = "easydict";
@@ -11,9 +11,9 @@ buildPythonPackage rec {
 
   docheck = false; # No tests in archive
 
-  meta = {
+  meta = with lib; {
     homepage = "https://github.com/makinacorpus/easydict";
-    license = with stdenv.lib; licenses.lgpl3;
+    license = licenses.lgpl3;
     description = "Access dict values as attributes (works recursively)";
   };
 }
diff --git a/pkgs/development/python-modules/elasticsearch-dsl/default.nix b/pkgs/development/python-modules/elasticsearch-dsl/default.nix
index 44188902591..67e277b57ac 100644
--- a/pkgs/development/python-modules/elasticsearch-dsl/default.nix
+++ b/pkgs/development/python-modules/elasticsearch-dsl/default.nix
@@ -18,7 +18,7 @@ buildPythonPackage rec {
   };
 
   propagatedBuildInputs = [ elasticsearch python-dateutil six ]
-                          ++ stdenv.lib.optional (!isPy3k) ipaddress;
+                          ++ lib.optional (!isPy3k) ipaddress;
 
   # ImportError: No module named test_elasticsearch_dsl
   # Tests require a local instance of elasticsearch
diff --git a/pkgs/development/python-modules/enzyme/default.nix b/pkgs/development/python-modules/enzyme/default.nix
index 110575464cb..ee547ad9b7b 100644
--- a/pkgs/development/python-modules/enzyme/default.nix
+++ b/pkgs/development/python-modules/enzyme/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchPypi, buildPythonPackage }:
+{ lib, fetchPypi, buildPythonPackage }:
 
 buildPythonPackage rec {
   pname = "enzyme";
@@ -12,9 +12,9 @@ buildPythonPackage rec {
     sha256 = "1fv2kh2v4lwj0hhrhj9pib1pdjh01yr4xgyljhx11l94gjlpy5pj";
   };
 
-  meta = {
+  meta = with lib; {
     homepage = "https://github.com/Diaoul/enzyme";
-    license = with stdenv.lib; licenses.asl20;
+    license = licenses.asl20;
     description = "Python video metadata parser";
   };
 }
diff --git a/pkgs/development/python-modules/etebase/default.nix b/pkgs/development/python-modules/etebase/default.nix
index c0f9125a8d7..7832f6b4787 100644
--- a/pkgs/development/python-modules/etebase/default.nix
+++ b/pkgs/development/python-modules/etebase/default.nix
@@ -35,7 +35,7 @@ rustPlatform.buildRustPackage rec {
     wheel
   ];
 
-  buildInputs = stdenv.lib.optionals stdenv.isDarwin [ Security ];
+  buildInputs = lib.optionals stdenv.isDarwin [ Security ];
 
   propagatedBuildInputs = [
     python
diff --git a/pkgs/development/python-modules/fasteners/default.nix b/pkgs/development/python-modules/fasteners/default.nix
index b81ebb4faa0..57ad69c0be4 100644
--- a/pkgs/development/python-modules/fasteners/default.nix
+++ b/pkgs/development/python-modules/fasteners/default.nix
@@ -20,7 +20,7 @@ buildPythonPackage rec {
 
   propagatedBuildInputs = [ six monotonic ];
 
-  checkInputs = [ testtools nose ] ++ stdenv.lib.optionals (!isPy3k) [ futures ];
+  checkInputs = [ testtools nose ] ++ lib.optionals (!isPy3k) [ futures ];
 
   checkPhase = ''
     nosetests
diff --git a/pkgs/development/python-modules/fire/default.nix b/pkgs/development/python-modules/fire/default.nix
index 5a14f772546..6a2cc594360 100644
--- a/pkgs/development/python-modules/fire/default.nix
+++ b/pkgs/development/python-modules/fire/default.nix
@@ -12,7 +12,7 @@ buildPythonPackage rec {
     sha256 = "0s5r6l39ck2scks54hmwwdf4lcihqqnqzjfx9lz2b67vxkajpwmc";
   };
 
-  propagatedBuildInputs = [ six termcolor ] ++ stdenv.lib.optional isPy27 enum34;
+  propagatedBuildInputs = [ six termcolor ] ++ lib.optional isPy27 enum34;
 
   checkInputs = [ hypothesis mock python-Levenshtein pytest ];
 
diff --git a/pkgs/development/python-modules/flake8/default.nix b/pkgs/development/python-modules/flake8/default.nix
index 33459b7c66b..9e53ed28ff3 100644
--- a/pkgs/development/python-modules/flake8/default.nix
+++ b/pkgs/development/python-modules/flake8/default.nix
@@ -14,10 +14,10 @@ buildPythonPackage rec {
 
   checkInputs = [ pytest mock pytestrunner ];
   propagatedBuildInputs = [ pyflakes pycodestyle mccabe ]
-    ++ stdenv.lib.optionals (pythonOlder "3.2") [ configparser functools32 ]
-    ++ stdenv.lib.optionals (pythonOlder "3.4") [ enum34 ]
-    ++ stdenv.lib.optionals (pythonOlder "3.5") [ typing ]
-    ++ stdenv.lib.optionals (pythonOlder "3.8") [ importlib-metadata ];
+    ++ lib.optionals (pythonOlder "3.2") [ configparser functools32 ]
+    ++ lib.optionals (pythonOlder "3.4") [ enum34 ]
+    ++ lib.optionals (pythonOlder "3.5") [ typing ]
+    ++ lib.optionals (pythonOlder "3.8") [ importlib-metadata ];
 
   # fixtures fail to initialize correctly
   checkPhase = ''
diff --git a/pkgs/development/python-modules/flask-migrate/default.nix b/pkgs/development/python-modules/flask-migrate/default.nix
index 24ed04437a0..4d50ade30e1 100644
--- a/pkgs/development/python-modules/flask-migrate/default.nix
+++ b/pkgs/development/python-modules/flask-migrate/default.nix
@@ -1,6 +1,4 @@
-{ stdenv, buildPythonPackage, fetchPypi, isPy3k, glibcLocales, flask, flask_sqlalchemy, flask_script, alembic }:
-
-with stdenv.lib;
+{ lib, buildPythonPackage, fetchPypi, isPy3k, glibcLocales, flask, flask_sqlalchemy, flask_script, alembic }:
 
 buildPythonPackage rec {
   pname = "Flask-Migrate";
@@ -11,15 +9,15 @@ buildPythonPackage rec {
     sha256 = "a69d508c2e09d289f6e55a417b3b8c7bfe70e640f53d2d9deb0d056a384f37ee";
   };
 
-  checkInputs = [ flask_script ] ++ optional isPy3k glibcLocales;
+  checkInputs = [ flask_script ] ++ lib.optional isPy3k glibcLocales;
   propagatedBuildInputs = [ flask flask_sqlalchemy alembic ];
 
   # tests invoke the flask cli which uses click and therefore has py3k encoding troubles
-  preCheck = optionalString isPy3k ''
+  preCheck = lib.optionalString isPy3k ''
     export LANG="en_US.UTF-8"
   '';
 
-  meta = {
+  meta = with lib; {
     description = "SQLAlchemy database migrations for Flask applications using Alembic";
     license = licenses.mit;
     homepage = "https://github.com/miguelgrinberg/Flask-Migrate";
diff --git a/pkgs/development/python-modules/flask-testing/default.nix b/pkgs/development/python-modules/flask-testing/default.nix
index 9f4d66335de..6cfcffdb7be 100644
--- a/pkgs/development/python-modules/flask-testing/default.nix
+++ b/pkgs/development/python-modules/flask-testing/default.nix
@@ -15,7 +15,7 @@ buildPythonPackage rec {
 
   propagatedBuildInputs = [ flask ];
 
-  checkInputs = [ blinker ] ++ stdenv.lib.optionals (!isPy3k) [ twill ];
+  checkInputs = [ blinker ] ++ lib.optionals (!isPy3k) [ twill ];
 
   # twill integration is outdated in Python 2, hence it the tests fails.
   # Some of the tests use localhost networking on darwin.
diff --git a/pkgs/development/python-modules/flatbuffers/default.nix b/pkgs/development/python-modules/flatbuffers/default.nix
index d06ea28b334..f697f7b8ae0 100644
--- a/pkgs/development/python-modules/flatbuffers/default.nix
+++ b/pkgs/development/python-modules/flatbuffers/default.nix
@@ -1,4 +1,4 @@
-{ stdenv
+{ lib
 , buildPythonPackage
 , flatbuffers
 }:
@@ -16,6 +16,6 @@ buildPythonPackage rec {
 
   meta = flatbuffers.meta // {
     description = "Python runtime library for use with the Flatbuffers serialization format";
-    maintainers = with stdenv.lib.maintainers; [ wulfsta ];
+    maintainers = with lib.maintainers; [ wulfsta ];
   };
 }
diff --git a/pkgs/development/python-modules/funcsigs/default.nix b/pkgs/development/python-modules/funcsigs/default.nix
index aaa49254ecc..1464baa57df 100644
--- a/pkgs/development/python-modules/funcsigs/default.nix
+++ b/pkgs/development/python-modules/funcsigs/default.nix
@@ -14,7 +14,7 @@ buildPythonPackage rec {
   buildInputs = [ unittest2 ];
 
   # https://github.com/testing-cabal/funcsigs/issues/10
-  patches = stdenv.lib.optional (isPyPy && isPy3k) [ ./fix-pypy3-tests.patch ];
+  patches = lib.optional (isPyPy && isPy3k) [ ./fix-pypy3-tests.patch ];
 
   meta = with lib; {
     description = "Python function signatures from PEP362 for Python 2.6, 2.7 and 3.2+";
diff --git a/pkgs/development/python-modules/gevent/default.nix b/pkgs/development/python-modules/gevent/default.nix
index ba80a928f25..0fcf6cdfaaa 100644
--- a/pkgs/development/python-modules/gevent/default.nix
+++ b/pkgs/development/python-modules/gevent/default.nix
@@ -15,7 +15,7 @@ buildPythonPackage rec {
   buildInputs = [ libev ];
   propagatedBuildInputs = [
     zope_interface
-  ] ++ stdenv.lib.optionals (!isPyPy) [ greenlet ];
+  ] ++ lib.optionals (!isPyPy) [ greenlet ];
 
   checkPhase = ''
     cd greentest
diff --git a/pkgs/development/python-modules/glymur/default.nix b/pkgs/development/python-modules/glymur/default.nix
index f8a0e463238..50ed257f57e 100644
--- a/pkgs/development/python-modules/glymur/default.nix
+++ b/pkgs/development/python-modules/glymur/default.nix
@@ -26,7 +26,7 @@ buildPythonPackage rec {
 
   propagatedBuildInputs = [
     numpy
-  ] ++ stdenv.lib.optional isPy27 [ contextlib2 mock importlib-resources ];
+  ] ++ lib.optional isPy27 [ contextlib2 mock importlib-resources ];
 
   checkInputs = [
     scikitimage
diff --git a/pkgs/development/python-modules/goocalendar/default.nix b/pkgs/development/python-modules/goocalendar/default.nix
index 85744d29593..b0eea600384 100644
--- a/pkgs/development/python-modules/goocalendar/default.nix
+++ b/pkgs/development/python-modules/goocalendar/default.nix
@@ -1,4 +1,4 @@
-{ lib, stdenv
+{ lib
 , fetchPypi
 , buildPythonPackage
 , pkg-config
@@ -10,8 +10,6 @@
 , isPy3k
  }:
 
-with stdenv.lib;
-
 buildPythonPackage rec {
   pname = "GooCalendar";
   version = "0.7.1";
diff --git a/pkgs/development/python-modules/grpcio/default.nix b/pkgs/development/python-modules/grpcio/default.nix
index 6288828cd1b..1b1ffb975fb 100644
--- a/pkgs/development/python-modules/grpcio/default.nix
+++ b/pkgs/development/python-modules/grpcio/default.nix
@@ -21,13 +21,13 @@ buildPythonPackage rec {
   outputs = [ "out" "dev" ];
 
   nativeBuildInputs = [ cython pkg-config ]
-    ++ stdenv.lib.optional stdenv.isDarwin darwin.cctools;
+    ++ lib.optional stdenv.isDarwin darwin.cctools;
 
   buildInputs = [ c-ares openssl zlib ];
   propagatedBuildInputs = [ six protobuf ]
-    ++ stdenv.lib.optionals (isPy27) [ enum34 futures ];
+    ++ lib.optionals (isPy27) [ enum34 futures ];
 
-  preBuild = stdenv.lib.optionalString stdenv.isDarwin "unset AR";
+  preBuild = lib.optionalString stdenv.isDarwin "unset AR";
 
   GRPC_BUILD_WITH_BORING_SSL_ASM = "";
   GRPC_PYTHON_BUILD_SYSTEM_OPENSSL = 1;
diff --git a/pkgs/development/python-modules/gst-python/default.nix b/pkgs/development/python-modules/gst-python/default.nix
index 30c26b19c08..9ff8434cc9a 100644
--- a/pkgs/development/python-modules/gst-python/default.nix
+++ b/pkgs/development/python-modules/gst-python/default.nix
@@ -1,4 +1,5 @@
-{ buildPythonPackage
+{ lib
+, buildPythonPackage
 , fetchurl
 , meson
 , ninja
@@ -51,11 +52,9 @@ buildPythonPackage rec {
   # https://github.com/NixOS/nixpkgs/issues/47390
   installCheckPhase = "meson test --print-errorlogs";
 
-  meta = {
+  meta = with lib; {
     homepage = "https://gstreamer.freedesktop.org";
-
     description = "Python bindings for GStreamer";
-
-    license = stdenv.lib.licenses.lgpl2Plus;
+    license = licenses.lgpl2Plus;
   };
 }
diff --git a/pkgs/development/python-modules/gumath/default.nix b/pkgs/development/python-modules/gumath/default.nix
index ccf1627d7f3..601aecdf331 100644
--- a/pkgs/development/python-modules/gumath/default.nix
+++ b/pkgs/development/python-modules/gumath/default.nix
@@ -1,4 +1,5 @@
-{ stdenv
+{ lib
+, stdenv
 , buildPythonPackage
 , python
 , numba
@@ -28,7 +29,7 @@ buildPythonPackage {
                 'add_runtime_library_dirs = ["${libndtypes}/lib", "${libxnd}/lib", "${libgumath}/lib"]'
   '';
 
-  postInstall = stdenv.lib.optionalString stdenv.isDarwin ''
+  postInstall = lib.optionalString stdenv.isDarwin ''
     install_name_tool -add_rpath ${libgumath}/lib $out/${python.sitePackages}/gumath/_gumath.*.so
   '';
 
diff --git a/pkgs/development/python-modules/gyp/default.nix b/pkgs/development/python-modules/gyp/default.nix
index b08814d4bd1..5be56c81257 100644
--- a/pkgs/development/python-modules/gyp/default.nix
+++ b/pkgs/development/python-modules/gyp/default.nix
@@ -14,7 +14,7 @@ buildPythonPackage {
     sha256 = "0r9phq5yrmj968vdvy9vivli35wn1j9a6iwshp69wl7q4p0x8q2b";
   };
 
-  patches = stdenv.lib.optionals stdenv.isDarwin [
+  patches = lib.optionals stdenv.isDarwin [
     ./no-darwin-cflags.patch
     ./no-xcode.patch
   ];
diff --git a/pkgs/development/python-modules/h5py/default.nix b/pkgs/development/python-modules/h5py/default.nix
index a9ebdc5dfe8..c167e2115c6 100644
--- a/pkgs/development/python-modules/h5py/default.nix
+++ b/pkgs/development/python-modules/h5py/default.nix
@@ -1,11 +1,9 @@
-{ stdenv, fetchPypi, isPy27, python, buildPythonPackage, pythonOlder
+{ lib, fetchPypi, isPy27, python, buildPythonPackage, pythonOlder
 , numpy, hdf5, cython, six, pkgconfig, unittest2, fetchpatch
 , mpi4py ? null, openssh, pytestCheckHook, cached-property }:
 
 assert hdf5.mpiSupport -> mpi4py != null && hdf5.mpi == mpi4py.mpi;
 
-with stdenv.lib;
-
 let
   mpi = hdf5.mpi;
   mpiSupport = hdf5.mpiSupport;
@@ -31,27 +29,26 @@ in buildPythonPackage rec {
   postConfigure = ''
     # Needed to run the tests reliably. See:
     # https://bitbucket.org/mpi4py/mpi4py/issues/87/multiple-test-errors-with-openmpi-30
-    ${optionalString mpiSupport "export OMPI_MCA_rmaps_base_oversubscribe=yes"}
+    ${lib.optionalString mpiSupport "export OMPI_MCA_rmaps_base_oversubscribe=yes"}
   '';
 
   preBuild = if mpiSupport then "export CC=${mpi}/bin/mpicc" else "";
 
   # tests now require pytest-mpi, which isn't available and difficult to package
   doCheck = false;
-  checkInputs = optional isPy27 unittest2 ++ [ pytestCheckHook openssh ];
+  checkInputs = lib.optional isPy27 unittest2 ++ [ pytestCheckHook openssh ];
   nativeBuildInputs = [ pkgconfig cython ];
   buildInputs = [ hdf5 ]
-    ++ optional mpiSupport mpi;
+    ++ lib.optional mpiSupport mpi;
   propagatedBuildInputs = [ numpy six]
-    ++ optionals mpiSupport [ mpi4py openssh ]
-    ++ optionals (pythonOlder "3.8") [ cached-property ];
+    ++ lib.optionals mpiSupport [ mpi4py openssh ]
+    ++ lib.optionals (pythonOlder "3.8") [ cached-property ];
 
   pythonImportsCheck = [ "h5py" ];
 
-  meta = {
-    description =
-      "Pythonic interface to the HDF5 binary data format";
+  meta = with lib; {
+    description = "Pythonic interface to the HDF5 binary data format";
     homepage = "http://www.h5py.org/";
-    license = stdenv.lib.licenses.bsd2;
+    license = licenses.bsd2;
   };
 }
diff --git a/pkgs/development/python-modules/hg-evolve/default.nix b/pkgs/development/python-modules/hg-evolve/default.nix
index bcc93ba10cb..38a770e879f 100644
--- a/pkgs/development/python-modules/hg-evolve/default.nix
+++ b/pkgs/development/python-modules/hg-evolve/default.nix
@@ -1,4 +1,4 @@
-{ lib, stdenv
+{ lib
 , buildPythonPackage
 , fetchPypi
 , isPy3k
@@ -19,6 +19,6 @@ buildPythonPackage rec {
     description = "Enables the “changeset evolution” feature of Mercurial core";
     homepage = "https://www.mercurial-scm.org/doc/evolution/";
     maintainers = with maintainers; [ xavierzwirtz ];
-    license = stdenv.lib.licenses.gpl2Plus;
+    license = licenses.gpl2Plus;
   };
 }
diff --git a/pkgs/development/python-modules/hg-git/default.nix b/pkgs/development/python-modules/hg-git/default.nix
index fd321493b09..1d8e1ec1e29 100644
--- a/pkgs/development/python-modules/hg-git/default.nix
+++ b/pkgs/development/python-modules/hg-git/default.nix
@@ -1,4 +1,4 @@
-{ lib, stdenv
+{ lib
 , buildPythonPackage
 , fetchPypi
 , dulwich
@@ -30,7 +30,7 @@ buildPythonPackage rec {
     description = "Push and pull from a Git server using Mercurial";
     homepage = "http://hg-git.github.com/";
     maintainers = with maintainers; [ koral ];
-    license = stdenv.lib.licenses.gpl2;
+    license = licenses.gpl2;
   };
 
 }
diff --git a/pkgs/development/python-modules/hidapi/default.nix b/pkgs/development/python-modules/hidapi/default.nix
index c5ee1c20839..790e7aa08fc 100644
--- a/pkgs/development/python-modules/hidapi/default.nix
+++ b/pkgs/development/python-modules/hidapi/default.nix
@@ -10,16 +10,16 @@ buildPythonPackage rec {
   };
 
   propagatedBuildInputs =
-    stdenv.lib.optionals stdenv.isLinux [ libusb1 udev ] ++
-    stdenv.lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ AppKit CoreFoundation IOKit ]) ++
+    lib.optionals stdenv.isLinux [ libusb1 udev ] ++
+    lib.optionals stdenv.isDarwin (with darwin.apple_sdk.frameworks; [ AppKit CoreFoundation IOKit ]) ++
     [ cython ];
 
   # Fix the USB backend library lookup
-  postPatch = stdenv.lib.optionalString stdenv.isLinux ''
+  postPatch = lib.optionalString stdenv.isLinux ''
     libusb=${libusb1.dev}/include/libusb-1.0
     test -d $libusb || { echo "ERROR: $libusb doesn't exist, please update/fix this build expression."; exit 1; }
     sed -i -e "s|/usr/include/libusb-1.0|$libusb|" setup.py
-  '' + stdenv.lib.optionalString stdenv.isDarwin ''
+  '' + lib.optionalString stdenv.isDarwin ''
     substituteInPlace setup.py --replace 'macos_sdk_path =' 'macos_sdk_path = "" #'
   '';
 
diff --git a/pkgs/development/python-modules/hoomd-blue/default.nix b/pkgs/development/python-modules/hoomd-blue/default.nix
index edb647a3fc6..f726340b7c8 100644
--- a/pkgs/development/python-modules/hoomd-blue/default.nix
+++ b/pkgs/development/python-modules/hoomd-blue/default.nix
@@ -29,9 +29,9 @@ stdenv.mkDerivation rec {
   };
 
   nativeBuildInputs = [ cmake pkgconfig ];
-  buildInputs = stdenv.lib.optionals withMPI [ mpi ];
+  buildInputs = lib.optionals withMPI [ mpi ];
   propagatedBuildInputs = [ python.pkgs.numpy ]
-   ++ stdenv.lib.optionals withMPI [ python.pkgs.mpi4py ];
+   ++ lib.optionals withMPI [ python.pkgs.mpi4py ];
 
   dontAddPrefix = true;
   cmakeFlags = [
diff --git a/pkgs/development/python-modules/htmlmin/default.nix b/pkgs/development/python-modules/htmlmin/default.nix
index ccbc157837c..e91aedc6cdb 100644
--- a/pkgs/development/python-modules/htmlmin/default.nix
+++ b/pkgs/development/python-modules/htmlmin/default.nix
@@ -1,4 +1,5 @@
-{ stdenv, buildPythonPackage, fetchPypi }:
+{ lib, buildPythonPackage, fetchPypi }:
+
 buildPythonPackage rec {
   pname = "htmlmin";
   version = "0.1.12";
@@ -10,10 +11,10 @@ buildPythonPackage rec {
   # Tests run fine in a normal source checkout, but not when being built by nix.
   doCheck = false;
 
-  meta = {
+  meta = with lib; {
     description = "A configurable HTML Minifier with safety features";
     homepage = "https://pypi.python.org/pypi/htmlmin";
-    license = stdenv.lib.licenses.bsd3;
+    license = licenses.bsd3;
     maintainers = [];
   };
 }
diff --git a/pkgs/development/python-modules/httpretty/0.nix b/pkgs/development/python-modules/httpretty/0.nix
index 436bbd97fd2..92ed5c6616e 100644
--- a/pkgs/development/python-modules/httpretty/0.nix
+++ b/pkgs/development/python-modules/httpretty/0.nix
@@ -1,4 +1,4 @@
-{ lib, stdenv
+{ lib
 , buildPythonPackage
 , fetchPypi
 , tornado
@@ -20,7 +20,7 @@ buildPythonPackage rec {
 
   # drop this for version > 0.9.7
   # Flaky tests: https://github.com/gabrielfalcao/HTTPretty/pull/394
-  doCheck = stdenv.lib.versionAtLeast version "0.9.8";
+  doCheck = lib.versionAtLeast version "0.9.8";
 
   src = fetchPypi {
     inherit pname version;
@@ -37,7 +37,7 @@ buildPythonPackage rec {
   __darwinAllowLocalNetworking = true;
 
   # Those flaky tests are failing intermittently on all platforms
-  NOSE_EXCLUDE = stdenv.lib.concatStringsSep "," [
+  NOSE_EXCLUDE = lib.concatStringsSep "," [
     "tests.functional.test_httplib2.test_callback_response"
     "tests.functional.test_requests.test_streaming_responses"
     "tests.functional.test_httplib2.test_callback_response"
diff --git a/pkgs/development/python-modules/httpretty/default.nix b/pkgs/development/python-modules/httpretty/default.nix
index 93cf6a0927f..8974672d0a9 100644
--- a/pkgs/development/python-modules/httpretty/default.nix
+++ b/pkgs/development/python-modules/httpretty/default.nix
@@ -1,4 +1,4 @@
-{ lib, stdenv
+{ lib
 , buildPythonPackage
 , fetchPypi
 , tornado
@@ -23,7 +23,7 @@ buildPythonPackage rec {
 
   # drop this for version > 0.9.7
   # Flaky tests: https://github.com/gabrielfalcao/HTTPretty/pull/394
-  doCheck = stdenv.lib.versionAtLeast version "0.9.8";
+  doCheck = lib.versionAtLeast version "0.9.8";
 
   src = fetchPypi {
     inherit pname version;
@@ -44,7 +44,7 @@ buildPythonPackage rec {
   __darwinAllowLocalNetworking = true;
 
   # Those flaky tests are failing intermittently on all platforms
-  NOSE_EXCLUDE = stdenv.lib.concatStringsSep "," [
+  NOSE_EXCLUDE = lib.concatStringsSep "," [
     "tests.functional.test_httplib2.test_callback_response"
     "tests.functional.test_requests.test_streaming_responses"
     "tests.functional.test_httplib2.test_callback_response"
diff --git a/pkgs/development/python-modules/hupper/default.nix b/pkgs/development/python-modules/hupper/default.nix
index b70202138d4..1fe5ab7153d 100644
--- a/pkgs/development/python-modules/hupper/default.nix
+++ b/pkgs/development/python-modules/hupper/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, buildPythonPackage, fetchPypi
+{ lib, stdenv, buildPythonPackage, fetchPypi
 , pytest, pytestcov, watchdog, mock
 }:
 
@@ -17,5 +17,5 @@ buildPythonPackage rec {
 
   # FIXME: watchdog dependency is disabled on Darwin because of #31865, which causes very silent
   # segfaults in the testsuite that end up failing the tests in a background thread (in myapp)
-  checkInputs = [ pytest pytestcov mock ] ++ stdenv.lib.optional (!stdenv.isDarwin) watchdog;
+  checkInputs = [ pytest pytestcov mock ] ++ lib.optional (!stdenv.isDarwin) watchdog;
 }
diff --git a/pkgs/development/python-modules/imageio/default.nix b/pkgs/development/python-modules/imageio/default.nix
index e63678a524a..71f7eae9c32 100644
--- a/pkgs/development/python-modules/imageio/default.nix
+++ b/pkgs/development/python-modules/imageio/default.nix
@@ -24,7 +24,7 @@ buildPythonPackage rec {
     inherit pname version;
   };
 
-  checkInputs = [ pytest psutil ] ++ stdenv.lib.optionals isPy3k [
+  checkInputs = [ pytest psutil ] ++ lib.optionals isPy3k [
     imageio-ffmpeg ffmpeg_3
     ];
   propagatedBuildInputs = [ numpy pillow ];
diff --git a/pkgs/development/python-modules/influxgraph/default.nix b/pkgs/development/python-modules/influxgraph/default.nix
index 982b3fb8db5..32374453375 100644
--- a/pkgs/development/python-modules/influxgraph/default.nix
+++ b/pkgs/development/python-modules/influxgraph/default.nix
@@ -11,7 +11,7 @@ buildPythonPackage rec {
     sha256 = "0l33sfwdh4bfprmzp2kx0d9098g6yxbnhyyx9qr3kzczpm0jg9vy";
   };
 
-  patchPhase = stdenv.lib.optionalString isPy3k ''
+  patchPhase = lib.optionalString isPy3k ''
     sed 's/python-memcached/python3-memcached/' \
       -i ./influxgraph.egg-info/requires.txt    \
       -i ./setup.py
diff --git a/pkgs/development/python-modules/ipython/5.nix b/pkgs/development/python-modules/ipython/5.nix
index 598e890bb1c..a75ceaa0b76 100644
--- a/pkgs/development/python-modules/ipython/5.nix
+++ b/pkgs/development/python-modules/ipython/5.nix
@@ -33,7 +33,7 @@ buildPythonPackage rec {
     sha256 = "4bac649857611baaaf76bc82c173aa542f7486446c335fe1a6c05d0d491c8906";
   };
 
-  prePatch = stdenv.lib.optionalString stdenv.isDarwin ''
+  prePatch = lib.optionalString stdenv.isDarwin ''
     substituteInPlace setup.py --replace "'gnureadline'" " "
   '';
 
diff --git a/pkgs/development/python-modules/johnnycanencrypt/default.nix b/pkgs/development/python-modules/johnnycanencrypt/default.nix
index 407bb44d8b2..f0ee4a6bd99 100644
--- a/pkgs/development/python-modules/johnnycanencrypt/default.nix
+++ b/pkgs/development/python-modules/johnnycanencrypt/default.nix
@@ -1,4 +1,5 @@
-{ stdenv
+{ lib
+, stdenv
 , rustPlatform
 , fetchFromGitHub
 , pipInstallHook
@@ -49,7 +50,7 @@ rustPlatform.buildRustPackage rec {
   buildInputs = [
     pcsclite
     nettle
-  ] ++ stdenv.lib.optionals stdenv.isDarwin [ PCSC ];
+  ] ++ lib.optionals stdenv.isDarwin [ PCSC ];
 
   # Needed b/c need to check AFTER python wheel is installed (using Rust Build, not buildPythonPackage)
   doCheck = false;
@@ -83,7 +84,7 @@ rustPlatform.buildRustPackage rec {
 
   pythonImportsCheck = [ "johnnycanencrypt" ];
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     homepage = "https://github.com/kushaldas/johnnycanencrypt";
     description = "Python module for OpenPGP written in Rust";
     license = licenses.gpl3Plus;
diff --git a/pkgs/development/python-modules/json-schema-for-humans/default.nix b/pkgs/development/python-modules/json-schema-for-humans/default.nix
index 2ab2b2f1874..4e762e456ce 100644
--- a/pkgs/development/python-modules/json-schema-for-humans/default.nix
+++ b/pkgs/development/python-modules/json-schema-for-humans/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, buildPythonPackage, fetchFromGitHub
+{ lib, buildPythonPackage, fetchFromGitHub
 , pbr, click, dataclasses-json, htmlmin, jinja2, markdown2, pygments, pytz, pyyaml, requests, pytestCheckHook, beautifulsoup4, tox
 }:
 
@@ -26,7 +26,7 @@ buildPythonPackage rec {
   checkInputs = [ pytestCheckHook beautifulsoup4 ];
   pytestFlagsArray = [ "--ignore tests/generate_test.py" ];
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     description = "Quickly generate HTML documentation from a JSON schema";
     homepage    = "https://github.com/coveooss/json-schema-for-humans";
     license     = licenses.asl20;
diff --git a/pkgs/development/python-modules/jsonpointer/default.nix b/pkgs/development/python-modules/jsonpointer/default.nix
index e2f22ec8638..e1eaaed6c17 100644
--- a/pkgs/development/python-modules/jsonpointer/default.nix
+++ b/pkgs/development/python-modules/jsonpointer/default.nix
@@ -1,4 +1,4 @@
-{ lib, stdenv
+{ lib
 , buildPythonPackage
 , fetchPypi
 }:
@@ -15,7 +15,7 @@ buildPythonPackage rec {
   meta = with lib; {
     description = "Resolve JSON Pointers in Python";
     homepage = "https://github.com/stefankoegl/python-json-pointer";
-    license = stdenv.lib.licenses.bsd2; # "Modified BSD license, says pypi"
+    license = licenses.bsd2; # "Modified BSD license, says pypi"
   };
 
 }
diff --git a/pkgs/development/python-modules/keyring/2.nix b/pkgs/development/python-modules/keyring/2.nix
index 1dc7eb0a8f9..ee3b42b9bb8 100644
--- a/pkgs/development/python-modules/keyring/2.nix
+++ b/pkgs/development/python-modules/keyring/2.nix
@@ -15,7 +15,7 @@ buildPythonPackage rec {
 
   checkInputs = [ pytest pytest-flake8 ];
 
-  propagatedBuildInputs = [ dbus-python entrypoints ] ++ stdenv.lib.optional stdenv.isLinux secretstorage;
+  propagatedBuildInputs = [ dbus-python entrypoints ] ++ lib.optional stdenv.isLinux secretstorage;
 
   doCheck = !stdenv.isDarwin;
 
diff --git a/pkgs/development/python-modules/keyrings-alt/default.nix b/pkgs/development/python-modules/keyrings-alt/default.nix
index 0b642d0d4f1..bc20ff4e374 100644
--- a/pkgs/development/python-modules/keyrings-alt/default.nix
+++ b/pkgs/development/python-modules/keyrings-alt/default.nix
@@ -20,7 +20,7 @@ buildPythonPackage rec {
   nativeBuildInputs = [ setuptools_scm toml ];
   propagatedBuildInputs = [ six ];
 
-  checkInputs = [ pytest keyring ] ++ stdenv.lib.optional (pythonOlder "3.3") backports_unittest-mock;
+  checkInputs = [ pytest keyring ] ++ lib.optional (pythonOlder "3.3") backports_unittest-mock;
 
   # heavily relies on importing tests from keyring package
   doCheck = false;
diff --git a/pkgs/development/python-modules/kiwisolver/1_1.nix b/pkgs/development/python-modules/kiwisolver/1_1.nix
index f4621c9c54d..0702e3518e0 100644
--- a/pkgs/development/python-modules/kiwisolver/1_1.nix
+++ b/pkgs/development/python-modules/kiwisolver/1_1.nix
@@ -14,7 +14,7 @@ buildPythonPackage rec {
     sha256 = "53eaed412477c836e1b9522c19858a8557d6e595077830146182225613b11a75";
   };
 
-  NIX_CFLAGS_COMPILE = stdenv.lib.optionalString stdenv.isDarwin "-I${libcxx}/include/c++/v1";
+  NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-I${libcxx}/include/c++/v1";
 
   # Does not include tests
   doCheck = false;
diff --git a/pkgs/development/python-modules/kiwisolver/default.nix b/pkgs/development/python-modules/kiwisolver/default.nix
index a24e7300538..d4d62787092 100644
--- a/pkgs/development/python-modules/kiwisolver/default.nix
+++ b/pkgs/development/python-modules/kiwisolver/default.nix
@@ -15,7 +15,7 @@ buildPythonPackage rec {
     sha256 = "950a199911a8d94683a6b10321f9345d5a3a8433ec58b217ace979e18f16e248";
   };
 
-  NIX_CFLAGS_COMPILE = stdenv.lib.optionalString stdenv.isDarwin "-I${libcxx}/include/c++/v1";
+  NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-I${libcxx}/include/c++/v1";
 
   nativeBuildInputs = [
     cppy
diff --git a/pkgs/development/python-modules/koji/default.nix b/pkgs/development/python-modules/koji/default.nix
index eac2ab59643..5f560be4e88 100644
--- a/pkgs/development/python-modules/koji/default.nix
+++ b/pkgs/development/python-modules/koji/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, buildPythonPackage, isPy3k, pycurl, six, rpm, dateutil }:
+{ lib, fetchurl, buildPythonPackage, isPy3k, pycurl, six, rpm, dateutil }:
 
 buildPythonPackage rec {
   pname = "koji";
@@ -23,10 +23,10 @@ buildPythonPackage rec {
     rm -rf $out/nix
   '';
 
-  meta = {
+  meta = with lib; {
     description = "An RPM-based build system";
     homepage = "https://pagure.io/koji";
-    license = stdenv.lib.licenses.lgpl21;
-    platforms = stdenv.lib.platforms.unix;
+    license = licenses.lgpl21;
+    platforms = platforms.unix;
   };
 }
diff --git a/pkgs/development/python-modules/latexcodec/default.nix b/pkgs/development/python-modules/latexcodec/default.nix
index 77b75193ca4..37ffe23b806 100644
--- a/pkgs/development/python-modules/latexcodec/default.nix
+++ b/pkgs/development/python-modules/latexcodec/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, buildPythonPackage, fetchPypi, six, pytest }:
+{ lib, buildPythonPackage, fetchPypi, six, pytest }:
 
 buildPythonPackage rec {
   pname = "latexcodec";
@@ -17,10 +17,10 @@ buildPythonPackage rec {
     pytest
   '';
 
-  meta = {
+  meta = with lib; {
     homepage = "https://github.com/mcmtroffaes/latexcodec";
     description = "Lexer and codec to work with LaTeX code in Python";
-    license = stdenv.lib.licenses.mit;
+    license = licenses.mit;
   };
 
 }
diff --git a/pkgs/development/python-modules/ledgerwallet/default.nix b/pkgs/development/python-modules/ledgerwallet/default.nix
index a95d8140e11..42bc0c39129 100644
--- a/pkgs/development/python-modules/ledgerwallet/default.nix
+++ b/pkgs/development/python-modules/ledgerwallet/default.nix
@@ -25,7 +25,7 @@ buildPythonPackage rec {
     sha256 = "0fb93h2wxm9as9rsywlgz2ng4wrlbjphn6mgbhj6nls2i86rrdxk";
   };
 
-  buildInputs = stdenv.lib.optionals stdenv.isDarwin [ AppKit ];
+  buildInputs = lib.optionals stdenv.isDarwin [ AppKit ];
   propagatedBuildInputs = [
     cryptography click construct ecdsa hidapi intelhex pillow protobuf requests tabulate
   ];
diff --git a/pkgs/development/python-modules/libevdev/default.nix b/pkgs/development/python-modules/libevdev/default.nix
index 227cabe0099..4a4ba489e0a 100644
--- a/pkgs/development/python-modules/libevdev/default.nix
+++ b/pkgs/development/python-modules/libevdev/default.nix
@@ -1,4 +1,4 @@
-{ lib, stdenv
+{ lib
 , buildPythonPackage
 , isPy27
 , fetchPypi
@@ -20,7 +20,7 @@ buildPythonPackage rec {
   patches = [
     (substituteAll {
       src = ./fix-paths.patch;
-      libevdev = stdenv.lib.getLib pkgs.libevdev;
+      libevdev = lib.getLib pkgs.libevdev;
     })
   ];
 
diff --git a/pkgs/development/python-modules/libgpuarray/default.nix b/pkgs/development/python-modules/libgpuarray/default.nix
index 80e560e4cce..567ad2cf489 100644
--- a/pkgs/development/python-modules/libgpuarray/default.nix
+++ b/pkgs/development/python-modules/libgpuarray/default.nix
@@ -48,7 +48,7 @@ buildPythonPackage rec {
 
   postFixup = ''
     rm $out/lib/libgpuarray-static.a
-  '' + stdenv.lib.optionalString (!stdenv.isDarwin) ''
+  '' + lib.optionalString (!stdenv.isDarwin) ''
     function fixRunPath {
       p=$(patchelf --print-rpath $1)
       patchelf --set-rpath "$p:$libraryPath" $1
diff --git a/pkgs/development/python-modules/lightgbm/default.nix b/pkgs/development/python-modules/lightgbm/default.nix
index d7157244b6a..62686234b6e 100644
--- a/pkgs/development/python-modules/lightgbm/default.nix
+++ b/pkgs/development/python-modules/lightgbm/default.nix
@@ -26,7 +26,7 @@ buildPythonPackage rec {
   # we never actually explicitly call the install command so this is the only way
   # to inject these options to it - however, openmp-library doesn't appear to have
   # any effect, so we have to inject it into NIX_LDFLAGS manually below
-  postPatch = stdenv.lib.optionalString stdenv.cc.isClang ''
+  postPatch = lib.optionalString stdenv.cc.isClang ''
     cat >> setup.cfg <<EOF
 
     [install]
@@ -44,7 +44,7 @@ buildPythonPackage rec {
 
   postConfigure = ''
     export HOME=$(mktemp -d)
-  '' + stdenv.lib.optionalString stdenv.cc.isClang ''
+  '' + lib.optionalString stdenv.cc.isClang ''
     export NIX_LDFLAGS="$NIX_LDFLAGS -L${llvmPackages.openmp}/lib -lomp"
   '';
 
diff --git a/pkgs/development/python-modules/linode-api/default.nix b/pkgs/development/python-modules/linode-api/default.nix
index 4689050ba6c..61624a64d66 100644
--- a/pkgs/development/python-modules/linode-api/default.nix
+++ b/pkgs/development/python-modules/linode-api/default.nix
@@ -15,9 +15,9 @@ buildPythonPackage rec {
   disabled = (pythonOlder "2.7");
 
   propagatedBuildInputs = [ requests future ]
-                             ++ stdenv.lib.optionals (pythonOlder "3.4") [ enum34 ];
+                             ++ lib.optionals (pythonOlder "3.4") [ enum34 ];
 
-  postPatch = (stdenv.lib.optionalString (!pythonOlder "3.4") ''
+  postPatch = (lib.optionalString (!pythonOlder "3.4") ''
     sed -i -e '/"enum34",/d' setup.py
   '');
 
diff --git a/pkgs/development/python-modules/livestreamer/default.nix b/pkgs/development/python-modules/livestreamer/default.nix
index 3583d469434..7ae9124bb82 100644
--- a/pkgs/development/python-modules/livestreamer/default.nix
+++ b/pkgs/development/python-modules/livestreamer/default.nix
@@ -22,7 +22,7 @@ buildPythonPackage rec {
   buildInputs = [ pkgs.makeWrapper ];
 
   propagatedBuildInputs = [ pkgs.rtmpdump pycrypto requests ]
-    ++ stdenv.lib.optionals isPy27 [ singledispatch futures ];
+    ++ lib.optionals isPy27 [ singledispatch futures ];
 
   postInstall = ''
     wrapProgram $out/bin/livestreamer --prefix PATH : ${pkgs.rtmpdump}/bin
diff --git a/pkgs/development/python-modules/llfuse/default.nix b/pkgs/development/python-modules/llfuse/default.nix
index 77ec8322d68..e615582a282 100644
--- a/pkgs/development/python-modules/llfuse/default.nix
+++ b/pkgs/development/python-modules/llfuse/default.nix
@@ -2,10 +2,6 @@
 , contextlib2, osxfuse
 }:
 
-let
-  inherit (stdenv.lib) optionals optionalString;
-in
-
 buildPythonPackage rec {
   pname = "llfuse";
   version = "1.3.8";
@@ -24,16 +20,18 @@ buildPythonPackage rec {
   ];
 
   nativeBuildInputs = [ pkg-config ];
+
   buildInputs =
-    optionals stdenv.isLinux [ fuse ]
-    ++ optionals stdenv.isDarwin [ osxfuse ];
+    lib.optionals stdenv.isLinux [ fuse ]
+    ++ lib.optionals stdenv.isDarwin [ osxfuse ];
+
   checkInputs = [ pytest which ] ++
-    optionals stdenv.isLinux [ attr ];
+    lib.optionals stdenv.isLinux [ attr ];
 
   propagatedBuildInputs = [ contextlib2 ];
 
   checkPhase = ''
-    py.test -k "not test_listdir" ${optionalString stdenv.isDarwin ''-m "not uses_fuse"''}
+    py.test -k "not test_listdir" ${lib.optionalString stdenv.isDarwin ''-m "not uses_fuse"''}
   '';
 
   meta = with lib; {
diff --git a/pkgs/development/python-modules/llvmlite/default.nix b/pkgs/development/python-modules/llvmlite/default.nix
index 7a7106a5eaa..02ee088782a 100644
--- a/pkgs/development/python-modules/llvmlite/default.nix
+++ b/pkgs/development/python-modules/llvmlite/default.nix
@@ -1,4 +1,5 @@
-{ stdenv
+{ lib
+, stdenv
 , fetchPypi
 , buildPythonPackage
 , python
@@ -21,7 +22,7 @@ buildPythonPackage rec {
   };
 
   nativeBuildInputs = [ llvm ];
-  propagatedBuildInputs = [ ] ++ stdenv.lib.optional (pythonOlder "3.4") enum34;
+  propagatedBuildInputs = [ ] ++ lib.optional (pythonOlder "3.4") enum34;
 
   # Disable static linking
   # https://github.com/numba/llvmlite/issues/93
@@ -38,14 +39,14 @@ buildPythonPackage rec {
     ${python.executable} runtests.py
   '';
 
-  __impureHostDeps = stdenv.lib.optionals stdenv.isDarwin [ "/usr/lib/libm.dylib" ];
+  __impureHostDeps = lib.optionals stdenv.isDarwin [ "/usr/lib/libm.dylib" ];
 
   passthru.llvm = llvm;
 
-  meta = {
+  meta = with lib; {
     description = "A lightweight LLVM python binding for writing JIT compilers";
     homepage = "http://llvmlite.pydata.org/";
-    license = stdenv.lib.licenses.bsd2;
-    maintainers = with stdenv.lib.maintainers; [ fridh ];
+    license = licenses.bsd2;
+    maintainers = with maintainers; [ fridh ];
   };
 }
diff --git a/pkgs/development/python-modules/loguru/default.nix b/pkgs/development/python-modules/loguru/default.nix
index da91d9eeddd..458d2ca5032 100644
--- a/pkgs/development/python-modules/loguru/default.nix
+++ b/pkgs/development/python-modules/loguru/default.nix
@@ -12,10 +12,10 @@ buildPythonPackage rec {
 
   checkInputs = [ pytestCheckHook colorama ];
 
-  pytestFlagsArray = stdenv.lib.optionals stdenv.isDarwin [ "--ignore=tests/test_multiprocessing.py" ];
+  pytestFlagsArray = lib.optionals stdenv.isDarwin [ "--ignore=tests/test_multiprocessing.py" ];
 
   disabledTests = [ "test_time_rotation_reopening" "test_file_buffering" ]
-    ++ stdenv.lib.optionals stdenv.isDarwin [ "test_rotation_and_retention" "test_rotation_and_retention_timed_file" "test_renaming" "test_await_complete_inheritance" ];
+    ++ lib.optionals stdenv.isDarwin [ "test_rotation_and_retention" "test_rotation_and_retention_timed_file" "test_renaming" "test_await_complete_inheritance" ];
 
   meta = with lib; {
     homepage = "https://github.com/Delgan/loguru";
diff --git a/pkgs/development/python-modules/maestral/default.nix b/pkgs/development/python-modules/maestral/default.nix
index b24ebbcc9eb..990545e4173 100644
--- a/pkgs/development/python-modules/maestral/default.nix
+++ b/pkgs/development/python-modules/maestral/default.nix
@@ -38,17 +38,17 @@ buildPythonPackage rec {
     sqlalchemy
     survey
     watchdog
-  ] ++ stdenv.lib.optionals (pythonOlder "3.8") [
+  ] ++ lib.optionals (pythonOlder "3.8") [
     importlib-metadata
-  ] ++ stdenv.lib.optionals (pythonOlder "3.9") [
+  ] ++ lib.optionals (pythonOlder "3.9") [
     importlib-resources
-  ] ++ stdenv.lib.optionals stdenv.isLinux [
+  ] ++ lib.optionals stdenv.isLinux [
     dbus-next
   ];
 
   makeWrapperArgs = [
     # Add the installed directories to the python path so the daemon can find them
-    "--prefix" "PYTHONPATH" ":" "${stdenv.lib.concatStringsSep ":" (map (p: p + "/lib/${python.libPrefix}/site-packages") (python.pkgs.requiredPythonModules propagatedBuildInputs))}"
+    "--prefix" "PYTHONPATH" ":" "${lib.concatStringsSep ":" (map (p: p + "/lib/${python.libPrefix}/site-packages") (python.pkgs.requiredPythonModules propagatedBuildInputs))}"
     "--prefix" "PYTHONPATH" ":" "$out/lib/${python.libPrefix}/site-packages"
   ];
 
diff --git a/pkgs/development/python-modules/magic-wormhole/default.nix b/pkgs/development/python-modules/magic-wormhole/default.nix
index c85c7e2307f..0d8b3a1ec07 100644
--- a/pkgs/development/python-modules/magic-wormhole/default.nix
+++ b/pkgs/development/python-modules/magic-wormhole/default.nix
@@ -34,7 +34,7 @@ buildPythonPackage rec {
   propagatedBuildInputs = [ spake2 pynacl six attrs twisted autobahn automat hkdf tqdm click humanize txtorcon ];
   checkInputs = [ mock magic-wormhole-transit-relay magic-wormhole-mailbox-server ];
 
-  postPatch = stdenv.lib.optionalString stdenv.isLinux ''
+  postPatch = lib.optionalString stdenv.isLinux ''
     sed -i -e "s|'ifconfig'|'${nettools}/bin/ifconfig'|" src/wormhole/ipaddrs.py
   '';
 
diff --git a/pkgs/development/python-modules/mailman-rss/default.nix b/pkgs/development/python-modules/mailman-rss/default.nix
index c47d300d850..84c97eb16e2 100644
--- a/pkgs/development/python-modules/mailman-rss/default.nix
+++ b/pkgs/development/python-modules/mailman-rss/default.nix
@@ -10,7 +10,7 @@ python3Packages.buildPythonApplication rec {
   };
 
   propagatedBuildInputs = with python3Packages; [ dateutil future requests beautifulsoup4 ]
-    ++ stdenv.lib.optional withTwitter python3Packages.twitter
+    ++ lib.optional withTwitter python3Packages.twitter
   ;
 
   # No tests in Pypi Tarball
diff --git a/pkgs/development/python-modules/markdownsuperscript/default.nix b/pkgs/development/python-modules/markdownsuperscript/default.nix
index 6c2e6ab1b63..94cfb637a15 100644
--- a/pkgs/development/python-modules/markdownsuperscript/default.nix
+++ b/pkgs/development/python-modules/markdownsuperscript/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, buildPythonPackage, fetchPypi, markdown,
+{ lib, buildPythonPackage, fetchPypi, markdown,
   pytest, pytestrunner, pytestcov, coverage }:
 
 buildPythonPackage rec {
@@ -22,10 +22,10 @@ buildPythonPackage rec {
 
   checkInputs = [ pytest pytestrunner pytestcov coverage ];
 
-  meta = {
+  meta = with lib; {
     description = "An extension to the Python Markdown package enabling superscript text";
     homepage = "https://github.com/jambonrose/markdown_superscript_extension";
-    license = stdenv.lib.licenses.bsd2;
+    license = licenses.bsd2;
     broken = true; # unmaintained in nixpkgs, barely maintained in pypi, added 2020-11-29
   };
 }
diff --git a/pkgs/development/python-modules/matplotlib/2.nix b/pkgs/development/python-modules/matplotlib/2.nix
index ed6ebb1af49..2c929d9a694 100644
--- a/pkgs/development/python-modules/matplotlib/2.nix
+++ b/pkgs/development/python-modules/matplotlib/2.nix
@@ -42,17 +42,17 @@ buildPythonPackage rec {
   nativeBuildInputs = [ pkg-config ];
 
   buildInputs = [ which sphinx ]
-    ++ stdenv.lib.optional enableGhostscript ghostscript
-    ++ stdenv.lib.optional stdenv.isDarwin [ Cocoa ];
+    ++ lib.optional enableGhostscript ghostscript
+    ++ lib.optional stdenv.isDarwin [ Cocoa ];
 
   propagatedBuildInputs =
     [ cycler dateutil nose numpy pyparsing tornado freetype kiwisolver
       libpng mock pytz ]
-    ++ stdenv.lib.optional (pythonOlder "3.3") backports_functools_lru_cache
-    ++ stdenv.lib.optionals enableGtk3 [ cairo pycairo gtk3 gobject-introspection pygobject3 ]
-    ++ stdenv.lib.optionals enableTk [ tcl tk tkinter libX11 ]
-    ++ stdenv.lib.optionals enableQt [ pyqt4 ]
-    ++ stdenv.lib.optionals python.isPy2 [ functools32 subprocess32 ];
+    ++ lib.optional (pythonOlder "3.3") backports_functools_lru_cache
+    ++ lib.optionals enableGtk3 [ cairo pycairo gtk3 gobject-introspection pygobject3 ]
+    ++ lib.optionals enableTk [ tcl tk tkinter libX11 ]
+    ++ lib.optionals enableQt [ pyqt4 ]
+    ++ lib.optionals python.isPy2 [ functools32 subprocess32 ];
 
   setup_cfg = ./setup.cfg;
   preBuild = ''
@@ -67,10 +67,9 @@ buildPythonPackage rec {
   # script.
   postPatch =
     let
-      inherit (stdenv.lib.strings) substring;
-      tcl_tk_cache = ''"${tk}/lib", "${tcl}/lib", "${substring 0 3 tk.version}"'';
+      tcl_tk_cache = ''"${tk}/lib", "${tcl}/lib", "${lib.strings.substring 0 3 tk.version}"'';
     in
-    stdenv.lib.optionalString enableTk
+    lib.optionalString enableTk
       "sed -i '/self.tcl_tk_cache = None/s|None|${tcl_tk_cache}|' setupext.py";
 
   # Matplotlib needs to be built against a specific version of freetype in
diff --git a/pkgs/development/python-modules/matplotlib/default.nix b/pkgs/development/python-modules/matplotlib/default.nix
index 11ea3251e0a..bf21422b772 100644
--- a/pkgs/development/python-modules/matplotlib/default.nix
+++ b/pkgs/development/python-modules/matplotlib/default.nix
@@ -35,15 +35,15 @@ buildPythonPackage rec {
   nativeBuildInputs = [ pkg-config ];
 
   buildInputs = [ which sphinx ]
-    ++ stdenv.lib.optional enableGhostscript ghostscript
-    ++ stdenv.lib.optional stdenv.isDarwin [ Cocoa ];
+    ++ lib.optional enableGhostscript ghostscript
+    ++ lib.optional stdenv.isDarwin [ Cocoa ];
 
   propagatedBuildInputs =
     [ cycler dateutil numpy pyparsing tornado freetype kiwisolver
       certifi libpng mock pytz pillow ]
-    ++ stdenv.lib.optionals enableGtk3 [ cairo pycairo gtk3 gobject-introspection pygobject3 ]
-    ++ stdenv.lib.optionals enableTk [ tcl tk tkinter libX11 ]
-    ++ stdenv.lib.optionals enableQt [ pyqt5 ];
+    ++ lib.optionals enableGtk3 [ cairo pycairo gtk3 gobject-introspection pygobject3 ]
+    ++ lib.optionals enableTk [ tcl tk tkinter libX11 ]
+    ++ lib.optionals enableQt [ pyqt5 ];
 
   setup_cfg = if stdenv.isDarwin then ./setup-darwin.cfg else ./setup.cfg;
   preBuild = ''
@@ -58,10 +58,9 @@ buildPythonPackage rec {
   # script.
   postPatch =
     let
-      inherit (stdenv.lib.strings) substring;
-      tcl_tk_cache = ''"${tk}/lib", "${tcl}/lib", "${substring 0 3 tk.version}"'';
+      tcl_tk_cache = ''"${tk}/lib", "${tcl}/lib", "${lib.strings.substring 0 3 tk.version}"'';
     in
-    stdenv.lib.optionalString enableTk
+    lib.optionalString enableTk
       "sed -i '/self.tcl_tk_cache = None/s|None|${tcl_tk_cache}|' setupext.py";
 
   # Matplotlib needs to be built against a specific version of freetype in
diff --git a/pkgs/development/python-modules/mezzanine/default.nix b/pkgs/development/python-modules/mezzanine/default.nix
index d27fd862045..86deecb5d4f 100644
--- a/pkgs/development/python-modules/mezzanine/default.nix
+++ b/pkgs/development/python-modules/mezzanine/default.nix
@@ -28,8 +28,8 @@ buildPythonPackage rec {
     sha256 = "42c7909953cc5aea91921b47d804b61e14893bf48a2a476ce49a96559a0fa1d3";
   };
 
-  disabled = isPyPy || stdenv.lib.versionOlder django.version "1.11"
-    || stdenv.lib.versionAtLeast django.version "2.0";
+  disabled = isPyPy || lib.versionOlder django.version "1.11"
+    || lib.versionAtLeast django.version "2.0";
 
   buildInputs = [ pyflakes pep8 ];
   propagatedBuildInputs = [ django django_contrib_comments filebrowser_safe grappelli_safe bleach tzlocal beautifulsoup4 requests requests_oauthlib future pillow chardet ];
diff --git a/pkgs/development/python-modules/mockito/default.nix b/pkgs/development/python-modules/mockito/default.nix
index 534d6674a8d..d7ca86b8ea3 100644
--- a/pkgs/development/python-modules/mockito/default.nix
+++ b/pkgs/development/python-modules/mockito/default.nix
@@ -9,7 +9,7 @@ buildPythonPackage rec {
     sha256 = "d6b3aca6cdb92bbd47e19ebdb1a0b84ef23ab874eae5c6d505323c8657257c06";
   };
 
-  propagatedBuildInputs = stdenv.lib.optionals (!isPy3k) [ funcsigs ];
+  propagatedBuildInputs = lib.optionals (!isPy3k) [ funcsigs ];
   checkInputs = [ pytest numpy ];
 
   # tests are no longer packaged in pypi tarball
diff --git a/pkgs/development/python-modules/modestmaps/default.nix b/pkgs/development/python-modules/modestmaps/default.nix
index 19316c26802..a7862ef5c67 100644
--- a/pkgs/development/python-modules/modestmaps/default.nix
+++ b/pkgs/development/python-modules/modestmaps/default.nix
@@ -20,7 +20,7 @@ buildPythonPackage rec {
   meta = with lib; {
     description = "A library for building interactive maps";
     homepage = "http://modestmaps.com";
-    license = stdenv.lib.licenses.bsd3;
+    license = licenses.bsd3;
   };
 
 }
diff --git a/pkgs/development/python-modules/monotonic/default.nix b/pkgs/development/python-modules/monotonic/default.nix
index 7dffd328442..e93bf206eda 100644
--- a/pkgs/development/python-modules/monotonic/default.nix
+++ b/pkgs/development/python-modules/monotonic/default.nix
@@ -12,9 +12,9 @@ buildPythonPackage rec {
     sha256 = "23953d55076df038541e648a53676fb24980f7a1be290cdda21300b3bc21dfb0";
   };
 
-  __propagatedImpureHostDeps = stdenv.lib.optional stdenv.isDarwin "/usr/lib/libc.dylib";
+  __propagatedImpureHostDeps = lib.optional stdenv.isDarwin "/usr/lib/libc.dylib";
 
-  patchPhase = stdenv.lib.optionalString stdenv.isLinux ''
+  patchPhase = lib.optionalString stdenv.isLinux ''
     substituteInPlace monotonic.py --replace \
       "ctypes.util.find_library('c')" "'${stdenv.glibc.out}/lib/libc.so.6'"
   '';
diff --git a/pkgs/development/python-modules/moviepy/default.nix b/pkgs/development/python-modules/moviepy/default.nix
index 13f8d5884cf..8bc984a5287 100644
--- a/pkgs/development/python-modules/moviepy/default.nix
+++ b/pkgs/development/python-modules/moviepy/default.nix
@@ -39,7 +39,7 @@ buildPythonPackage rec {
 
   propagatedBuildInputs = [
     numpy decorator imageio imageio-ffmpeg tqdm requests proglog
-  ] ++ (stdenv.lib.optionals advancedProcessing [
+  ] ++ (lib.optionals advancedProcessing [
     opencv3 scikitimage scikitlearn scipy matplotlib youtube-dl
   ]);
 
diff --git a/pkgs/development/python-modules/mpi4py/default.nix b/pkgs/development/python-modules/mpi4py/default.nix
index c16c4719a34..058133665f4 100644
--- a/pkgs/development/python-modules/mpi4py/default.nix
+++ b/pkgs/development/python-modules/mpi4py/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchPypi, python, buildPythonPackage, mpi, openssh }:
+{ lib, fetchPypi, python, buildPythonPackage, mpi, openssh }:
 
 buildPythonPackage rec {
   pname = "mpi4py";
@@ -43,10 +43,9 @@ buildPythonPackage rec {
 
   nativeBuildInputs = [ mpi openssh ];
 
-  meta = {
-    description =
-      "Python bindings for the Message Passing Interface standard";
+  meta = with lib; {
+    description = "Python bindings for the Message Passing Interface standard";
     homepage = "https://bitbucket.org/mpi4py/mpi4py/";
-    license = stdenv.lib.licenses.bsd3;
+    license = licenses.bsd3;
   };
 }
diff --git a/pkgs/development/python-modules/mxnet/default.nix b/pkgs/development/python-modules/mxnet/default.nix
index d32905e7e61..2ad3b9fd6df 100644
--- a/pkgs/development/python-modules/mxnet/default.nix
+++ b/pkgs/development/python-modules/mxnet/default.nix
@@ -1,4 +1,4 @@
-{ stdenv
+{ lib
 , buildPythonPackage
 , pkgs
 , requests
@@ -14,7 +14,7 @@ buildPythonPackage {
   buildInputs = [ pkgs.mxnet ];
   propagatedBuildInputs = [ requests numpy graphviz ];
 
-  LD_LIBRARY_PATH = stdenv.lib.makeLibraryPath [ pkgs.mxnet ];
+  LD_LIBRARY_PATH = lib.makeLibraryPath [ pkgs.mxnet ];
 
   doCheck = !isPy3k;
 
diff --git a/pkgs/development/python-modules/ndtypes/default.nix b/pkgs/development/python-modules/ndtypes/default.nix
index 0a6e5635a4f..75fc5373b4c 100644
--- a/pkgs/development/python-modules/ndtypes/default.nix
+++ b/pkgs/development/python-modules/ndtypes/default.nix
@@ -1,4 +1,5 @@
-{ stdenv
+{ lib
+, stdenv
 , buildPythonPackage
 , python
 , numpy
@@ -26,7 +27,7 @@ buildPythonPackage {
   postInstall = ''
     mkdir $out/include
     cp python/ndtypes/*.h $out/include
-  '' + stdenv.lib.optionalString stdenv.isDarwin ''
+  '' + lib.optionalString stdenv.isDarwin ''
     install_name_tool -add_rpath ${libndtypes}/lib $out/${python.sitePackages}/ndtypes/_ndtypes.*.so
   '';
 
diff --git a/pkgs/development/python-modules/netaddr/default.nix b/pkgs/development/python-modules/netaddr/default.nix
index d92673104a9..7f4aab9c371 100644
--- a/pkgs/development/python-modules/netaddr/default.nix
+++ b/pkgs/development/python-modules/netaddr/default.nix
@@ -18,7 +18,7 @@ buildPythonPackage rec {
 
   LC_ALL = "en_US.UTF-8";
 
-  propagatedBuildInputs = stdenv.lib.optionals (pythonOlder "3.7") [ importlib-resources ];
+  propagatedBuildInputs = lib.optionals (pythonOlder "3.7") [ importlib-resources ];
 
   checkInputs = [ glibcLocales pytestCheckHook ];
 
diff --git a/pkgs/development/python-modules/nipy/default.nix b/pkgs/development/python-modules/nipy/default.nix
index 719e07b617b..cb7871aed61 100644
--- a/pkgs/development/python-modules/nipy/default.nix
+++ b/pkgs/development/python-modules/nipy/default.nix
@@ -21,7 +21,7 @@ buildPythonPackage rec {
     sha256 = "1pn731nsczrx198i2gadffqmfbhviglrclv6xxwhnbv6w5hfs2yk";
   };
 
-  buildInputs = stdenv.lib.optional doCheck [ nose ];
+  buildInputs = lib.optional doCheck [ nose ];
   propagatedBuildInputs = [ matplotlib nibabel numpy scipy sympy ];
 
   checkPhase = ''    # wants to be run in a different directory
diff --git a/pkgs/development/python-modules/notify/default.nix b/pkgs/development/python-modules/notify/default.nix
index 5621f0b24af..1a60cf70d2d 100644
--- a/pkgs/development/python-modules/notify/default.nix
+++ b/pkgs/development/python-modules/notify/default.nix
@@ -15,7 +15,7 @@ stdenv.mkDerivation {
     sha256 = "1kh4spwgqxm534qlzzf2ijchckvs0pwjxl1irhicjmlg7mybnfvx";
   };
 
-  patches = stdenv.lib.singleton (fetchurl {
+  patches = lib.singleton (fetchurl {
     name = "libnotify07.patch";
     url = "https://src.fedoraproject.org/cgit/notify-python.git/plain/"
         + "libnotify07.patch?id2=289573d50ae4838a1658d573d2c9f4c75e86db0c";
diff --git a/pkgs/development/python-modules/nuitka/default.nix b/pkgs/development/python-modules/nuitka/default.nix
index 4056c8a440e..7c2125c7b77 100644
--- a/pkgs/development/python-modules/nuitka/default.nix
+++ b/pkgs/development/python-modules/nuitka/default.nix
@@ -26,7 +26,7 @@ in buildPythonPackage rec {
 
   postPatch = ''
     patchShebangs tests/run-tests
-  '' + stdenv.lib.optionalString stdenv.isLinux ''
+  '' + lib.optionalString stdenv.isLinux ''
     substituteInPlace nuitka/plugins/standard/ImplicitImports.py --replace 'locateDLL("uuid")' '"${pkgs.util-linux.out}/lib/libuuid.so"'
   '';
 
diff --git a/pkgs/development/python-modules/numba/default.nix b/pkgs/development/python-modules/numba/default.nix
index ad31b8e960c..aa08ead2d97 100644
--- a/pkgs/development/python-modules/numba/default.nix
+++ b/pkgs/development/python-modules/numba/default.nix
@@ -1,4 +1,5 @@
-{ stdenv
+{ lib
+, stdenv
 , pythonOlder
 , fetchPypi
 , python
@@ -23,10 +24,10 @@ buildPythonPackage rec {
     sha256 = "16bd59572114adbf5f600ea383880d7b2071ae45477e84a24994e089ea390768";
   };
 
-  NIX_CFLAGS_COMPILE = stdenv.lib.optionalString stdenv.isDarwin "-I${libcxx}/include/c++/v1";
+  NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-I${libcxx}/include/c++/v1";
 
   propagatedBuildInputs = [numpy llvmlite]
-    ++ stdenv.lib.optionals isPy27 [ funcsigs singledispatch];
+    ++ lib.optionals isPy27 [ funcsigs singledispatch];
 
   # Copy test script into $out and run the test suite.
   checkPhase = ''
@@ -35,10 +36,10 @@ buildPythonPackage rec {
   # ImportError: cannot import name '_typeconv'
   doCheck = false;
 
-  meta =  {
+  meta =  with lib; {
     homepage = "http://numba.pydata.org/";
-    license = stdenv.lib.licenses.bsd2;
+    license = licenses.bsd2;
     description = "Compiling Python code using LLVM";
-    maintainers = with stdenv.lib.maintainers; [ fridh ];
+    maintainers = with maintainers; [ fridh ];
   };
 }
diff --git a/pkgs/development/python-modules/omegaconf/default.nix b/pkgs/development/python-modules/omegaconf/default.nix
index 930a0367824..99b9cccc7de 100644
--- a/pkgs/development/python-modules/omegaconf/default.nix
+++ b/pkgs/development/python-modules/omegaconf/default.nix
@@ -14,7 +14,7 @@ buildPythonPackage rec {
 
   checkInputs = [ pytest ];
   buildInputs = [ pytestrunner ];
-  propagatedBuildInputs = [ pyyaml six ] ++ stdenv.lib.optional isPy27 pathlib2;
+  propagatedBuildInputs = [ pyyaml six ] ++ lib.optional isPy27 pathlib2;
 
   meta = with lib; {
     description = "A framework for configuring complex applications";
diff --git a/pkgs/development/python-modules/orderedmultidict/default.nix b/pkgs/development/python-modules/orderedmultidict/default.nix
index 7cb4871031b..1cd0f648bd3 100644
--- a/pkgs/development/python-modules/orderedmultidict/default.nix
+++ b/pkgs/development/python-modules/orderedmultidict/default.nix
@@ -12,7 +12,7 @@ buildPythonPackage rec {
   checkInputs = [ flake8 ];
 
   propagatedBuildInputs = [ six ]
-    ++ stdenv.lib.optionals (pythonOlder "3.8") [
+    ++ lib.optionals (pythonOlder "3.8") [
       importlib-metadata
     ];
 
diff --git a/pkgs/development/python-modules/oset/default.nix b/pkgs/development/python-modules/oset/default.nix
index aa435b403e8..5d8a5f741bd 100644
--- a/pkgs/development/python-modules/oset/default.nix
+++ b/pkgs/development/python-modules/oset/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, buildPythonPackage, fetchPypi }:
+{ lib, buildPythonPackage, fetchPypi }:
 
 buildPythonPackage rec {
   pname = "oset";
@@ -11,9 +11,9 @@ buildPythonPackage rec {
 
   doCheck = false;
 
-  meta = {
+  meta = with lib; {
     description = "Ordered set";
-    license = stdenv.lib.licenses.psfl;
+    license = licenses.psfl;
   };
 
 }
diff --git a/pkgs/development/python-modules/pamela/default.nix b/pkgs/development/python-modules/pamela/default.nix
index 40597c36b58..7fd62dae2cd 100644
--- a/pkgs/development/python-modules/pamela/default.nix
+++ b/pkgs/development/python-modules/pamela/default.nix
@@ -1,4 +1,4 @@
-{ lib, stdenv
+{ lib
 , buildPythonPackage
 , fetchPypi
 , pkgs
@@ -16,7 +16,7 @@ buildPythonPackage rec {
   postUnpack = ''
     substituteInPlace $sourceRoot/pamela.py --replace \
       'find_library("pam")' \
-      '"${stdenv.lib.getLib pkgs.pam}/lib/libpam.so"'
+      '"${lib.getLib pkgs.pam}/lib/libpam.so"'
   '';
 
   doCheck = false;
diff --git a/pkgs/development/python-modules/pandas/2.nix b/pkgs/development/python-modules/pandas/2.nix
index e4f65a94dc5..936a3db296e 100644
--- a/pkgs/development/python-modules/pandas/2.nix
+++ b/pkgs/development/python-modules/pandas/2.nix
@@ -1,6 +1,7 @@
 # Python 2 expression
 
-{ buildPythonPackage
+{ lib
+, buildPythonPackage
 , fetchPypi
 , python
 , stdenv
@@ -26,11 +27,7 @@
 , libcxx ? null
 }:
 
-let
-  inherit (stdenv.lib) optional optionals optionalString;
-  inherit (stdenv) isDarwin;
-
-in buildPythonPackage rec {
+buildPythonPackage rec {
   pname = "pandas";
   version = "0.24.2";
 
@@ -42,7 +39,7 @@ in buildPythonPackage rec {
   checkInputs = [ pytest glibcLocales moto hypothesis ];
 
   nativeBuildInputs = [ cython ];
-  buildInputs = optional isDarwin libcxx;
+  buildInputs = lib.optional stdenv.isDarwin libcxx;
   propagatedBuildInputs = [
     dateutil
     scipy
@@ -61,7 +58,7 @@ in buildPythonPackage rec {
 
   # For OSX, we need to add a dependency on libcxx, which provides
   # `complex.h` and other libraries that pandas depends on to build.
-  postPatch = optionalString isDarwin ''
+  postPatch = lib.optionalString stdenv.isDarwin ''
     cpp_sdk="${libcxx}/include/c++/v1";
     echo "Adding $cpp_sdk to the setup.py common_include variable"
     substituteInPlace setup.py \
@@ -70,7 +67,7 @@ in buildPythonPackage rec {
   '';
 
 
-  disabledTests = stdenv.lib.concatMapStringsSep " and " (s: "not " + s) ([
+  disabledTests = lib.concatMapStringsSep " and " (s: "not " + s) ([
     # since dateutil 0.6.0 the following fails: test_fallback_plural, test_ambiguous_flags, test_ambiguous_compat
     # was supposed to be solved by https://github.com/dateutil/dateutil/issues/321, but is not the case
     "test_fallback_plural"
@@ -86,7 +83,7 @@ in buildPythonPackage rec {
     "io"
     # KeyError Timestamp
     "test_to_excel"
-  ] ++ optionals isDarwin [
+  ] ++ lib.optionals stdenv.isDarwin [
     "test_locale"
     "test_clipboard"
   ]);
@@ -98,7 +95,7 @@ in buildPythonPackage rec {
   ''
   # TODO: Get locale and clipboard support working on darwin.
   #       Until then we disable the tests.
-  + optionalString isDarwin ''
+  + lib.optionalString stdenv.isDarwin ''
     # Fake the impure dependencies pbpaste and pbcopy
     echo "#!${runtimeShell}" > pbcopy
     echo "#!${runtimeShell}" > pbpaste
@@ -109,14 +106,14 @@ in buildPythonPackage rec {
     runHook postCheck
   '';
 
-  meta = {
+  meta = with lib; {
     # https://github.com/pandas-dev/pandas/issues/14866
     # pandas devs are no longer testing i686 so safer to assume it's broken
     broken = stdenv.isi686;
     homepage = "https://pandas.pydata.org/";
     description = "Python Data Analysis Library";
-    license = stdenv.lib.licenses.bsd3;
-    maintainers = with stdenv.lib.maintainers; [ raskin knedlsepp ];
-    platforms = stdenv.lib.platforms.unix;
+    license = licenses.bsd3;
+    maintainers = with maintainers; [ raskin knedlsepp ];
+    platforms = platforms.unix;
   };
 }
diff --git a/pkgs/development/python-modules/pandas/default.nix b/pkgs/development/python-modules/pandas/default.nix
index b9865fe628b..ab70a7782ad 100644
--- a/pkgs/development/python-modules/pandas/default.nix
+++ b/pkgs/development/python-modules/pandas/default.nix
@@ -27,11 +27,7 @@
 , libcxx ? null
 }:
 
-let
-  inherit (stdenv.lib) optional optionals optionalString;
-  inherit (stdenv) isDarwin;
-
-in buildPythonPackage rec {
+buildPythonPackage rec {
   pname = "pandas";
   version = "1.1.5";
 
@@ -41,7 +37,7 @@ in buildPythonPackage rec {
   };
 
   nativeBuildInputs = [ cython ];
-  buildInputs = optional isDarwin libcxx;
+  buildInputs = lib.optional stdenv.isDarwin libcxx;
   propagatedBuildInputs = [
     beautifulsoup4
     bottleneck
@@ -62,11 +58,11 @@ in buildPythonPackage rec {
 
   # doesn't work with -Werror,-Wunused-command-line-argument
   # https://github.com/NixOS/nixpkgs/issues/39687
-  hardeningDisable = optional stdenv.cc.isClang "strictoverflow";
+  hardeningDisable = lib.optional stdenv.cc.isClang "strictoverflow";
 
   # For OSX, we need to add a dependency on libcxx, which provides
   # `complex.h` and other libraries that pandas depends on to build.
-  postPatch = optionalString isDarwin ''
+  postPatch = lib.optionalString stdenv.isDarwin ''
     cpp_sdk="${libcxx}/include/c++/v1";
     echo "Adding $cpp_sdk to the setup.py common_include variable"
     substituteInPlace setup.py \
@@ -76,7 +72,7 @@ in buildPythonPackage rec {
 
   # Parallel Cythonization is broken in Python 3.8 on Darwin. Fixed in the next
   # release. https://github.com/pandas-dev/pandas/pull/30862
-  setupPyBuildFlags = optionals (!(isPy38 && isDarwin)) [
+  setupPyBuildFlags = lib.optionals (!(isPy38 && stdenv.isDarwin)) [
     # As suggested by
     # https://pandas.pydata.org/pandas-docs/stable/development/contributing.html#creating-a-python-environment
     "--parallel=$NIX_BUILD_CORES"
@@ -114,7 +110,7 @@ in buildPythonPackage rec {
     "test_constructor_with_embedded_frames"
     # tries to import compiled C extension locally
     "test_missing_required_dependency"
-  ] ++ optionals isDarwin [
+  ] ++ lib.optionals stdenv.isDarwin [
     "test_locale"
     "test_clipboard"
   ];
@@ -128,7 +124,7 @@ in buildPythonPackage rec {
   ''
   # TODO: Get locale and clipboard support working on darwin.
   #       Until then we disable the tests.
-  + optionalString isDarwin ''
+  + lib.optionalString stdenv.isDarwin ''
     # Fake the impure dependencies pbpaste and pbcopy
     echo "#!${runtimeShell}" > pbcopy
     echo "#!${runtimeShell}" > pbpaste
diff --git a/pkgs/development/python-modules/parse-type/default.nix b/pkgs/development/python-modules/parse-type/default.nix
index e787c65fc11..d338a351e54 100644
--- a/pkgs/development/python-modules/parse-type/default.nix
+++ b/pkgs/development/python-modules/parse-type/default.nix
@@ -14,7 +14,7 @@ buildPythonPackage rec {
   };
 
   checkInputs = [ pytest pytestrunner ];
-  propagatedBuildInputs = [ parse six ] ++ stdenv.lib.optional (pythonOlder "3.4") enum34;
+  propagatedBuildInputs = [ parse six ] ++ lib.optional (pythonOlder "3.4") enum34;
 
   checkPhase = ''
     py.test tests
diff --git a/pkgs/development/python-modules/pbr/default.nix b/pkgs/development/python-modules/pbr/default.nix
index bc7c6399473..6b204a946b3 100644
--- a/pkgs/development/python-modules/pbr/default.nix
+++ b/pkgs/development/python-modules/pbr/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, buildPythonPackage, fetchPypi }:
+{ lib, buildPythonPackage, fetchPypi }:
 
 buildPythonPackage rec {
   pname = "pbr";
@@ -12,9 +12,9 @@ buildPythonPackage rec {
   # circular dependencies with fixtures
   doCheck = false;
 
-  meta = {
+  meta = with lib; {
     homepage = "http://docs.openstack.org/developer/pbr/";
-    license = stdenv.lib.licenses.asl20;
+    license = licenses.asl20;
     description = "Python Build Reasonableness";
   };
 }
diff --git a/pkgs/development/python-modules/pecan/default.nix b/pkgs/development/python-modules/pecan/default.nix
index 7303a9b1504..ed0c89b7802 100644
--- a/pkgs/development/python-modules/pecan/default.nix
+++ b/pkgs/development/python-modules/pecan/default.nix
@@ -45,7 +45,7 @@ buildPythonPackage rec {
     mock
     sqlalchemy
     virtualenv
-  ] ++ stdenv.lib.optionals isPy27 [ Kajiki ];
+  ] ++ lib.optionals isPy27 [ Kajiki ];
 
   pytestFlagsArray = [
     "--pyargs pecan "
diff --git a/pkgs/development/python-modules/peewee/default.nix b/pkgs/development/python-modules/peewee/default.nix
index ee3d08a173c..6f5d8e26227 100644
--- a/pkgs/development/python-modules/peewee/default.nix
+++ b/pkgs/development/python-modules/peewee/default.nix
@@ -1,4 +1,6 @@
-{ stdenv, lib, buildPythonPackage, fetchFromGitHub
+{ lib
+, buildPythonPackage
+, fetchFromGitHub
 , sqlite
 , cython
 , apsw
@@ -40,7 +42,7 @@ buildPythonPackage rec {
 
   doCheck = withPostgres;
 
-  meta = with stdenv.lib;{
+  meta = with lib; {
     description = "a small, expressive orm";
     homepage    = "http://peewee-orm.com";
     license     = licenses.mit;
diff --git a/pkgs/development/python-modules/pgsanity/default.nix b/pkgs/development/python-modules/pgsanity/default.nix
index b95f461aa37..26e5eb2bd6a 100644
--- a/pkgs/development/python-modules/pgsanity/default.nix
+++ b/pkgs/development/python-modules/pgsanity/default.nix
@@ -1,4 +1,4 @@
-{ lib, stdenv
+{ lib
 , python
 , fetchPypi
 , buildPythonPackage
@@ -30,7 +30,7 @@ buildPythonPackage rec {
       run it through ecpg and
       let ecpg report on the syntax errors of the SQL.
     '';
-    license = stdenv.lib.licenses.mit;
+    license = licenses.mit;
     maintainers = with maintainers; [ nalbyuites ];
   };
 }
diff --git a/pkgs/development/python-modules/phonenumbers/default.nix b/pkgs/development/python-modules/phonenumbers/default.nix
index 62149a78866..354ca2796e1 100644
--- a/pkgs/development/python-modules/phonenumbers/default.nix
+++ b/pkgs/development/python-modules/phonenumbers/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchPypi, buildPythonPackage }:
+{ lib, buildPythonPackage, fetchPypi }:
 
 buildPythonPackage rec {
   pname = "phonenumbers";
@@ -9,10 +9,10 @@ buildPythonPackage rec {
     sha256 = "96d02120a3481e22d8a8eb5e4595ceec1930855749f6e4a06ef931881f59f562";
   };
 
-  meta = {
+  meta = with lib; {
     description = "Python version of Google's common library for parsing, formatting, storing and validating international phone numbers";
     homepage    = "https://github.com/daviddrysdale/python-phonenumbers";
-    license     = stdenv.lib.licenses.asl20;
-    maintainers = with stdenv.lib.maintainers; [ fadenb ];
+    license     = licenses.asl20;
+    maintainers = with maintainers; [ fadenb ];
   };
 }
diff --git a/pkgs/development/python-modules/pickleshare/default.nix b/pkgs/development/python-modules/pickleshare/default.nix
index 0171adc6bfc..2151e13b960 100644
--- a/pkgs/development/python-modules/pickleshare/default.nix
+++ b/pkgs/development/python-modules/pickleshare/default.nix
@@ -16,7 +16,7 @@ buildPythonPackage rec {
   };
 
   propagatedBuildInputs = [ pathpy ]
-    ++ stdenv.lib.optional (pythonOlder "3.4") pathlib2;
+    ++ lib.optional (pythonOlder "3.4") pathlib2;
 
   # No proper test suite
   doCheck = false;
diff --git a/pkgs/development/python-modules/pillow/6.nix b/pkgs/development/python-modules/pillow/6.nix
index ce28b19a013..0e3fabf1fbc 100644
--- a/pkgs/development/python-modules/pillow/6.nix
+++ b/pkgs/development/python-modules/pillow/6.nix
@@ -22,7 +22,7 @@ buildPythonPackage rec {
 
   checkPhase = ''
     runHook preCheck
-    python -m pytest -v -x -W always${stdenv.lib.optionalString stdenv.isDarwin " --deselect=Tests/test_file_icns.py::TestFileIcns::test_save --deselect=Tests/test_imagegrab.py::TestImageGrab::test_grab"}
+    python -m pytest -v -x -W always${lib.optionalString stdenv.isDarwin " --deselect=Tests/test_file_icns.py::TestFileIcns::test_save --deselect=Tests/test_imagegrab.py::TestImageGrab::test_grab"}
     runHook postCheck
   '';
 
@@ -32,7 +32,7 @@ buildPythonPackage rec {
 
   buildInputs = [
     freetype libjpeg openjpeg libimagequant zlib libtiff libwebp tcl lcms2 ]
-    ++ stdenv.lib.optionals (isPyPy) [ tk libX11 ];
+    ++ lib.optionals (isPyPy) [ tk libX11 ];
 
   # NOTE: we use LCMS_ROOT as WEBP root since there is not other setting for webp.
   # NOTE: The Pillow install script will, by default, add paths like /usr/lib
@@ -61,7 +61,7 @@ buildPythonPackage rec {
     export CFLAGS="-I${libwebp}/include"
   ''
   # Remove impurities
-  + stdenv.lib.optionalString stdenv.isDarwin ''
+  + lib.optionalString stdenv.isDarwin ''
     substituteInPlace setup.py \
       --replace '"/Library/Frameworks",' "" \
       --replace '"/System/Library/Frameworks"' ""
diff --git a/pkgs/development/python-modules/pillow/default.nix b/pkgs/development/python-modules/pillow/default.nix
index 1122d21b534..4084df19404 100644
--- a/pkgs/development/python-modules/pillow/default.nix
+++ b/pkgs/development/python-modules/pillow/default.nix
@@ -24,7 +24,7 @@ buildPythonPackage rec {
   '';
 
   # Disable darwin tests which require executables: `iconutil` and `screencapture`
-  disabledTests = stdenv.lib.optionals stdenv.isDarwin [ "test_save" "test_grab" "test_grabclipboard" ];
+  disabledTests = lib.optionals stdenv.isDarwin [ "test_save" "test_grab" "test_grabclipboard" ];
 
   propagatedBuildInputs = [ olefile ];
 
@@ -32,7 +32,7 @@ buildPythonPackage rec {
 
   buildInputs = [
     freetype libjpeg openjpeg libimagequant zlib libtiff libwebp tcl lcms2 ]
-    ++ stdenv.lib.optionals (isPyPy) [ tk libX11 ];
+    ++ lib.optionals (isPyPy) [ tk libX11 ];
 
   # NOTE: we use LCMS_ROOT as WEBP root since there is not other setting for webp.
   # NOTE: The Pillow install script will, by default, add paths like /usr/lib
@@ -61,7 +61,7 @@ buildPythonPackage rec {
     export CFLAGS="-I${libwebp}/include"
   ''
   # Remove impurities
-  + stdenv.lib.optionalString stdenv.isDarwin ''
+  + lib.optionalString stdenv.isDarwin ''
     substituteInPlace setup.py \
       --replace '"/Library/Frameworks",' "" \
       --replace '"/System/Library/Frameworks"' ""
diff --git a/pkgs/development/python-modules/pip-tools/default.nix b/pkgs/development/python-modules/pip-tools/default.nix
index 398ab8cd29b..4ea6f75932c 100644
--- a/pkgs/development/python-modules/pip-tools/default.nix
+++ b/pkgs/development/python-modules/pip-tools/default.nix
@@ -1,4 +1,4 @@
-{ lib, stdenv, fetchPypi, buildPythonPackage, pip, pytest, click, six
+{ lib, fetchPypi, buildPythonPackage, pip, pytest, click, six
 , setuptools_scm, git, glibcLocales, mock }:
 
 buildPythonPackage rec {
@@ -14,7 +14,7 @@ buildPythonPackage rec {
   checkInputs = [ pytest git glibcLocales mock ];
   propagatedBuildInputs = [ pip click six setuptools_scm ];
 
-  disabledTests = stdenv.lib.concatMapStringsSep " and " (s: "not " + s) [
+  disabledTests = lib.concatMapStringsSep " and " (s: "not " + s) [
     # Depend on network tests:
     "test_allow_unsafe_option" #paramaterized, but all fail
     "test_annotate_option" #paramaterized, but all fail
diff --git a/pkgs/development/python-modules/plyvel/default.nix b/pkgs/development/python-modules/plyvel/default.nix
index 0872a534760..d8537d68158 100644
--- a/pkgs/development/python-modules/plyvel/default.nix
+++ b/pkgs/development/python-modules/plyvel/default.nix
@@ -15,7 +15,7 @@ buildPythonPackage rec {
     sha256 = "a7a09033a0fd33ca47094e8bbe01714abfcf644f4b7a337d3970e91a2599e2c4";
   };
 
-  buildInputs = [ pkgs.leveldb ] ++ stdenv.lib.optional isPy3k pytest;
+  buildInputs = [ pkgs.leveldb ] ++ lib.optional isPy3k pytest;
 
   # no tests for python2
   doCheck = isPy3k;
diff --git a/pkgs/development/python-modules/protobuf/default.nix b/pkgs/development/python-modules/protobuf/default.nix
index 4925c3dfd02..e7bbdd6ccdf 100644
--- a/pkgs/development/python-modules/protobuf/default.nix
+++ b/pkgs/development/python-modules/protobuf/default.nix
@@ -1,4 +1,5 @@
 { buildPackages
+, lib
 , stdenv
 , fetchpatch
 , python
@@ -14,8 +15,6 @@
 , doCheck ? true
 }:
 
-with stdenv.lib;
-
 buildPythonPackage {
   inherit (protobuf) pname src version;
   inherit disabled;
@@ -23,18 +22,18 @@ buildPythonPackage {
 
   NIX_CFLAGS_COMPILE = toString (
     # work around python distutils compiling C++ with $CC
-    optional stdenv.isDarwin "-I${libcxx}/include/c++/v1"
-    ++ optional (versionOlder protobuf.version "2.7.0") "-std=c++98"
+    lib.optional stdenv.isDarwin "-I${libcxx}/include/c++/v1"
+    ++ lib.optional (lib.versionOlder protobuf.version "2.7.0") "-std=c++98"
   );
 
   outputs = [ "out" "dev" ];
 
-  propagatedBuildInputs = [ six ] ++ optionals isPy27 [ google-apputils ];
+  propagatedBuildInputs = [ six ] ++ lib.optionals isPy27 [ google-apputils ];
   propagatedNativeBuildInputs = [ buildPackages.protobuf ]; # For protoc.
-  nativeBuildInputs = [ pyext ] ++ optionals isPy27 [ google-apputils ];
+  nativeBuildInputs = [ pyext ] ++ lib.optionals isPy27 [ google-apputils ];
   buildInputs = [ protobuf ];
 
-  patches = optional (isPy37 && (versionOlder protobuf.version "3.6.1.2"))
+  patches = lib.optional (isPy37 && (lib.versionOlder protobuf.version "3.6.1.2"))
     # Python 3.7 compatibility (not needed for protobuf >= 3.6.1.2)
     (fetchpatch {
       url = "https://github.com/protocolbuffers/protobuf/commit/0a59054c30e4f0ba10f10acfc1d7f3814c63e1a7.patch";
@@ -50,7 +49,7 @@ buildPythonPackage {
     cd python
   '';
 
-  preConfigure = optionalString (versionAtLeast protobuf.version "2.6.0") ''
+  preConfigure = lib.optionalString (lib.versionAtLeast protobuf.version "2.6.0") ''
     export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=cpp
     export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION_VERSION=2
   '';
@@ -58,21 +57,21 @@ buildPythonPackage {
   preBuild = ''
     # Workaround for https://github.com/google/protobuf/issues/2895
     ${python.pythonForBuild.interpreter} setup.py build
-  '' + optionalString (versionAtLeast protobuf.version "2.6.0") ''
+  '' + lib.optionalString (lib.versionAtLeast protobuf.version "2.6.0") ''
     ${python.pythonForBuild.interpreter} setup.py build_ext --cpp_implementation
   '';
 
-  installFlags = optional (versionAtLeast protobuf.version "2.6.0")
+  installFlags = lib.optional (lib.versionAtLeast protobuf.version "2.6.0")
     "--install-option='--cpp_implementation'";
 
   # the _message.so isn't installed, so we'll do that manually.
   # if someone can figure out a less hacky way to get the _message.so to
   # install, please do replace this.
-  postInstall = optionalString (versionAtLeast protobuf.version "2.6.0") ''
+  postInstall = lib.optionalString (lib.versionAtLeast protobuf.version "2.6.0") ''
     cp -v $(find build -name "_message*") $out/${python.sitePackages}/google/protobuf/pyext
   '';
 
-  meta = {
+  meta = with lib; {
     description = "Protocol Buffers are Google's data interchange format";
     homepage = "https://developers.google.com/protocol-buffers/";
     license = licenses.bsd3;
diff --git a/pkgs/development/python-modules/pulp/default.nix b/pkgs/development/python-modules/pulp/default.nix
index 480714e9e28..3e4c4b4b663 100644
--- a/pkgs/development/python-modules/pulp/default.nix
+++ b/pkgs/development/python-modules/pulp/default.nix
@@ -1,4 +1,4 @@
-{ lib, stdenv
+{ lib
 , fetchPypi
 , buildPythonPackage
 , pyparsing
diff --git a/pkgs/development/python-modules/pwntools/default.nix b/pkgs/development/python-modules/pwntools/default.nix
index 8f559edf41f..77f7859c6d4 100644
--- a/pkgs/development/python-modules/pwntools/default.nix
+++ b/pkgs/development/python-modules/pwntools/default.nix
@@ -62,7 +62,7 @@ buildPythonPackage rec {
 
   postFixup = ''
     mkdir -p "$out/bin"
-    makeWrapper "${debugger}/bin/${stdenv.lib.strings.getName debugger}" "$out/bin/pwntools-gdb"
+    makeWrapper "${debugger}/bin/${lib.strings.getName debugger}" "$out/bin/pwntools-gdb"
   '';
 
   meta = with lib; {
diff --git a/pkgs/development/python-modules/py3exiv2/default.nix b/pkgs/development/python-modules/py3exiv2/default.nix
index f9ed9acd0c8..0c2ae128827 100644
--- a/pkgs/development/python-modules/py3exiv2/default.nix
+++ b/pkgs/development/python-modules/py3exiv2/default.nix
@@ -1,4 +1,4 @@
-{ buildPythonPackage, isPy3k, fetchPypi, stdenv, exiv2, boost, libcxx, substituteAll, python }:
+{ lib, buildPythonPackage, isPy3k, fetchPypi, stdenv, exiv2, boost, libcxx, substituteAll, python }:
 
 buildPythonPackage rec {
   pname = "py3exiv2";
@@ -13,13 +13,13 @@ buildPythonPackage rec {
   buildInputs = [ exiv2 boost ];
 
   # work around python distutils compiling C++ with $CC (see issue #26709)
-  NIX_CFLAGS_COMPILE = stdenv.lib.optionalString stdenv.isDarwin "-I${libcxx}/include/c++/v1";
+  NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-I${libcxx}/include/c++/v1";
 
-  meta = {
+  meta = with lib; {
     homepage = "https://launchpad.net/py3exiv2";
     description = "A Python3 binding to the library exiv2";
-    license = with stdenv.lib.licenses; [ gpl3 ];
-    maintainers = with stdenv.lib.maintainers; [ vinymeuh ];
-    platforms = with stdenv.lib.platforms; linux ++ darwin;
+    license = licenses.gpl3;
+    maintainers = with maintainers; [ vinymeuh ];
+    platforms = with platforms; linux ++ darwin;
   };
 }
diff --git a/pkgs/development/python-modules/pyannotate/default.nix b/pkgs/development/python-modules/pyannotate/default.nix
index 4442d90ae71..9c9c18a886e 100644
--- a/pkgs/development/python-modules/pyannotate/default.nix
+++ b/pkgs/development/python-modules/pyannotate/default.nix
@@ -19,7 +19,7 @@ buildPythonPackage rec {
 
   checkInputs = [ pytest ];
   propagatedBuildInputs = [ six mypy-extensions ]
-    ++ stdenv.lib.optionals (pythonOlder "3.5") [ typing ];
+    ++ lib.optionals (pythonOlder "3.5") [ typing ];
 
   checkPhase = ''
     py.test
diff --git a/pkgs/development/python-modules/pyatspi/default.nix b/pkgs/development/python-modules/pyatspi/default.nix
index 5e96f642c28..5ae00417b6c 100644
--- a/pkgs/development/python-modules/pyatspi/default.nix
+++ b/pkgs/development/python-modules/pyatspi/default.nix
@@ -1,4 +1,4 @@
-{ lib, stdenv, fetchurl, pkg-config, buildPythonPackage, isPy3k, at-spi2-core, pygobject3, gnome3 }:
+{ lib, fetchurl, pkg-config, buildPythonPackage, isPy3k, at-spi2-core, pygobject3, gnome3 }:
 
 buildPythonPackage rec {
   pname = "pyatspi";
@@ -6,7 +6,7 @@ buildPythonPackage rec {
   format = "other";
 
   src = fetchurl {
-    url = "mirror://gnome/sources/${pname}/${stdenv.lib.versions.majorMinor version}/${pname}-${version}.tar.xz";
+    url = "mirror://gnome/sources/${pname}/${lib.versions.majorMinor version}/${pname}-${version}.tar.xz";
     sha256 = "/4CTEv0ML2HhkcGBoaY4owtXm5G2gs+1oFU1pVJltD0=";
   };
 
diff --git a/pkgs/development/python-modules/pybtex-docutils/default.nix b/pkgs/development/python-modules/pybtex-docutils/default.nix
index 8f3f32b20ac..2dbd4e8cff5 100644
--- a/pkgs/development/python-modules/pybtex-docutils/default.nix
+++ b/pkgs/development/python-modules/pybtex-docutils/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, buildPythonPackage, fetchPypi, docutils, pybtex, six }:
+{ lib, buildPythonPackage, fetchPypi, docutils, pybtex, six }:
 
 buildPythonPackage rec {
   version = "1.0.0";
@@ -12,9 +12,9 @@ buildPythonPackage rec {
     sha256 = "cead6554b4af99c287dd29f38b1fa152c9542f56a51cb6cbc3997c95b2725b2e";
   };
 
-  meta = {
+  meta = with lib; {
     description = "A docutils backend for pybtex";
     homepage = "https://github.com/mcmtroffaes/pybtex-docutils";
-    license = stdenv.lib.licenses.mit;
+    license = licenses.mit;
   };
 }
diff --git a/pkgs/development/python-modules/pybtex/default.nix b/pkgs/development/python-modules/pybtex/default.nix
index a62e7e27f9c..fb6fbf8dd38 100644
--- a/pkgs/development/python-modules/pybtex/default.nix
+++ b/pkgs/development/python-modules/pybtex/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, buildPythonPackage, fetchPypi, latexcodec, pyyaml }:
+{ lib, buildPythonPackage, fetchPypi, latexcodec, pyyaml }:
 
 buildPythonPackage rec {
   version = "0.23.0";
@@ -12,9 +12,9 @@ buildPythonPackage rec {
     sha256 = "b92be18ccd5e9a37895949dcf359a1f6890246b73646dddf1129178ee12e4bef";
   };
 
-  meta = {
+  meta = with lib; {
     homepage = "https://pybtex.org/";
     description = "A BibTeX-compatible bibliography processor written in Python";
-    license = stdenv.lib.licenses.mit;
+    license = licenses.mit;
   };
 }
diff --git a/pkgs/development/python-modules/pycassa/default.nix b/pkgs/development/python-modules/pycassa/default.nix
index d366486c8f8..0e07d8d436f 100644
--- a/pkgs/development/python-modules/pycassa/default.nix
+++ b/pkgs/development/python-modules/pycassa/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, buildPythonPackage, fetchPypi, thrift, isPy3k }:
+{ lib, buildPythonPackage, fetchPypi, thrift, isPy3k }:
 
 let
 
@@ -30,9 +30,9 @@ buildPythonPackage rec {
 
   propagatedBuildInputs = [ thrift' ];
 
-  meta = {
+  meta = with lib; {
     description = "A python client library for Apache Cassandra";
     homepage = "https://github.com/pycassa/pycassa";
-    license = stdenv.lib.licenses.mit;
+    license = licenses.mit;
   };
 }
diff --git a/pkgs/development/python-modules/pycdio/default.nix b/pkgs/development/python-modules/pycdio/default.nix
index b290d9ea959..712029b692c 100644
--- a/pkgs/development/python-modules/pycdio/default.nix
+++ b/pkgs/development/python-modules/pycdio/default.nix
@@ -28,7 +28,7 @@ buildPythonPackage rec {
 
   nativeBuildInputs = [ nose pkgs.pkgconfig pkgs.swig ];
   buildInputs = [ setuptools pkgs.libcdio ]
-    ++ stdenv.lib.optional stdenv.isDarwin pkgs.libiconv;
+    ++ lib.optional stdenv.isDarwin pkgs.libiconv;
 
   # Run tests using nosetests but first need to install the binaries
   # to the root source directory where they can be found.
diff --git a/pkgs/development/python-modules/pycryptodome/default.nix b/pkgs/development/python-modules/pycryptodome/default.nix
index 40084c2885e..e88b8529a35 100644
--- a/pkgs/development/python-modules/pycryptodome/default.nix
+++ b/pkgs/development/python-modules/pycryptodome/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchPypi, buildPythonPackage }:
+{ lib, fetchPypi, buildPythonPackage }:
 
 buildPythonPackage rec {
   version = "3.9.9";
@@ -9,9 +9,9 @@ buildPythonPackage rec {
     sha256 = "910e202a557e1131b1c1b3f17a63914d57aac55cf9fb9b51644962841c3995c4";
   };
 
-  meta = {
+  meta = with lib; {
     homepage = "https://www.pycryptodome.org/";
     description = "Python Cryptography Toolkit";
-    platforms = stdenv.lib.platforms.unix;
+    platforms = platforms.unix;
   };
 }
diff --git a/pkgs/development/python-modules/pycuda/default.nix b/pkgs/development/python-modules/pycuda/default.nix
index 368894228af..1db5df28e32 100644
--- a/pkgs/development/python-modules/pycuda/default.nix
+++ b/pkgs/development/python-modules/pycuda/default.nix
@@ -12,7 +12,7 @@
 , cudatoolkit
 , python
 , mkDerivation
-, lib, stdenv
+, lib
 }:
 let
   compyte = import ./compyte.nix {
@@ -28,7 +28,7 @@ buildPythonPackage rec {
     sha256 = "effa3b99b55af67f3afba9b0d1b64b4a0add4dd6a33bdd6786df1aa4cc8761a5";
   };
 
-  preConfigure = with stdenv.lib.versions; ''
+  preConfigure = with lib.versions; ''
     ${python.interpreter} configure.py --boost-inc-dir=${boost.dev}/include \
                           --boost-lib-dir=${boost}/lib \
                           --no-use-shipped-boost \
diff --git a/pkgs/development/python-modules/pydub/default.nix b/pkgs/development/python-modules/pydub/default.nix
index 13b99983198..884df63ce03 100644
--- a/pkgs/development/python-modules/pydub/default.nix
+++ b/pkgs/development/python-modules/pydub/default.nix
@@ -13,7 +13,7 @@ buildPythonPackage rec {
 
 
   # disable a test that fails on aarch64 due to rounding errors
-  postPatch = stdenv.lib.optionalString stdenv.isAarch64 ''
+  postPatch = lib.optionalString stdenv.isAarch64 ''
     substituteInPlace test/test.py \
       --replace "test_overlay_with_gain_change" "notest_overlay_with_gain_change"
   '';
diff --git a/pkgs/development/python-modules/pyee/default.nix b/pkgs/development/python-modules/pyee/default.nix
index 3c92dee783a..712db3e8712 100644
--- a/pkgs/development/python-modules/pyee/default.nix
+++ b/pkgs/development/python-modules/pyee/default.nix
@@ -21,7 +21,7 @@ buildPythonPackage rec {
     pytest-trio
     pytestrunner
     twisted
-  ] ++ stdenv.lib.optional isPy27 [
+  ] ++ lib.optional isPy27 [
     attrs
     futures
     pyparsing
diff --git a/pkgs/development/python-modules/pyexiv2/default.nix b/pkgs/development/python-modules/pyexiv2/default.nix
index cca8b552de1..bf7afdf79e2 100644
--- a/pkgs/development/python-modules/pyexiv2/default.nix
+++ b/pkgs/development/python-modules/pyexiv2/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, buildPythonPackage, fetchurl, python, exiv2, scons, boost }:
+{ lib, buildPythonPackage, fetchurl, python, exiv2, scons, boost }:
 
 buildPythonPackage rec {
   pname = "pyexiv2";
@@ -20,8 +20,8 @@ buildPythonPackage rec {
 
   buildInputs = [ python exiv2 scons boost ];
 
-  meta = {
-    platforms = stdenv.lib.platforms.linux;
+  meta = with lib; {
+    platforms = platforms.linux;
     # Likely needs an older boost which does not have `boost_pythonXY` but `boost_python`.
     broken = true; # 2018-06-23
   };
diff --git a/pkgs/development/python-modules/pyface/default.nix b/pkgs/development/python-modules/pyface/default.nix
index db118fbbd8c..d317ebdf21b 100644
--- a/pkgs/development/python-modules/pyface/default.nix
+++ b/pkgs/development/python-modules/pyface/default.nix
@@ -1,4 +1,4 @@
-{ lib, stdenv, fetchPypi, buildPythonPackage
+{ lib, fetchPypi, buildPythonPackage
 , setuptools, six, traits
 }:
 
@@ -18,7 +18,7 @@ buildPythonPackage rec {
   meta = with lib; {
     description = "Traits-capable windowing framework";
     homepage = "https://github.com/enthought/pyface";
-    maintainers = with stdenv.lib.maintainers; [ knedlsepp ];
+    maintainers = with maintainers; [ knedlsepp ];
     license = licenses.bsdOriginal;
   };
 }
diff --git a/pkgs/development/python-modules/pyfakefs/default.nix b/pkgs/development/python-modules/pyfakefs/default.nix
index 4deaa3eb268..64ec58487c4 100644
--- a/pkgs/development/python-modules/pyfakefs/default.nix
+++ b/pkgs/development/python-modules/pyfakefs/default.nix
@@ -19,7 +19,7 @@ buildPythonPackage rec {
       --replace "test_append_mode_tell_linux_windows" "notest_append_mode_tell_linux_windows"
     substituteInPlace pyfakefs/tests/fake_filesystem_unittest_test.py \
       --replace "test_copy_real_file" "notest_copy_real_file"
-  '' + (stdenv.lib.optionalString stdenv.isDarwin ''
+  '' + (lib.optionalString stdenv.isDarwin ''
     # this test fails on darwin due to case-insensitive file system
     substituteInPlace pyfakefs/tests/fake_os_test.py \
       --replace "test_rename_dir_to_existing_dir" "notest_rename_dir_to_existing_dir"
diff --git a/pkgs/development/python-modules/pyfribidi/default.nix b/pkgs/development/python-modules/pyfribidi/default.nix
index 17905b2bb39..dfe5449b282 100644
--- a/pkgs/development/python-modules/pyfribidi/default.nix
+++ b/pkgs/development/python-modules/pyfribidi/default.nix
@@ -1,4 +1,5 @@
-{ lib, stdenv
+{ lib
+, stdenv
 , buildPythonPackage
 , fetchPypi
 , isPyPy
@@ -16,14 +17,14 @@ buildPythonPackage rec {
     sha256 = "64726a4a56783acdc79c6b9b3a15f16e6071077c897a0b999f3b43f744bc621c";
   };
 
-  patches = stdenv.lib.optional stdenv.cc.isClang ./pyfribidi-clang.patch;
+  patches = lib.optional stdenv.cc.isClang ./pyfribidi-clang.patch;
 
   propagatedBuildInputs = [ six ];
 
   meta = with lib; {
     description = "A simple wrapper around fribidi";
     homepage = "https://github.com/pediapress/pyfribidi";
-    license = stdenv.lib.licenses.gpl2;
+    license = licenses.gpl2;
   };
 
 }
diff --git a/pkgs/development/python-modules/pygal/default.nix b/pkgs/development/python-modules/pygal/default.nix
index 733bfa15a4c..6855c9e4f02 100644
--- a/pkgs/development/python-modules/pygal/default.nix
+++ b/pkgs/development/python-modules/pygal/default.nix
@@ -55,7 +55,7 @@ buildPythonPackage rec {
   '';
 
   propagatedBuildInputs = [ cairosvg tinycss cssselect ]
-    ++ stdenv.lib.optionals (!isPyPy) [ lxml ];
+    ++ lib.optionals (!isPyPy) [ lxml ];
 
   meta = with lib; {
     description = "Sexy and simple python charting";
diff --git a/pkgs/development/python-modules/pygobject/3.36.nix b/pkgs/development/python-modules/pygobject/3.36.nix
index 1cbf264d1e2..ccad57eba1e 100644
--- a/pkgs/development/python-modules/pygobject/3.36.nix
+++ b/pkgs/development/python-modules/pygobject/3.36.nix
@@ -8,7 +8,7 @@ buildPythonPackage rec {
   format = "other";
 
   src = fetchurl {
-    url = "mirror://gnome/sources/${pname}/${stdenv.lib.versions.majorMinor version}/${pname}-${version}.tar.xz";
+    url = "mirror://gnome/sources/${pname}/${lib.versions.majorMinor version}/${pname}-${version}.tar.xz";
     sha256 = "0b9CgC0c7BE7Wtqg579/N0W0RSHcIWNYjSdtXNYdcY8=";
   };
 
@@ -20,7 +20,7 @@ buildPythonPackage rec {
 
   nativeBuildInputs = [ pkg-config meson ninja gobject-introspection ];
   buildInputs = [ glib gobject-introspection ]
-                 ++ stdenv.lib.optionals stdenv.isDarwin [ which ncurses ];
+                 ++ lib.optionals stdenv.isDarwin [ which ncurses ];
   propagatedBuildInputs = [ pycairo cairo ];
 
   passthru = {
diff --git a/pkgs/development/python-modules/pygobject/3.nix b/pkgs/development/python-modules/pygobject/3.nix
index b42a772ed73..8c26ec6174b 100644
--- a/pkgs/development/python-modules/pygobject/3.nix
+++ b/pkgs/development/python-modules/pygobject/3.nix
@@ -10,7 +10,7 @@ buildPythonPackage rec {
   format = "other";
 
   src = fetchurl {
-    url = "mirror://gnome/sources/${pname}/${stdenv.lib.versions.majorMinor version}/${pname}-${version}.tar.xz";
+    url = "mirror://gnome/sources/${pname}/${lib.versions.majorMinor version}/${pname}-${version}.tar.xz";
     sha256 = "A3LRu5Ei/Bn1AKJJsfOMK7Z0hQAPWIdJe0sgWz5whNU=";
   };
 
@@ -18,7 +18,7 @@ buildPythonPackage rec {
 
   nativeBuildInputs = [ pkg-config meson ninja gobject-introspection ];
   buildInputs = [ glib gobject-introspection ]
-                 ++ stdenv.lib.optionals stdenv.isDarwin [ which ncurses ];
+                 ++ lib.optionals stdenv.isDarwin [ which ncurses ];
   propagatedBuildInputs = [ pycairo cairo ];
 
   passthru = {
diff --git a/pkgs/development/python-modules/pygobject/default.nix b/pkgs/development/python-modules/pygobject/default.nix
index cf4f9d5cfbb..bf42d17b4de 100644
--- a/pkgs/development/python-modules/pygobject/default.nix
+++ b/pkgs/development/python-modules/pygobject/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, python, buildPythonPackage, pkg-config, glib, isPy3k, pythonAtLeast }:
+{ lib, stdenv, fetchurl, python, buildPythonPackage, pkg-config, glib, isPy3k, pythonAtLeast }:
 
 buildPythonPackage rec {
   pname = "pygobject";
@@ -13,7 +13,7 @@ buildPythonPackage rec {
 
   outputs = [ "out" "devdoc" ];
 
-  patches = stdenv.lib.optionals stdenv.isDarwin [
+  patches = lib.optionals stdenv.isDarwin [
     ./pygobject-2.0-fix-darwin.patch
   ];
 
@@ -26,7 +26,7 @@ buildPythonPackage rec {
   # same site-packages: we need a pth file for both. pygtk.py would be
   # used to select a specific version, in our setup it should have no
   # effect, but we leave it in case somebody expects and calls it.
-  postInstall = stdenv.lib.optionalString (!isPy3k) ''
+  postInstall = lib.optionalString (!isPy3k) ''
     mv $out/lib/${python.libPrefix}/site-packages/{pygtk.pth,${pname}-${version}.pth}
 
     # Prevent wrapping of codegen files as these are meant to be
@@ -34,9 +34,9 @@ buildPythonPackage rec {
     chmod a-x $out/share/pygobject/*/codegen/*.py
   '';
 
-  meta = {
+  meta = with lib; {
     homepage = "https://pygobject.readthedocs.io/";
     description = "Python bindings for GLib";
-    platforms = stdenv.lib.platforms.unix;
+    platforms = platforms.unix;
   };
 }
diff --git a/pkgs/development/python-modules/pygtk/default.nix b/pkgs/development/python-modules/pygtk/default.nix
index b3d84c21387..938b55630c0 100644
--- a/pkgs/development/python-modules/pygtk/default.nix
+++ b/pkgs/development/python-modules/pygtk/default.nix
@@ -8,7 +8,7 @@ buildPythonPackage rec {
   disabled = isPy3k;
 
   src = fetchurl {
-    url = "mirror://gnome/sources/${pname}/${stdenv.lib.versions.majorMinor version}/${pname}-${version}.tar.bz2";
+    url = "mirror://gnome/sources/${pname}/${lib.versions.majorMinor version}/${pname}-${version}.tar.bz2";
     sha256 = "04k942gn8vl95kwf0qskkv6npclfm31d78ljkrkgyqxxcni1w76d";
   };
 
@@ -27,7 +27,7 @@ buildPythonPackage rec {
   nativeBuildInputs = [ pkg-config ];
   buildInputs = [
     pango
-  ] ++ stdenv.lib.optional (libglade != null) libglade;
+  ] ++ lib.optional (libglade != null) libglade;
 
   propagatedBuildInputs = [ gtk2 pygobject2 pycairo ];
 
@@ -35,11 +35,11 @@ buildPythonPackage rec {
 
   buildPhase = "buildPhase";
 
-  NIX_CFLAGS_COMPILE = stdenv.lib.optionalString stdenv.isDarwin "-ObjC";
+  NIX_CFLAGS_COMPILE = lib.optionalString stdenv.isDarwin "-ObjC";
 
   installPhase = "installPhase";
 
-  checkPhase = stdenv.lib.optionalString (libglade == null)
+  checkPhase = lib.optionalString (libglade == null)
     ''
       sed -i -e "s/glade = importModule('gtk.glade', buildDir)//" \
              tests/common.py
diff --git a/pkgs/development/python-modules/pync/default.nix b/pkgs/development/python-modules/pync/default.nix
index 20811f2df9d..9506b8bae95 100644
--- a/pkgs/development/python-modules/pync/default.nix
+++ b/pkgs/development/python-modules/pync/default.nix
@@ -19,7 +19,7 @@ buildPythonPackage rec {
   buildInputs = [ pkgs.coreutils ];
   propagatedBuildInputs = [ dateutil ];
 
-  preInstall = stdenv.lib.optionalString stdenv.isDarwin ''
+  preInstall = lib.optionalString stdenv.isDarwin ''
     sed -i 's|^\([ ]*\)self.bin_path.*$|\1self.bin_path = "${pkgs.terminal-notifier}/bin/terminal-notifier"|' build/lib/pync/TerminalNotifier.py
   '';
 
diff --git a/pkgs/development/python-modules/pynput/default.nix b/pkgs/development/python-modules/pynput/default.nix
index 5f193a8ab35..49da01f8e71 100644
--- a/pkgs/development/python-modules/pynput/default.nix
+++ b/pkgs/development/python-modules/pynput/default.nix
@@ -12,7 +12,7 @@ buildPythonPackage rec {
   nativeBuildInputs = [ sphinx ];
 
   propagatedBuildInputs = [ setuptools-lint xlib ]
-  ++ stdenv.lib.optionals stdenv.isLinux [
+  ++ lib.optionals stdenv.isLinux [
     evdev
   ];
 
diff --git a/pkgs/development/python-modules/pyobjc/default.nix b/pkgs/development/python-modules/pyobjc/default.nix
index 9799cbaf0e8..4b27bea10bc 100644
--- a/pkgs/development/python-modules/pyobjc/default.nix
+++ b/pkgs/development/python-modules/pyobjc/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchPypi, isPy3k, buildPythonPackage }:
+{ lib, fetchPypi, isPy3k, buildPythonPackage }:
 
 buildPythonPackage rec {
   pname = "pyobjc";
@@ -13,10 +13,10 @@ buildPythonPackage rec {
     sha256 = "2b6c3e98f1408564ace1df36927154d7827c8e2f382386ab5d2db95c891e35a0";
   };
 
-  meta = {
+  meta = with lib; {
     description = "A bridge between the Python and Objective-C programming languages";
-    license = stdenv.lib.licenses.mit;
-    maintainers = with stdenv.lib.maintainers; [ ];
+    license = licenses.mit;
+    maintainers = with maintainers; [ ];
     homepage = "https://pythonhosted.org/pyobjc/";
   };
 }
diff --git a/pkgs/development/python-modules/pyopenssl/default.nix b/pkgs/development/python-modules/pyopenssl/default.nix
index 023e5f12fd4..c8b3bd4158c 100644
--- a/pkgs/development/python-modules/pyopenssl/default.nix
+++ b/pkgs/development/python-modules/pyopenssl/default.nix
@@ -1,4 +1,5 @@
-{ stdenv
+{ lib
+, stdenv
 , buildPythonPackage
 , fetchPypi
 , openssl
@@ -13,9 +14,6 @@
 , fetchpatch
 }:
 
-with stdenv.lib;
-
-
 let
   # https://github.com/pyca/pyopenssl/issues/791
   # These tests, we disable in the case that libressl is passed in as openssl.
@@ -51,21 +49,20 @@ let
     # https://github.com/pyca/pyopenssl/issues/768
     "test_wantWriteError"
   ] ++ (
-    optionals (hasPrefix "libressl" openssl.meta.name) failingLibresslTests
+    lib.optionals (lib.hasPrefix "libressl" openssl.meta.name) failingLibresslTests
   ) ++ (
-    optionals (versionAtLeast (getVersion openssl.name) "1.1") failingOpenSSL_1_1Tests
+    lib.optionals (lib.versionAtLeast (lib.getVersion openssl.name) "1.1") failingOpenSSL_1_1Tests
   ) ++ (
     # https://github.com/pyca/pyopenssl/issues/974
-    optionals stdenv.is32bit [ "test_verify_with_time" ]
+    lib.optionals stdenv.is32bit [ "test_verify_with_time" ]
   );
 
   # Compose the final string expression, including the "-k" and the single quotes.
-  testExpression = optionalString (disabledTests != [])
-    "-k 'not ${concatStringsSep " and not " disabledTests}'";
+  testExpression = lib.optionalString (disabledTests != [])
+    "-k 'not ${lib.concatStringsSep " and not " disabledTests}'";
 
 in
 
-
 buildPythonPackage rec {
   pname = "pyOpenSSL";
   version = "20.0.0";
diff --git a/pkgs/development/python-modules/pyparted/default.nix b/pkgs/development/python-modules/pyparted/default.nix
index b6768ad992d..f46a5d2db82 100644
--- a/pkgs/development/python-modules/pyparted/default.nix
+++ b/pkgs/development/python-modules/pyparted/default.nix
@@ -24,7 +24,7 @@ buildPythonPackage rec {
     sed -i -e '
       s|e\.path\.startswith("/tmp/temp-device-")|"temp-device-" in e.path|
     ' tests/test__ped_ped.py
-  '' + stdenv.lib.optionalString stdenv.isi686 ''
+  '' + lib.optionalString stdenv.isi686 ''
     # remove some integers in this test case which overflow on 32bit systems
     sed -i -r -e '/class *UnitGetSizeTestCase/,/^$/{/[0-9]{11}/d}' \
       tests/test__ped_ped.py
diff --git a/pkgs/development/python-modules/pypass/default.nix b/pkgs/development/python-modules/pypass/default.nix
index 2458a29ac31..f3e49452c89 100644
--- a/pkgs/development/python-modules/pypass/default.nix
+++ b/pkgs/development/python-modules/pypass/default.nix
@@ -1,4 +1,5 @@
-{ buildPythonPackage
+{ lib
+, buildPythonPackage
 , click
 , colorama
 , enum34
@@ -11,7 +12,6 @@
 , pexpect
 , pythonAtLeast
 , pythonOlder
-, stdenv
 , substituteAll
 , tree
 , xclip
@@ -43,7 +43,7 @@ buildPythonPackage rec {
   ];
 
   # Remove enum34 requirement if Python >= 3.4
-  postPatch = stdenv.lib.optionalString (pythonAtLeast "3.4") ''
+  postPatch = lib.optionalString (pythonAtLeast "3.4") ''
     substituteInPlace requirements.txt --replace "enum34" ""
   '';
 
@@ -53,7 +53,7 @@ buildPythonPackage rec {
     click
     colorama
     pexpect
-  ] ++ stdenv.lib.optional (pythonOlder "3.4") enum34;
+  ] ++ lib.optional (pythonOlder "3.4") enum34;
 
   checkInputs = [ nose ];
 
@@ -74,11 +74,11 @@ buildPythonPackage rec {
     runHook postCheck
   '';
 
-  meta = {
+  meta = with lib; {
     description = "Password manager pass in Python";
     homepage = "https://github.com/aviau/python-pass";
-    license = stdenv.lib.licenses.gpl3Plus;
-    platforms = stdenv.lib.platforms.all;
-    maintainers = with stdenv.lib.maintainers; [ jluttine ];
+    license = licenses.gpl3Plus;
+    platforms = platforms.all;
+    maintainers = with maintainers; [ jluttine ];
   };
 }
diff --git a/pkgs/development/python-modules/pyqt/4.x.nix b/pkgs/development/python-modules/pyqt/4.x.nix
index 54abcddd5d8..3427438b8a2 100644
--- a/pkgs/development/python-modules/pyqt/4.x.nix
+++ b/pkgs/development/python-modules/pyqt/4.x.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, buildPythonPackage, python, dbus-python, sip, qt4, pkg-config, lndir, dbus, makeWrapper }:
+{ lib, stdenv, fetchurl, buildPythonPackage, python, dbus-python, sip, qt4, pkg-config, lndir, dbus, makeWrapper }:
 
 buildPythonPackage rec {
   pname = "PyQt-x11-gpl";
@@ -16,13 +16,13 @@ buildPythonPackage rec {
     rm -rf "$out/nix-support"
 
     export PYTHONPATH=$PYTHONPATH:$out/lib/${python.libPrefix}/site-packages
-    ${stdenv.lib.optionalString stdenv.isDarwin ''
+    ${lib.optionalString stdenv.isDarwin ''
       export QMAKESPEC="unsupported/macx-clang-libc++" # macOS target after bootstrapping phase \
     ''}
 
     substituteInPlace configure.py \
       --replace 'install_dir=pydbusmoddir' "install_dir='$out/lib/${python.libPrefix}/site-packages/dbus/mainloop'" \
-    ${stdenv.lib.optionalString stdenv.isDarwin ''
+    ${lib.optionalString stdenv.isDarwin ''
       --replace "qt_macx_spec = 'macx-g++'" "qt_macx_spec = 'unsupported/macx-clang-libc++'" # for bootstrapping phase \
     ''}
 
@@ -38,7 +38,7 @@ buildPythonPackage rec {
     "--destdir=${placeholder "out"}/${python.sitePackages}"
     "--plugin-destdir=${placeholder "out"}/lib/qt4/plugins"
     "--sipdir=${placeholder "out"}/share/sip/PyQt4"
-    "--dbus=${stdenv.lib.getDev dbus-python}/include/dbus-1.0"
+    "--dbus=${lib.getDev dbus-python}/include/dbus-1.0"
     "--verbose"
   ];
 
@@ -59,11 +59,11 @@ buildPythonPackage rec {
     qt = qt4;
   };
 
-  meta = {
+  meta = with lib; {
     description = "Python bindings for Qt";
     license = "GPL";
     homepage = "http://www.riverbankcomputing.co.uk";
-    maintainers = [ stdenv.lib.maintainers.sander ];
-    platforms = stdenv.lib.platforms.mesaPlatforms;
+    maintainers = [ maintainers.sander ];
+    platforms = platforms.mesaPlatforms;
   };
 }
diff --git a/pkgs/development/python-modules/pyscard/default.nix b/pkgs/development/python-modules/pyscard/default.nix
index 9798d94900b..28c40e5ec5f 100644
--- a/pkgs/development/python-modules/pyscard/default.nix
+++ b/pkgs/development/python-modules/pyscard/default.nix
@@ -1,11 +1,8 @@
-{ stdenv, fetchPypi, buildPythonPackage, swig, pcsclite, PCSC }:
+{ lib, stdenv, fetchPypi, buildPythonPackage, swig, pcsclite, PCSC }:
 
 let
   # Package does not support configuring the pcsc library.
   withApplePCSC = stdenv.isDarwin;
-
-  inherit (stdenv.lib) getLib getDev optionalString optionals;
-  inherit (stdenv.hostPlatform.extensions) sharedLibrary;
 in
 
 buildPythonPackage rec {
@@ -24,19 +21,19 @@ buildPythonPackage rec {
   '' else ''
     substituteInPlace smartcard/scard/winscarddll.c \
       --replace "libpcsclite.so.1" \
-                "${getLib pcsclite}/lib/libpcsclite${sharedLibrary}"
+                "${lib.getLib pcsclite}/lib/libpcsclite${stdenv.hostPlatform.extensions.sharedLibrary}"
   '';
 
-  NIX_CFLAGS_COMPILE = optionalString (! withApplePCSC)
-    "-I ${getDev pcsclite}/include/PCSC";
+  NIX_CFLAGS_COMPILE = lib.optionalString (! withApplePCSC)
+    "-I ${lib.getDev pcsclite}/include/PCSC";
 
   propagatedBuildInputs = if withApplePCSC then [ PCSC ] else [ pcsclite ];
   nativeBuildInputs = [ swig ];
 
-  meta = {
+  meta = with lib; {
     homepage = "https://pyscard.sourceforge.io/";
     description = "Smartcard library for python";
-    license = stdenv.lib.licenses.lgpl21;
-    maintainers = with stdenv.lib.maintainers; [ layus ];
+    license = licenses.lgpl21;
+    maintainers = with maintainers; [ layus ];
   };
 }
diff --git a/pkgs/development/python-modules/pyscss/default.nix b/pkgs/development/python-modules/pyscss/default.nix
index 87f23b8edf7..6da19bc48ab 100644
--- a/pkgs/development/python-modules/pyscss/default.nix
+++ b/pkgs/development/python-modules/pyscss/default.nix
@@ -23,8 +23,8 @@ buildPythonPackage rec {
   checkInputs = [ pytest ];
 
   propagatedBuildInputs = [ six ]
-    ++ (stdenv.lib.optionals (pythonOlder "3.4") [ enum34 pathlib ])
-    ++ (stdenv.lib.optionals (pythonOlder "2.7") [ ordereddict ]);
+    ++ (lib.optionals (pythonOlder "3.4") [ enum34 pathlib ])
+    ++ (lib.optionals (pythonOlder "2.7") [ ordereddict ]);
 
   checkPhase = ''
     py.test
diff --git a/pkgs/development/python-modules/pyside/apiextractor.nix b/pkgs/development/python-modules/pyside/apiextractor.nix
index 10f030b13f6..9398a62997b 100644
--- a/pkgs/development/python-modules/pyside/apiextractor.nix
+++ b/pkgs/development/python-modules/pyside/apiextractor.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, cmake, libxml2, libxslt, python3, qt4 }:
+{ lib, stdenv, fetchurl, cmake, libxml2, libxslt, python3, qt4 }:
 
 # This derivation does not provide any Python module and should therefore be called via `all-packages.nix`.
 let
@@ -20,11 +20,11 @@ in stdenv.mkDerivation {
   nativeBuildInputs = [ cmake pythonEnv ];
   buildInputs = [ qt4 libxml2 libxslt ];
 
-  meta = {
+  meta = with lib; {
     description = "Eases the development of bindings of Qt-based libraries for high level languages by automating most of the process";
-    license = stdenv.lib.licenses.gpl2;
+    license = licenses.gpl2;
     homepage = "http://www.pyside.org/docs/apiextractor/";
     maintainers = [ ];
-    platforms = stdenv.lib.platforms.all;
+    platforms = platforms.all;
   };
 }
diff --git a/pkgs/development/python-modules/pyside/generatorrunner.nix b/pkgs/development/python-modules/pyside/generatorrunner.nix
index cbc586f4734..532ee6b2b24 100644
--- a/pkgs/development/python-modules/pyside/generatorrunner.nix
+++ b/pkgs/development/python-modules/pyside/generatorrunner.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchurl, cmake, pysideApiextractor, python3, qt4 }:
+{ lib, stdenv, fetchurl, cmake, pysideApiextractor, python3, qt4 }:
 
 # This derivation does not provide any Python module and should therefore be called via `all-packages.nix`.
 let
@@ -22,11 +22,11 @@ in stdenv.mkDerivation {
   nativeBuildInputs = [ cmake pythonEnv ];
   buildInputs = [ pysideApiextractor qt4 ];
 
-  meta = {
+  meta = with lib; {
     description = "Eases the development of binding generators for C++ and Qt-based libraries by providing a framework to help automating most of the process";
-    license = stdenv.lib.licenses.gpl2;
+    license = licenses.gpl2;
     homepage = "http://www.pyside.org/docs/generatorrunner/";
     maintainers = [ ];
-    platforms = stdenv.lib.platforms.all;
+    platforms = platforms.all;
   };
 }
diff --git a/pkgs/development/python-modules/pyspotify/default.nix b/pkgs/development/python-modules/pyspotify/default.nix
index a6bf14cdca0..302eb12de5a 100644
--- a/pkgs/development/python-modules/pyspotify/default.nix
+++ b/pkgs/development/python-modules/pyspotify/default.nix
@@ -22,7 +22,7 @@ buildPythonPackage rec {
     find -print0 | xargs -0 touch
   '';
 
-  postInstall = stdenv.lib.optionalString stdenv.isDarwin ''
+  postInstall = lib.optionalString stdenv.isDarwin ''
     find "$out" -name _spotify.so -exec \
         install_name_tool -change \
         @loader_path/../Frameworks/libspotify.framework/libspotify \
diff --git a/pkgs/development/python-modules/pysqlite/default.nix b/pkgs/development/python-modules/pysqlite/default.nix
index fec1bbd0bed..09cc312223a 100644
--- a/pkgs/development/python-modules/pysqlite/default.nix
+++ b/pkgs/development/python-modules/pysqlite/default.nix
@@ -26,7 +26,7 @@ buildPythonPackage rec {
     substituteInPlace "setup.cfg"                                     \
             --replace "/usr/local/include" "${pkgs.sqlite.dev}/include"   \
             --replace "/usr/local/lib" "${pkgs.sqlite.out}/lib"
-    ${stdenv.lib.optionalString (!stdenv.isDarwin) ''export LDSHARED="$CC -pthread -shared"''}
+    ${lib.optionalString (!stdenv.isDarwin) ''export LDSHARED="$CC -pthread -shared"''}
   '';
 
   meta = with lib; {
diff --git a/pkgs/development/python-modules/pytest-asyncio/default.nix b/pkgs/development/python-modules/pytest-asyncio/default.nix
index 961845a28e1..c621d9a4785 100644
--- a/pkgs/development/python-modules/pytest-asyncio/default.nix
+++ b/pkgs/development/python-modules/pytest-asyncio/default.nix
@@ -11,7 +11,7 @@ buildPythonPackage rec {
   };
 
   buildInputs = [ pytest ]
-    ++ stdenv.lib.optionals isPy35 [ async_generator ];
+    ++ lib.optionals isPy35 [ async_generator ];
 
   # No tests in archive
   doCheck = false;
diff --git a/pkgs/development/python-modules/pytest/4.nix b/pkgs/development/python-modules/pytest/4.nix
index 88963537c9d..63e57a7f769 100644
--- a/pkgs/development/python-modules/pytest/4.nix
+++ b/pkgs/development/python-modules/pytest/4.nix
@@ -14,8 +14,8 @@ buildPythonPackage rec {
   checkInputs = [ hypothesis mock ];
   buildInputs = [ setuptools_scm ];
   propagatedBuildInputs = [ attrs py setuptools six pluggy more-itertools atomicwrites wcwidth packaging ]
-    ++ stdenv.lib.optionals (!isPy3k) [ funcsigs ]
-    ++ stdenv.lib.optionals (pythonOlder "3.6") [ pathlib2 ];
+    ++ lib.optionals (!isPy3k) [ funcsigs ]
+    ++ lib.optionals (pythonOlder "3.6") [ pathlib2 ];
 
   doCheck = !isPyPy; # https://github.com/pytest-dev/pytest/issues/3460
   checkPhase = ''
diff --git a/pkgs/development/python-modules/pytest/5.nix b/pkgs/development/python-modules/pytest/5.nix
index ade36f4aa0b..1293cc94b0f 100644
--- a/pkgs/development/python-modules/pytest/5.nix
+++ b/pkgs/development/python-modules/pytest/5.nix
@@ -43,7 +43,7 @@ buildPythonPackage rec {
     six
     toml
     wcwidth
-  ] ++ stdenv.lib.optionals (pythonOlder "3.6") [ pathlib2 ];
+  ] ++ lib.optionals (pythonOlder "3.6") [ pathlib2 ];
 
   doCheck = !isPyPy; # https://github.com/pytest-dev/pytest/issues/3460
 
diff --git a/pkgs/development/python-modules/pytest/default.nix b/pkgs/development/python-modules/pytest/default.nix
index 3c8e00f1af8..6f5c99a99b1 100644
--- a/pkgs/development/python-modules/pytest/default.nix
+++ b/pkgs/development/python-modules/pytest/default.nix
@@ -45,7 +45,7 @@ buildPythonPackage rec {
     six
     toml
     wcwidth
-  ] ++ stdenv.lib.optionals (pythonOlder "3.6") [ pathlib2 ];
+  ] ++ lib.optionals (pythonOlder "3.6") [ pathlib2 ];
 
   doCheck = !isPyPy; # https://github.com/pytest-dev/pytest/issues/3460
 
diff --git a/pkgs/development/python-modules/python-engineio/default.nix b/pkgs/development/python-modules/python-engineio/default.nix
index 19c8941d2fc..ed03d966307 100644
--- a/pkgs/development/python-modules/python-engineio/default.nix
+++ b/pkgs/development/python-modules/python-engineio/default.nix
@@ -38,7 +38,7 @@ buildPythonPackage rec {
 
   doCheck = !stdenv.isDarwin;
 
-  preCheck = stdenv.lib.optionalString stdenv.isLinux ''
+  preCheck = lib.optionalString stdenv.isLinux ''
     echo "nameserver 127.0.0.1" > resolv.conf
     export NIX_REDIRECTS=/etc/protocols=${iana-etc}/etc/protocols:/etc/resolv.conf=$(realpath resolv.conf) \
       LD_PRELOAD=${libredirect}/lib/libredirect.so
diff --git a/pkgs/development/python-modules/python-jsonrpc-server/default.nix b/pkgs/development/python-modules/python-jsonrpc-server/default.nix
index 9879a441b3e..3a0ab33363e 100644
--- a/pkgs/development/python-modules/python-jsonrpc-server/default.nix
+++ b/pkgs/development/python-modules/python-jsonrpc-server/default.nix
@@ -23,7 +23,7 @@ buildPythonPackage rec {
   ];
 
   propagatedBuildInputs = [ future ujson ]
-    ++ stdenv.lib.optional (pythonOlder "3.2") futures;
+    ++ lib.optional (pythonOlder "3.2") futures;
 
   meta = with lib; {
     homepage = "https://github.com/palantir/python-jsonrpc-server";
diff --git a/pkgs/development/python-modules/python-language-server/default.nix b/pkgs/development/python-modules/python-language-server/default.nix
index dc3b33a6f53..f22652d0f73 100644
--- a/pkgs/development/python-modules/python-language-server/default.nix
+++ b/pkgs/development/python-modules/python-language-server/default.nix
@@ -31,16 +31,16 @@ buildPythonPackage rec {
   };
 
   propagatedBuildInputs = [ setuptools jedi pluggy future python-jsonrpc-server flake8 ujson ]
-    ++ stdenv.lib.optional (withProvider "autopep8") autopep8
-    ++ stdenv.lib.optional (withProvider "mccabe") mccabe
-    ++ stdenv.lib.optional (withProvider "pycodestyle") pycodestyle
-    ++ stdenv.lib.optional (withProvider "pydocstyle") pydocstyle
-    ++ stdenv.lib.optional (withProvider "pyflakes") pyflakes
-    ++ stdenv.lib.optional (withProvider "pylint") pylint
-    ++ stdenv.lib.optional (withProvider "rope") rope
-    ++ stdenv.lib.optional (withProvider "yapf") yapf
-    ++ stdenv.lib.optional isPy27 configparser
-    ++ stdenv.lib.optionals (pythonOlder "3.2") [ backports_functools_lru_cache futures ];
+    ++ lib.optional (withProvider "autopep8") autopep8
+    ++ lib.optional (withProvider "mccabe") mccabe
+    ++ lib.optional (withProvider "pycodestyle") pycodestyle
+    ++ lib.optional (withProvider "pydocstyle") pydocstyle
+    ++ lib.optional (withProvider "pyflakes") pyflakes
+    ++ lib.optional (withProvider "pylint") pylint
+    ++ lib.optional (withProvider "rope") rope
+    ++ lib.optional (withProvider "yapf") yapf
+    ++ lib.optional isPy27 configparser
+    ++ lib.optionals (pythonOlder "3.2") [ backports_functools_lru_cache futures ];
 
 
   # The tests require all the providers, disable otherwise.
@@ -68,7 +68,7 @@ buildPythonPackage rec {
     "test_snippet_parsing"
     "test_numpy_hover"
     "test_symbols"
-  ] ++ stdenv.lib.optional isPy27 "test_flake8_lint";
+  ] ++ lib.optional isPy27 "test_flake8_lint";
 
   meta = with lib; {
     homepage = "https://github.com/palantir/python-language-server";
diff --git a/pkgs/development/python-modules/python-mapnik/default.nix b/pkgs/development/python-modules/python-mapnik/default.nix
index e129bf45219..fe68ed60e37 100644
--- a/pkgs/development/python-modules/python-mapnik/default.nix
+++ b/pkgs/development/python-modules/python-mapnik/default.nix
@@ -30,7 +30,7 @@ in buildPythonPackage rec {
   disabled = isPyPy;
   doCheck = false; # doesn't find needed test data files
   preBuild = let
-    pythonVersion = with stdenv.lib.versions; "${major python.version}${minor python.version}";
+    pythonVersion = with lib.versions; "${major python.version}${minor python.version}";
   in ''
     export BOOST_PYTHON_LIB="boost_python${pythonVersion}"
     export BOOST_THREAD_LIB="boost_thread"
diff --git a/pkgs/development/python-modules/python-redis-lock/default.nix b/pkgs/development/python-modules/python-redis-lock/default.nix
index 7cf2affc417..235d085fffd 100644
--- a/pkgs/development/python-modules/python-redis-lock/default.nix
+++ b/pkgs/development/python-modules/python-redis-lock/default.nix
@@ -24,7 +24,7 @@ buildPythonPackage rec {
   '';
 
   propagatedBuildInputs = [ redis ]
-  ++ stdenv.lib.optional withDjango django_redis;
+  ++ lib.optional withDjango django_redis;
 
 
   meta = with lib; {
diff --git a/pkgs/development/python-modules/python-xmp-toolkit/default.nix b/pkgs/development/python-modules/python-xmp-toolkit/default.nix
index ff4942abef5..3e6d7284568 100644
--- a/pkgs/development/python-modules/python-xmp-toolkit/default.nix
+++ b/pkgs/development/python-modules/python-xmp-toolkit/default.nix
@@ -26,7 +26,7 @@ buildPythonPackage {
 
   buildInputs = [ exempi ];
 
-  checkInputs = stdenv.lib.optionals (pythonOlder "3.3") [ mock ];
+  checkInputs = lib.optionals (pythonOlder "3.3") [ mock ];
 
   propagatedBuildInputs = [ pytz ];
 
diff --git a/pkgs/development/python-modules/pythonocc-core/default.nix b/pkgs/development/python-modules/pythonocc-core/default.nix
index cbcf4ab9d02..d1d06d22c64 100644
--- a/pkgs/development/python-modules/pythonocc-core/default.nix
+++ b/pkgs/development/python-modules/pythonocc-core/default.nix
@@ -23,7 +23,7 @@ stdenv.mkDerivation rec {
   buildInputs = [
     python opencascade smesh
     freetype libGL libGLU libX11
-  ] ++ stdenv.lib.optionals stdenv.isDarwin [ Cocoa ];
+  ] ++ lib.optionals stdenv.isDarwin [ Cocoa ];
 
   cmakeFlags = [
     "-Wno-dev"
diff --git a/pkgs/development/python-modules/pytorch/bin.nix b/pkgs/development/python-modules/pytorch/bin.nix
index a25f2013adf..1ffda5c86b0 100644
--- a/pkgs/development/python-modules/pytorch/bin.nix
+++ b/pkgs/development/python-modules/pytorch/bin.nix
@@ -52,7 +52,7 @@ in buildPythonPackage {
   '';
 
   postFixup = let
-    rpath = stdenv.lib.makeLibraryPath [ stdenv.cc.cc.lib nvidia_x11 ];
+    rpath = lib.makeLibraryPath [ stdenv.cc.cc.lib nvidia_x11 ];
   in ''
     find $out/${python.sitePackages}/torch/lib -type f \( -name '*.so' -or -name '*.so.*' \) | while read lib; do
       echo "setting rpath for $lib..."
diff --git a/pkgs/development/python-modules/pytorch/default.nix b/pkgs/development/python-modules/pytorch/default.nix
index 822586bf190..db1914f4ee7 100644
--- a/pkgs/development/python-modules/pytorch/default.nix
+++ b/pkgs/development/python-modules/pytorch/default.nix
@@ -265,7 +265,7 @@ in buildPythonPackage rec {
     cp -r $out/${python.sitePackages}/torch/lib     $lib/lib
   '';
 
-  postFixup = stdenv.lib.optionalString stdenv.isDarwin ''
+  postFixup = lib.optionalString stdenv.isDarwin ''
     for f in $(ls $lib/lib/*.dylib); do
         install_name_tool -id $lib/lib/$(basename $f) $f || true
     done
diff --git a/pkgs/development/python-modules/pyutil/default.nix b/pkgs/development/python-modules/pyutil/default.nix
index effb9f7b7e6..f1c0d3be8cc 100644
--- a/pkgs/development/python-modules/pyutil/default.nix
+++ b/pkgs/development/python-modules/pyutil/default.nix
@@ -24,7 +24,7 @@ buildPythonPackage rec {
   # package, apparently some kind of plugin.
   doCheck = false;
 
-  prePatch = stdenv.lib.optionalString isPyPy ''
+  prePatch = lib.optionalString isPyPy ''
     grep -rl 'utf-8-with-signature-unix' ./ | xargs sed -i -e "s|utf-8-with-signature-unix|utf-8|g"
   '';
 
diff --git a/pkgs/development/python-modules/rbtools/default.nix b/pkgs/development/python-modules/rbtools/default.nix
index f1c9685d5cc..1c99ee0fc8d 100644
--- a/pkgs/development/python-modules/rbtools/default.nix
+++ b/pkgs/development/python-modules/rbtools/default.nix
@@ -1,4 +1,4 @@
-{ lib, stdenv
+{ lib
 , buildPythonPackage
 , fetchurl
 , isPy3k
@@ -16,7 +16,7 @@ buildPythonPackage rec {
   disabled = !isPy3k;
 
   src = fetchurl {
-    url = "https://downloads.reviewboard.org/releases/RBTools/${stdenv.lib.versions.majorMinor version}/RBTools-${version}.tar.gz";
+    url = "https://downloads.reviewboard.org/releases/RBTools/${lib.versions.majorMinor version}/RBTools-${version}.tar.gz";
     sha256 = "577c2f8bbf88f77bda84ee95af0310b59111c156f48a5aab56ca481e2f77eaf4";
   };
 
diff --git a/pkgs/development/python-modules/reikna/default.nix b/pkgs/development/python-modules/reikna/default.nix
index ebe3dc772d7..896bc8e02f0 100644
--- a/pkgs/development/python-modules/reikna/default.nix
+++ b/pkgs/development/python-modules/reikna/default.nix
@@ -1,4 +1,4 @@
-{ stdenv
+{ lib
 , fetchPypi
 , buildPythonPackage
 , sphinx
@@ -23,8 +23,8 @@ buildPythonPackage rec {
   checkInputs = [ sphinx pytestcov pytest ];
 
   propagatedBuildInputs = [ Mako numpy funcsigs ]
-    ++ stdenv.lib.optional withCuda pycuda
-    ++ stdenv.lib.optional withOpenCL pyopencl;
+    ++ lib.optional withCuda pycuda
+    ++ lib.optional withOpenCL pyopencl;
 
   checkPhase = ''
     py.test
@@ -33,11 +33,11 @@ buildPythonPackage rec {
   # Requires device
   doCheck = false;
 
-  meta = {
+  meta = with lib; {
     description = "GPGPU algorithms for PyCUDA and PyOpenCL";
     homepage = "https://github.com/fjarri/reikna";
-    license = stdenv.lib.licenses.mit;
-    maintainers = [ stdenv.lib.maintainers.fridh ];
+    license = licenses.mit;
+    maintainers = [ maintainers.fridh ];
 
   };
 
diff --git a/pkgs/development/python-modules/rfc6555/default.nix b/pkgs/development/python-modules/rfc6555/default.nix
index 0bd7b0ca686..4e47915bdf7 100644
--- a/pkgs/development/python-modules/rfc6555/default.nix
+++ b/pkgs/development/python-modules/rfc6555/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, buildPythonPackage, fetchPypi, pythonPackages }:
+{ lib, buildPythonPackage, fetchPypi, pythonPackages }:
 
 buildPythonPackage rec {
   pname = "rfc6555";
@@ -19,10 +19,10 @@ buildPythonPackage rec {
     py.test tests/
   '';
 
-  meta = {
+  meta = with lib; {
     description = "Python implementation of the Happy Eyeballs Algorithm";
     homepage = "https://pypi.org/project/rfc6555";
-    license = stdenv.lib.licenses.asl20;
-    maintainers = with stdenv.lib.maintainers; [ endocrimes ];
+    license = licenses.asl20;
+    maintainers = with maintainers; [ endocrimes ];
   };
 }
diff --git a/pkgs/development/python-modules/rich/default.nix b/pkgs/development/python-modules/rich/default.nix
index 1e667f1f3de..d19f47281cd 100644
--- a/pkgs/development/python-modules/rich/default.nix
+++ b/pkgs/development/python-modules/rich/default.nix
@@ -32,7 +32,7 @@ buildPythonPackage rec {
     ipywidgets
     pygments
     typing-extensions
-  ] ++ stdenv.lib.optional (pythonOlder "3.7") dataclasses;
+  ] ++ lib.optional (pythonOlder "3.7") dataclasses;
 
   checkInputs = [ pytestCheckHook ];
   pythonImportsCheck = [ "rich" ];
diff --git a/pkgs/development/python-modules/rsa/4_0.nix b/pkgs/development/python-modules/rsa/4_0.nix
index a6aa89b2ea1..8400647aaad 100644
--- a/pkgs/development/python-modules/rsa/4_0.nix
+++ b/pkgs/development/python-modules/rsa/4_0.nix
@@ -20,7 +20,7 @@ buildPythonPackage rec {
   checkInputs = [ unittest2 mock ];
   propagatedBuildInputs = [ pyasn1 ];
 
-  preConfigure = stdenv.lib.optionalString (isPy3k && pythonOlder "3.7") ''
+  preConfigure = lib.optionalString (isPy3k && pythonOlder "3.7") ''
     substituteInPlace setup.py --replace "open('README.md')" "open('README.md',encoding='utf-8')"
   '';
 
diff --git a/pkgs/development/python-modules/rsa/default.nix b/pkgs/development/python-modules/rsa/default.nix
index 1f26350fc36..b688369beb5 100644
--- a/pkgs/development/python-modules/rsa/default.nix
+++ b/pkgs/development/python-modules/rsa/default.nix
@@ -21,7 +21,7 @@ buildPythonPackage rec {
   checkInputs = [ unittest2 mock ];
   propagatedBuildInputs = [ pyasn1 ];
 
-  preConfigure = stdenv.lib.optionalString (isPy3k && pythonOlder "3.7") ''
+  preConfigure = lib.optionalString (isPy3k && pythonOlder "3.7") ''
     substituteInPlace setup.py --replace "open('README.md')" "open('README.md',encoding='utf-8')"
   '';
 
diff --git a/pkgs/development/python-modules/s3transfer/default.nix b/pkgs/development/python-modules/s3transfer/default.nix
index 27551a798d7..6f816fc9bb8 100644
--- a/pkgs/development/python-modules/s3transfer/default.nix
+++ b/pkgs/development/python-modules/s3transfer/default.nix
@@ -1,4 +1,4 @@
-{ stdenv
+{ lib
 , fetchPypi
 , pythonOlder
 , buildPythonPackage
@@ -23,7 +23,7 @@ buildPythonPackage rec {
 
   propagatedBuildInputs =
     [ botocore
-    ] ++ stdenv.lib.optional (pythonOlder "3") futures;
+    ] ++ lib.optional (pythonOlder "3") futures;
 
   buildInputs = [
     docutils
@@ -43,9 +43,9 @@ buildPythonPackage rec {
   # version on pypi has no tests/ dir
   doCheck = false;
 
-  meta = {
+  meta = with lib; {
     homepage = "https://github.com/boto/s3transfer";
-    license = stdenv.lib.licenses.asl20;
+    license = licenses.asl20;
     description = "A library for managing Amazon S3 transfers";
   };
 }
diff --git a/pkgs/development/python-modules/scrapy/default.nix b/pkgs/development/python-modules/scrapy/default.nix
index 48bafa41dff..6887eded3bf 100644
--- a/pkgs/development/python-modules/scrapy/default.nix
+++ b/pkgs/development/python-modules/scrapy/default.nix
@@ -80,7 +80,7 @@ buildPythonPackage rec {
     "test_retry_dns_error"
     "test_custom_asyncio_loop_enabled_true"
     "test_custom_loop_asyncio"
-  ] ++ stdenv.lib.optionals stdenv.isDarwin [
+  ] ++ lib.optionals stdenv.isDarwin [
     "test_xmliter_encoding"
     "test_download"
   ];
diff --git a/pkgs/development/python-modules/screeninfo/default.nix b/pkgs/development/python-modules/screeninfo/default.nix
index f53a7053ff5..f71f8d0c263 100644
--- a/pkgs/development/python-modules/screeninfo/default.nix
+++ b/pkgs/development/python-modules/screeninfo/default.nix
@@ -23,7 +23,7 @@ buildPythonApplication rec {
       --replace "load_library(\"Xrandr\")" "ctypes.cdll.LoadLibrary(\"${libXrandr}/lib/libXrandr.so\")"
   '';
 
-  propagatedBuildInputs = stdenv.lib.optional isPy36 dataclasses;
+  propagatedBuildInputs = lib.optional isPy36 dataclasses;
 
   buildInputs = [ libX11 libXinerama libXrandr];
 
diff --git a/pkgs/development/python-modules/selenium/default.nix b/pkgs/development/python-modules/selenium/default.nix
index b32dfe2653e..664f84933ed 100644
--- a/pkgs/development/python-modules/selenium/default.nix
+++ b/pkgs/development/python-modules/selenium/default.nix
@@ -36,7 +36,7 @@ buildPythonPackage rec {
     geckodriver urllib3
   ];
 
-  patchPhase = stdenv.lib.optionalString stdenv.isLinux ''
+  patchPhase = lib.optionalString stdenv.isLinux ''
     cp "${x_ignore_nofocus}/cpp/linux-specific/"* .
     substituteInPlace x_ignore_nofocus.c --replace "/usr/lib/libX11.so.6" "${xorg.libX11.out}/lib/libX11.so.6"
     cc -c -fPIC x_ignore_nofocus.c -o x_ignore_nofocus.o
diff --git a/pkgs/development/python-modules/sentry-sdk/default.nix b/pkgs/development/python-modules/sentry-sdk/default.nix
index b846c0bc743..ea9bbc1f0c3 100644
--- a/pkgs/development/python-modules/sentry-sdk/default.nix
+++ b/pkgs/development/python-modules/sentry-sdk/default.nix
@@ -38,7 +38,7 @@ buildPythonPackage rec {
 
   checkInputs = [ blinker botocore chalice django flask tornado bottle rq falcon sqlalchemy werkzeug trytond
     executing pure-eval asttokens ]
-  ++ stdenv.lib.optionals isPy3k [ celery pyramid sanic aiohttp ];
+  ++ lib.optionals isPy3k [ celery pyramid sanic aiohttp ];
 
   propagatedBuildInputs = [ urllib3 certifi ];
 
diff --git a/pkgs/development/python-modules/shapely/default.nix b/pkgs/development/python-modules/shapely/default.nix
index f852f77bcfd..b5dd0be5445 100644
--- a/pkgs/development/python-modules/shapely/default.nix
+++ b/pkgs/development/python-modules/shapely/default.nix
@@ -29,7 +29,7 @@ buildPythonPackage rec {
     (substituteAll {
       src = ./library-paths.patch;
       libgeos_c = GEOS_LIBRARY_PATH;
-      libc = stdenv.lib.optionalString (!stdenv.isDarwin) "${stdenv.cc.libc}/lib/libc${stdenv.hostPlatform.extensions.sharedLibrary}.6";
+      libc = lib.optionalString (!stdenv.isDarwin) "${stdenv.cc.libc}/lib/libc${stdenv.hostPlatform.extensions.sharedLibrary}.6";
     })
   ];
 
diff --git a/pkgs/development/python-modules/simplebayes/default.nix b/pkgs/development/python-modules/simplebayes/default.nix
index b7dd0310a08..ed86b48fc07 100644
--- a/pkgs/development/python-modules/simplebayes/default.nix
+++ b/pkgs/development/python-modules/simplebayes/default.nix
@@ -21,7 +21,7 @@ buildPythonPackage {
 
   checkInputs = [ nose mock ];
 
-  postPatch = stdenv.lib.optionalString isPy3k ''
+  postPatch = lib.optionalString isPy3k ''
     sed -i -e 's/open *(\([^)]*\))/open(\1, encoding="utf-8")/' setup.py
   '';
 
diff --git a/pkgs/development/python-modules/spacy/models.nix b/pkgs/development/python-modules/spacy/models.nix
index 4279383ae6b..8c57d2e0d26 100644
--- a/pkgs/development/python-modules/spacy/models.nix
+++ b/pkgs/development/python-modules/spacy/models.nix
@@ -1,4 +1,4 @@
-{ stdenv, lib, buildPythonPackage, fetchurl, jieba, pkuseg, spacy }:
+{ lib, buildPythonPackage, fetchurl, jieba, pkuseg, spacy }:
 let
   buildModelPackage = { pname, version, sha256, license }:
   let
@@ -24,8 +24,8 @@ let
     };
   };
 
-  makeModelSet = models: with stdenv.lib; listToAttrs (map (m: nameValuePair m.pname (buildModelPackage m)) models);
+  makeModelSet = models: with lib; listToAttrs (map (m: nameValuePair m.pname (buildModelPackage m)) models);
 
-in makeModelSet (stdenv.lib.importJSON ./models.json)
+in makeModelSet (lib.importJSON ./models.json)
 
 # cat models.json | jq -r '.[] | @uri "https://github.com/explosion/spacy-models/releases/download/\(.pname)-\(.version)/\(.pname)-\(.version).tar.gz"' | xargs -n1 nix-prefetch-url
diff --git a/pkgs/development/python-modules/stringtemplate/default.nix b/pkgs/development/python-modules/stringtemplate/default.nix
index c70cac59920..8bdb69a3074 100644
--- a/pkgs/development/python-modules/stringtemplate/default.nix
+++ b/pkgs/development/python-modules/stringtemplate/default.nix
@@ -1,4 +1,4 @@
-{stdenv, fetchurl, buildPythonPackage, antlr, isPy3k}:
+{ lib, fetchurl, buildPythonPackage, antlr, isPy3k }:
 
 buildPythonPackage rec {
   pname = "PyStringTemplate";
@@ -16,9 +16,9 @@ buildPythonPackage rec {
   # No tests included in archive
   doCheck = false;
 
-  meta = {
+  meta = with lib; {
     homepage = "https://www.stringtemplate.org/";
     description = "Text Templating Library";
-    platforms = stdenv.lib.platforms.linux;
+    platforms = platforms.linux;
   };
 }
diff --git a/pkgs/development/python-modules/tables/3.5.nix b/pkgs/development/python-modules/tables/3.5.nix
index bf0eb51c851..efc47a1ad3f 100644
--- a/pkgs/development/python-modules/tables/3.5.nix
+++ b/pkgs/development/python-modules/tables/3.5.nix
@@ -1,8 +1,6 @@
-{ stdenv, lib, fetchPypi, python, buildPythonPackage
+{ lib, fetchPypi, python, buildPythonPackage
 , cython, bzip2, lzo, numpy, numexpr, hdf5, six, c-blosc, mock }:
 
-with stdenv.lib;
-
 buildPythonPackage rec {
   version = "3.5.2";
   pname = "tables";
@@ -18,10 +16,10 @@ buildPythonPackage rec {
   # The setup script complains about missing run-paths, but they are
   # actually set.
   setupPyBuildFlags = [
-    "--hdf5=${getDev hdf5}"
-    "--lzo=${getDev lzo}"
-    "--bzip2=${getDev bzip2}"
-    "--blosc=${getDev c-blosc}"
+    "--hdf5=${lib.getDev hdf5}"
+    "--lzo=${lib.getDev lzo}"
+    "--bzip2=${lib.getDev bzip2}"
+    "--blosc=${lib.getDev c-blosc}"
   ];
   # Run the test suite.
   # It requires the build path to be in the python search path.
@@ -50,9 +48,9 @@ buildPythonPackage rec {
   # Disable tests until the failure described above is fixed.
   doCheck = false;
 
-  meta = {
+  meta = with lib; {
     description = "Hierarchical datasets for Python";
     homepage = "http://www.pytables.org/";
-    license = stdenv.lib.licenses.bsd2;
+    license = licenses.bsd2;
   };
 }
diff --git a/pkgs/development/python-modules/tables/default.nix b/pkgs/development/python-modules/tables/default.nix
index cd2af0dc28d..fe49ab4d9ed 100644
--- a/pkgs/development/python-modules/tables/default.nix
+++ b/pkgs/development/python-modules/tables/default.nix
@@ -1,8 +1,6 @@
-{ stdenv, lib, fetchPypi, python, buildPythonPackage, isPy38
+{ lib, fetchPypi, python, buildPythonPackage, isPy38
 , cython, bzip2, lzo, numpy, numexpr, hdf5, six, c-blosc, mock }:
 
-with stdenv.lib;
-
 buildPythonPackage rec {
   version = "3.6.1";
   pname = "tables";
@@ -30,10 +28,10 @@ buildPythonPackage rec {
   # The setup script complains about missing run-paths, but they are
   # actually set.
   setupPyBuildFlags = [
-    "--hdf5=${getDev hdf5}"
-    "--lzo=${getDev lzo}"
-    "--bzip2=${getDev bzip2}"
-    "--blosc=${getDev c-blosc}"
+    "--hdf5=${lib.getDev hdf5}"
+    "--lzo=${lib.getDev lzo}"
+    "--bzip2=${lib.getDev bzip2}"
+    "--blosc=${lib.getDev c-blosc}"
   ];
   # Run the test suite.
   # It requires the build path to be in the python search path.
@@ -62,9 +60,9 @@ buildPythonPackage rec {
   # Disable tests until the failure described above is fixed.
   doCheck = false;
 
-  meta = {
+  meta = with lib; {
     description = "Hierarchical datasets for Python";
     homepage = "http://www.pytables.org/";
-    license = stdenv.lib.licenses.bsd2;
+    license = licenses.bsd2;
   };
 }
diff --git a/pkgs/development/python-modules/tatsu/default.nix b/pkgs/development/python-modules/tatsu/default.nix
index 0469fc30e75..cba34a95a7b 100644
--- a/pkgs/development/python-modules/tatsu/default.nix
+++ b/pkgs/development/python-modules/tatsu/default.nix
@@ -25,8 +25,8 @@ buildPythonPackage rec {
 
   nativeBuildInputs = [ pytestrunner ];
   propagatedBuildInputs = [ colorama mypy pyyaml regex ]
-    ++ stdenv.lib.optionals (pythonOlder "3.7") [ dataclasses ]
-    ++ stdenv.lib.optionals (pythonOlder "3.5") [ typing ];
+    ++ lib.optionals (pythonOlder "3.7") [ dataclasses ]
+    ++ lib.optionals (pythonOlder "3.5") [ typing ];
   checkInputs = [ pytest-mypy ];
 
   checkPhase = ''
diff --git a/pkgs/development/python-modules/tensorflow/bin.nix b/pkgs/development/python-modules/tensorflow/bin.nix
index c0a9d5eadaf..ef6d4f45ef9 100644
--- a/pkgs/development/python-modules/tensorflow/bin.nix
+++ b/pkgs/development/python-modules/tensorflow/bin.nix
@@ -125,7 +125,7 @@ in buildPythonPackage {
         zlib
       ];
 
-      rpath = stdenv.lib.makeLibraryPath (libpaths ++ cudapaths);
+      rpath = lib.makeLibraryPath (libpaths ++ cudapaths);
     in
     lib.optionalString stdenv.isLinux ''
       # This is an array containing all the directories in the tensorflow2
diff --git a/pkgs/development/python-modules/tkinter/default.nix b/pkgs/development/python-modules/tkinter/default.nix
index 1efebed9872..9f82dee45ef 100644
--- a/pkgs/development/python-modules/tkinter/default.nix
+++ b/pkgs/development/python-modules/tkinter/default.nix
@@ -1,4 +1,5 @@
-{ stdenv
+{ lib
+, stdenv
 , buildPythonPackage
 , python
 , py
@@ -17,7 +18,7 @@ buildPythonPackage {
     # Move the tkinter module
     mkdir -p $out/${py.sitePackages}
     mv lib/${py.libPrefix}/lib-dynload/_tkinter* $out/${py.sitePackages}/
-  '' + stdenv.lib.optionalString (!stdenv.isDarwin) ''
+  '' + lib.optionalString (!stdenv.isDarwin) ''
     # Update the rpath to point to python without x11Support
     old_rpath=$(patchelf --print-rpath $out/${py.sitePackages}/_tkinter*)
     new_rpath=$(sed "s#${py}#${python}#g" <<< "$old_rpath" )
diff --git a/pkgs/development/python-modules/todoist/default.nix b/pkgs/development/python-modules/todoist/default.nix
index ac781796230..62749d3b02f 100644
--- a/pkgs/development/python-modules/todoist/default.nix
+++ b/pkgs/development/python-modules/todoist/default.nix
@@ -1,4 +1,4 @@
-{ stdenv, fetchPypi, buildPythonPackage
+{ lib, fetchPypi, buildPythonPackage
 , requests, fetchpatch, pythonOlder, typing
 }:
 
@@ -23,12 +23,12 @@ buildPythonPackage rec {
     })
   ];
 
-  propagatedBuildInputs = [ requests ] ++ stdenv.lib.optional (pythonOlder "3.5") typing;
+  propagatedBuildInputs = [ requests ] ++ lib.optional (pythonOlder "3.5") typing;
 
-  meta = {
+  meta = with lib; {
     description = "The official Todoist Python API library";
     homepage = "https://todoist-python.readthedocs.io/en/latest/";
-    license = stdenv.lib.licenses.mit;
-    maintainers = with stdenv.lib.maintainers; [ ma27 ];
+    license = licenses.mit;
+    maintainers = with maintainers; [ ma27 ];
   };
 }
diff --git a/pkgs/development/python-modules/trackpy/default.nix b/pkgs/development/python-modules/trackpy/default.nix
index 6132a30c414..ff4c4a76758 100644
--- a/pkgs/development/python-modules/trackpy/default.nix
+++ b/pkgs/development/python-modules/trackpy/default.nix
@@ -35,7 +35,7 @@ buildPythonPackage rec {
   ];
 
   checkPhase = ''
-    ${stdenv.lib.optionalString (stdenv.isDarwin) ''
+    ${lib.optionalString (stdenv.isDarwin) ''
     # specifically needed for darwin
     export HOME=$(mktemp -d)
     mkdir -p $HOME/.matplotlib
diff --git a/pkgs/development/python-modules/transformers/default.nix b/pkgs/development/python-modules/transformers/default.nix
index ee288f7626b..59420475440 100644
--- a/pkgs/development/python-modules/transformers/default.nix
+++ b/pkgs/development/python-modules/transformers/default.nix
@@ -35,7 +35,7 @@ buildPythonPackage rec {
     sacremoses
     tokenizers
     tqdm
-  ] ++ stdenv.lib.optionals (pythonOlder "3.8") [ importlib-metadata ];
+  ] ++ lib.optionals (pythonOlder "3.8") [ importlib-metadata ];
 
   # Many tests require internet access.
   doCheck = false;
diff --git a/pkgs/development/python-modules/trytond/default.nix b/pkgs/development/python-modules/trytond/default.nix
index 7db53969402..68254d8601e 100644
--- a/pkgs/development/python-modules/trytond/default.nix
+++ b/pkgs/development/python-modules/trytond/default.nix
@@ -1,4 +1,4 @@
-{ stdenv
+{ lib
 , buildPythonApplication
 , fetchPypi
 , pythonOlder
@@ -21,8 +21,6 @@
 , withPostgresql ? true
 }:
 
-with stdenv.lib;
-
 buildPythonApplication rec {
   pname = "trytond";
   version = "5.8.2";
@@ -56,14 +54,14 @@ buildPythonApplication rec {
     python-Levenshtein
     simplejson
     html2text
-  ] ++ stdenv.lib.optional withPostgresql psycopg2;
+  ] ++ lib.optional withPostgresql psycopg2;
 
   # If unset, trytond will try to mkdir /homeless-shelter
   preCheck = ''
     export HOME=$(mktemp -d)
   '';
 
-  meta = {
+  meta = with lib; {
     description = "The server of the Tryton application platform";
     longDescription = ''
       The server for Tryton, a three-tier high-level general purpose
diff --git a/pkgs/development/python-modules/tumpa/default.nix b/pkgs/development/python-modules/tumpa/default.nix
index 28560feb04f..6d953740eb8 100644
--- a/pkgs/development/python-modules/tumpa/default.nix
+++ b/pkgs/development/python-modules/tumpa/default.nix
@@ -1,4 +1,4 @@
-{ stdenv
+{ lib
 , buildPythonPackage
 , fetchFromGitHub
 , setuptools
@@ -27,7 +27,7 @@ buildPythonPackage rec {
 
   doCheck = false;
 
-  meta = with stdenv.lib; {
+  meta = with lib; {
     description = "OpenPGP key creation and smartcard access";
     homepage = "https://github.com/kushaldas/tumpa";
     license = licenses.gpl3Plus;
diff --git a/pkgs/development/python-modules/twisted/default.nix b/pkgs/development/python-modules/twisted/default.nix
index efec0b737bc..421565725b1 100644
--- a/pkgs/development/python-modules/twisted/default.nix
+++ b/pkgs/development/python-modules/twisted/default.nix
@@ -30,7 +30,7 @@ buildPythonPackage rec {
 
   # Patch t.p._inotify to point to libc. Without this,
   # twisted.python.runtime.platform.supportsINotify() == False
-  patchPhase = stdenv.lib.optionalString stdenv.isLinux ''
+  patchPhase = lib.optionalString stdenv.isLinux ''
     substituteInPlace src/twisted/python/_inotify.py --replace \
       "ctypes.util.find_library('c')" "'${stdenv.glibc.out}/lib/libc.so.6'"
   '';
diff --git a/pkgs/development/python-modules/unicorn/default.nix b/pkgs/development/python-modules/unicorn/default.nix
index 215a32e3b60..484f422adf3 100644
--- a/pkgs/development/python-modules/unicorn/default.nix
+++ b/pkgs/development/python-modules/unicorn/default.nix
@@ -2,7 +2,7 @@
 
 buildPythonPackage rec {
   pname = "unicorn";
-  version = stdenv.lib.getVersion unicorn-emu;
+  version = lib.getVersion unicorn-emu;
 
   src = unicorn-emu.src;
   sourceRoot = "source/bindings/python";
diff --git a/pkgs/development/python-modules/urllib3/default.nix b/pkgs/development/python-modules/urllib3/default.nix
index 4bf36439174..6cf7ce34d38 100644
--- a/pkgs/development/python-modules/urllib3/default.nix
+++ b/pkgs/development/python-modules/urllib3/default.nix
@@ -1,4 +1,4 @@
-{ lib, stdenv, buildPythonPackage, fetchPypi
+{ lib, buildPythonPackage, fetchPypi
 , pytest, mock, tornado, pyopenssl, cryptography
 , idna, certifi, ipaddress, pysocks }:
 
@@ -11,7 +11,7 @@ buildPythonPackage rec {
     sha256 = "19188f96923873c92ccb987120ec4acaa12f0461fa9ce5d3d0772bc965a39e08";
   };
 
-  NOSE_EXCLUDE = stdenv.lib.concatStringsSep "," [
+  NOSE_EXCLUDE = lib.concatStringsSep "," [
     "test_headers" "test_headerdict" "test_can_validate_ip_san" "test_delayed_body_read_timeout"
     "test_timeout_errors_cause_retries" "test_select_multiple_interrupts_with_event"
   ];
diff --git a/pkgs/development/python-modules/watchdog/default.nix b/pkgs/development/python-modules/watchdog/default.nix
index 893cdd7e99b..5cb8929b9db 100644
--- a/pkgs/development/python-modules/watchdog/default.nix
+++ b/pkgs/development/python-modules/watchdog/default.nix
@@ -16,7 +16,7 @@ buildPythonPackage rec {
     sha256 = "e38bffc89b15bafe2a131f0e1c74924cf07dcec020c2e0a26cccd208831fcd43";
   };
 
-  buildInputs = stdenv.lib.optionals stdenv.isDarwin
+  buildInputs = lib.optionals stdenv.isDarwin
     [ pkgs.darwin.apple_sdk.frameworks.CoreServices ];
   propagatedBuildInputs = [ argh pathtools pyyaml ];
 
diff --git a/pkgs/development/python-modules/werkzeug/default.nix b/pkgs/development/python-modules/werkzeug/default.nix
index 858130b805f..7f35dd124d8 100644
--- a/pkgs/development/python-modules/werkzeug/default.nix
+++ b/pkgs/development/python-modules/werkzeug/default.nix
@@ -17,7 +17,7 @@ buildPythonPackage rec {
   propagatedBuildInputs = [ itsdangerous ];
   checkInputs = [ pytestCheckHook requests hypothesis pytest-timeout ];
 
-  disabledTests = stdenv.lib.optionals stdenv.isDarwin [
+  disabledTests = lib.optionals stdenv.isDarwin [
     "test_get_machine_id"
   ];
 
diff --git a/pkgs/development/python-modules/xcffib/default.nix b/pkgs/development/python-modules/xcffib/default.nix
index 33431684708..8f51ec1e77f 100644
--- a/pkgs/development/python-modules/xcffib/default.nix
+++ b/pkgs/development/python-modules/xcffib/default.nix
@@ -1,4 +1,4 @@
-{ lib, stdenv
+{ lib
 , buildPythonPackage
 , fetchPypi
 , xorg
diff --git a/pkgs/development/python-modules/xnd/default.nix b/pkgs/development/python-modules/xnd/default.nix
index 3178e171f84..3657997f5a7 100644
--- a/pkgs/development/python-modules/xnd/default.nix
+++ b/pkgs/development/python-modules/xnd/default.nix
@@ -1,4 +1,5 @@
-{ stdenv
+{ lib
+, stdenv
 , buildPythonPackage
 , python
 , ndtypes
@@ -27,7 +28,7 @@ buildPythonPackage {
   postInstall = ''
     mkdir $out/include
     cp python/xnd/*.h $out/include
-  '' + stdenv.lib.optionalString stdenv.isDarwin ''
+  '' + lib.optionalString stdenv.isDarwin ''
     install_name_tool -add_rpath ${libxnd}/lib $out/${python.sitePackages}/xnd/_xnd.*.so
   '';
 
diff --git a/pkgs/development/python-modules/zconfig/default.nix b/pkgs/development/python-modules/zconfig/default.nix
index 4882f92b047..a6a00ad821b 100644
--- a/pkgs/development/python-modules/zconfig/default.nix
+++ b/pkgs/development/python-modules/zconfig/default.nix
@@ -23,7 +23,7 @@ buildPythonPackage rec {
       url = "https://github.com/zopefoundation/ZConfig/commit/f0c2990d35ac3c924ecc8be4a5c71c8e4abbd0e5.patch";
       sha256 = "1bjg3wrvii0rwzf3s0vlpzgg2ckj0h2zxkyxwjcr64s4k2vaq9ij";
     })
-  ] ++ stdenv.lib.optional stdenv.hostPlatform.isMusl ./remove-setlocale-test.patch;
+  ] ++ lib.optional stdenv.hostPlatform.isMusl ./remove-setlocale-test.patch;
 
   buildInputs = [ manuel docutils ];
   propagatedBuildInputs = [ zope_testrunner ];
diff --git a/pkgs/development/python-modules/zope_lifecycleevent/default.nix b/pkgs/development/python-modules/zope_lifecycleevent/default.nix
index 28070ea67e7..390624b50de 100644
--- a/pkgs/development/python-modules/zope_lifecycleevent/default.nix
+++ b/pkgs/development/python-modules/zope_lifecycleevent/default.nix
@@ -22,7 +22,7 @@ buildPythonPackage rec {
   doCheck = false;
 
   # zope uses pep 420 namespaces for python3, doesn't work with nix + python2
-  pythonImportsCheck = stdenv.lib.optionals isPy3k [
+  pythonImportsCheck = lib.optionals isPy3k [
     "zope.lifecycleevent"
     "zope.interface"
   ];