diff --git a/tests/io/file-stdio.py b/tests/io/file-stdio.py
new file mode 100644
index 0000000000000000000000000000000000000000..cbdb070163c31abc19944c853dd7a7b886cc7def
--- /dev/null
+++ b/tests/io/file-stdio.py
@@ -0,0 +1,4 @@
+import sys
+
+print(sys.stdin.fileno())
+print(sys.stdout.fileno())
diff --git a/unix/file.c b/unix/file.c
index 5249b5bba34544976a6953111185870ab0e1f5ff..7bbe3bfd005b2d42f35310d25a9eac8cb37eeec2 100644
--- a/unix/file.c
+++ b/unix/file.c
@@ -48,6 +48,12 @@ static mp_obj_t fdfile_close(mp_obj_t self_in) {
 }
 static MP_DEFINE_CONST_FUN_OBJ_1(fdfile_close_obj, fdfile_close);
 
+static mp_obj_t fdfile_fileno(mp_obj_t self_in) {
+    mp_obj_fdfile_t *self = self_in;
+    return MP_OBJ_NEW_SMALL_INT(self->fd);
+}
+static MP_DEFINE_CONST_FUN_OBJ_1(fdfile_fileno_obj, fdfile_fileno);
+
 static mp_obj_fdfile_t *fdfile_new(int fd) {
     mp_obj_fdfile_t *o = m_new_obj(mp_obj_fdfile_t);
     o->base.type = &rawfile_type;
@@ -99,6 +105,7 @@ static mp_obj_t fdfile_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
 }
 
 static const mp_method_t rawfile_type_methods[] = {
+        { "fileno", &fdfile_fileno_obj },
         { "read", &mp_stream_read_obj },
         { "readall", &mp_stream_readall_obj },
         { "readline", &mp_stream_unbuffered_readline_obj},
diff --git a/unix/socket.c b/unix/socket.c
index c38e38a0a1196e0ec05bce4e83824169da5879b7..aaa15cbee25e118a3afb2fcc181c11c181881d0e 100644
--- a/unix/socket.c
+++ b/unix/socket.c
@@ -84,6 +84,12 @@ static mp_obj_t socket_close(mp_obj_t self_in) {
 }
 static MP_DEFINE_CONST_FUN_OBJ_1(socket_close_obj, socket_close);
 
+static mp_obj_t socket_fileno(mp_obj_t self_in) {
+    mp_obj_socket_t *self = self_in;
+    return MP_OBJ_NEW_SMALL_INT(self->fd);
+}
+static MP_DEFINE_CONST_FUN_OBJ_1(socket_fileno_obj, socket_fileno);
+
 static mp_obj_t socket_connect(mp_obj_t self_in, mp_obj_t addr_in) {
     mp_obj_socket_t *self = self_in;
     buffer_info_t bufinfo;
@@ -209,6 +215,7 @@ static mp_obj_t socket_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const
 }
 
 static const mp_method_t microsocket_type_methods[] = {
+        { "fileno", &socket_fileno_obj },
         { "read", &mp_stream_read_obj },
         { "readall", &mp_stream_readall_obj },
         { "readline", &mp_stream_unbuffered_readline_obj},